Skip to main content
All CollectionsIntegrations
Integrating Custom Payment Gateway with Archie
Integrating Custom Payment Gateway with Archie

Setting up your custom payment gateway

Camilo avatar
Written by Camilo
Updated over a week ago

We’ve recently introduced an new feature that lets you integrate a custom payment gateway with Archie. In this article, we’ll walk you through how this feature works and outline the steps required to complete the integration process.

Step 1. Configure Your Redirect URL

When setting up a custom payment gateway, you'll need to provide a URL where Archie will redirect users when they click on "Pay," whether it's during the checkout process of a booking or purchase, or when an invoice is being paid.

The URL must redirect to your custom payment gateway where customers can pay.

Once you have the URL set, go to "Settings/Integrations/App marketplace", click the "Payment" tab, and click "View Integration" under "Custom Payment Gateway", and click "Setup custom payment gateway".

Proceed to add a Name to identify this entry, and the URL.

Step 2. Handling the Redirect URL

When a user clicks the "Pay" button, Archie will open a WebView that directs to the URL you specified. The URL will include a param "data" which is encrypted with a private key (given in your custom integration page).

Step 3. Decrypting the Data

The data object will contain the user object and the space object, you will have to decrypt it with the key to get the JSON data. Form there, you can use Archie API and the provider API to get the data needed to process the payment on your provider. For instance you could get the user and the item or element that is being purchased, process the payment, and mark it as completed with the API.

To access the Archie API, go to "Settings/Integrations/Developer portal", you can then proceed to create an application that will give you a Client ID and Client Secret key to generate an access token to access the Archie API.

Here are some examples Decrypt functions.

// DecryptMessage : decrypt message with AES from base64 encoded string
func DecryptMessage(secret string, encrypted string)(string, error) {
ciphertext, _: = base64.StdEncoding.DecodeString(encrypted)
// create a 32 byte long key from the secret. Note that extra bytes are ignored if the secret is longer than 32 bytes
key: = [] byte(secret)[: 32]
c, err: = aes.NewCipher(key)
if err != nil {
return "", err
}
gcm, err: = cipher.NewGCM(c)
if err != nil {
return "", err
}
nonceSize: = gcm.NonceSize()
if len(ciphertext) < nonceSize {
return "", errorsP.New("ciphertext is too short")
}
nonce, ciphertext: = ciphertext[: nonceSize], ciphertext[nonceSize: ]
plaintext, err: = gcm.Open(nil, nonce, ciphertext, nil)
if err != nil {
panic(err)
}
return string(plaintext), nil
}

In JavaScript (Node.js):

// DecryptMessage : decrypt message with AES from base64 encoded string

function DecryptMessage(secret, encrypted) {
const ciphertext = Buffer.from(encrypted, 'base64');
// create a 32 byte long key from the secret. Note that extra bytes are ignored if the secret is longer than 32 bytes
const key = Buffer.from(secret).slice(0, 32);
const cipher = crypto.createCipheriv('aes-256-gcm', key, '');
const nonceSize = cipher.getAuthTag().length;

if (ciphertext.length < nonceSize) {
throw new Error('ciphertext is too short');
}

const nonce = ciphertext.slice(0, nonceSize);
const ciphertextToDecrypt = ciphertext.slice(nonceSize);
const plaintext = cipher.decrypt(nonce, ciphertextToDecrypt, null);
return plaintext.toString();
}
Did this answer your question?