1. ACH API - POST REQUEST

Below code sample can be used to generate an ACH request using Python 3. User needs to provide an SVB provided api_key and secret string before running the script.

 

import os
import hmac
import time
import json
import hashlib
import requests
import binascii
from hashlib import sha256
from urllib.parse import urlencode, urlparse, parse_qs

# constants
API_KEY = "Enter_API_Key_Here"
HMAC_SECRET = "Enter_HMAC_Secret_Key_Here"

BASE_URL = 'https://uat.api.svb.com'
PATH = '/v1/ach'


def gen_hmac(payload):
    secret = HMAC_SECRET
    timestamp = str(int(time.time()))
    method = 'POST'
    path = PATH
    params = ''

    if payload is None:
        body = ''
    else:
        body = json.dumps(payload)

    # combine everything to create the message and secret
    message = "\n".join([timestamp, method, path, params, body])

    signature = hmac.new(bytes(secret, 'utf-8'), bytes(message, 'utf-8'),
                         hashlib.sha256).hexdigest()

    # Cryptographically strong random number to use as a one-off
    nonce = str(int(binascii.hexlify(os.urandom(16)), 16))

    return signature, nonce, timestamp


def create_ach_payment(ach_transfer):
    url = BASE_URL + PATH

    # make sure to set up the body before hmac signing
    payload = {
        "data": ach_transfer
    }

    x_signature, nonce, x_timestamp = gen_hmac(payload)
    # print("Signature: " + x_signature)
    # print("Timestamp: " + x_timestamp)

    # add headers to request
    headers = {
        'authorization': 'Bearer ' + API_KEY,
        'content-type': 'application/json',
        'X-Signature': x_signature,
        'X-Timestamp': x_timestamp
    }

    response = requests.post(url, headers=headers, data=json.dumps(payload))
    response_json = json.loads(response.text)

    # print(json.dumps(headers, indent=2))  # headers
    # print(json.dumps(response_json, indent=2))  # TEXT/HTML
    # print(response.status_code, response.reason)  # HTTP

    return response_json


ach_transfer = {
        "account_number": "1111111111",
        "amount": 1000,
        "direction": "credit",
        "receiver_account_number": "99999",
        "receiver_account_type": "checking",
        "receiver_name": "Best SVB client",
        "receiver_routing_number": "121140399",
        "sec_code": "ccd"
    }

print(create_ach_payment(ach_transfer))

2. ACH API - GET REQUEST

Below code sample can be used to generate an ACH API - GET request using Python 3. User needs to provide an SVB provided api_key and secret string before running the script.

import os
import hmac
import time
import json
import base64
import hashlib
import requests
import binascii
from hashlib import sha256
from urllib.parse import urlencode

API_KEY = "Enter_API_Key_Here"
HMAC_SECRET = "Enter_HMAC_Secret_Key_Here"

payload = None

def gen_hmac(payload):
    secret = HMAC_SECRET
    timestamp = str(int(time.time()))
    # Cryptographically strong random number
    nonce = str(int(binascii.hexlify(os.urandom(16)), 16))
    method = 'GET'
    path = '/v1/ach'
    params = ''

    if payload is None:
        body = ''
    else:
        body = json.dumps(payload)

    print("body is: ", body)

    message = "\n".join([timestamp, method, path, params, body])
    signature = hmac.new(bytes(secret, 'utf-8'), bytes(message, 'utf-8'), 
                hashlib.sha256).hexdigest()

    print(type(signature))
    return signature, nonce, timestamp


def test_svb_ach(payload):
    x_signature, nonce, x_timestamp = gen_hmac(payload)
    url = "https://uat.api.svb.com/v1/ach"

    print("Signature: " + x_signature)
    print("Timestamp: " + x_timestamp)

    headers = {
        'authorization': 'Bearer ' + API_KEY,
        'content-type': 'application/json',
        'X-Signature': x_signature,
        'X-Timestamp': x_timestamp
    }

    print(json.dumps(headers, indent=2))
    response = requests.get(url, headers=headers)
    response_json = json.loads(response.text)
    print(json.dumps(response_json, indent=2))  # TEXT/HTML
    print(response.status_code, response.reason)  # HTTP


test_svb_ach(payload)

 

 

3. VCN API - POST REQUEST

Below code sample can be used to generate a VCN using Python 3. User needs to provide an SVB provided api_key and secret string before running the script.

import os
import hmac
import time
import json
import base64
import hashlib
import requests
import binascii
from hashlib import sha256
from urllib.parse import urlencode

API_KEY = "Enter_API_Key_Here"
HMAC_SECRET = "Enter_HMAC_Secret_Key_Here"

payload = None

def gen_hmac(payload):
    secret = HMAC_SECRET
    timestamp = str(int(time.time()))
    # Cryptographically strong random number
    nonce = str(int(binascii.hexlify(os.urandom(16)), 16))
    method = 'POST'
    path = '/v1/virtualcards'
    params = ''

    if payload is None:
        body = ''
    else:
        body = json.dumps(payload)

    message = "\n".join([timestamp, method, path, params, body])
    signature = hmac.new(bytes(secret, 'utf-8'), bytes(message, 'utf-8'), 
                hashlib.sha256).hexdigest()

    print(type(signature))
    return signature, nonce, timestamp



def test_svb_vcn(payload):
    data = {
        "total_card_amount": 100,
        "valid_ending_on": "2023-03-31"
    }

    payload = {
        "data": data,
        "show_card_number": True
    }

    x_signature, nonce, x_timestamp = gen_hmac(payload)
    url = "https://uat.api.svb.com/v1/virtualcards"

    print("Signature: " + x_signature)
    print("Timestamp: " + x_timestamp)

    headers = {
        'authorization': 'Bearer ' + API_KEY,
        'content-type': 'application/json',
        'X-Signature': x_signature,
        'X-Timestamp': x_timestamp
    }

    print(json.dumps(headers, indent=2))
    response = requests.post(url, headers=headers, data=json.dumps(payload))
    response_json = json.loads(response.text)
    print(json.dumps(response_json, indent=2)) 
    print(response.status_code, response.reason)  

test_svb_vcn(payload)

4. VCN API - GET REQUEST

Below code sample can be used to generate a VCN API - GET request using Python 3. User needs to provide an SVB provided api_key and secret string before running the script.

import os
import hmac
import time
import json
import base64
import hashlib
import requests
import binascii
from hashlib import sha256
from urllib.parse import urlencode

API_KEY = "Enter_API_Key_Here"
HMAC_SECRET = "Enter_HMAC_Secret_Key_Here"

payload = None

def gen_hmac(payload):
    secret = HMAC_SECRET
    timestamp = str(int(time.time()))
    # Cryptographically strong random number
    nonce = str(int(binascii.hexlify(os.urandom(16)), 16))
    method = 'GET'
    path = '/v1/virtualcards'
    params = ''

    if payload is None:
        body = ''
    else:
        body = json.dumps(payload)

    message = "\n".join([timestamp, method, path, params, body])
    signature = hmac.new(bytes(secret, 'utf-8'), bytes(message, 'utf-8'), 
                hashlib.sha256).hexdigest()

    return signature, nonce, timestamp

def test_svb_vcn(payload):
    x_signature, nonce, x_timestamp = gen_hmac(payload)
    url = "https://uat.api.svb.com/v1/virtualcards"

    print("Signature: " + x_signature)
    print("Timestamp: " + x_timestamp)

    headers = {
        'authorization': 'Bearer ' + API_KEY,
        'content-type': 'application/json',
        'X-Signature': x_signature,
        'X-Timestamp': x_timestamp
    }

    print(json.dumps(headers, indent=2))
    response = requests.get(url, headers=headers)
    response_json = json.loads(response.text)
    print(json.dumps(response_json, indent=2))  
    print(response.status_code, response.reason) 

test_svb_vcn(payload)