2.1.1 โ€ข Published 8 months ago

@migopayments/sdk v2.1.1

Weekly downloads
-
License
ISC
Repository
-
Last release
8 months ago

๐Ÿ“ฆ Installation

$ npm install @migopayments/sdk

๐Ÿš€ Initialize the SDK

The merchant and privateKey are provided by MigoPayments.

import { loadMigo } from "@migopayments/sdk";

const migo = await loadMigo({
    merchant: "merchant", // provided by Migo
    privateKey: "privateKey", // provided by Migo
    environment: "sandbox",
});
EnvironmentDescription
sandboxUse this to build and test your application ๐Ÿงช.
productionUse this for production.

The migo object will expose the multiple methods available in the SDK.

๐Ÿงฉ The schema object

The schema object serves a crucial purpose in the SDK by dynamically validating payload information sent by the client. It is custom-tailored to each client, providing a unique framework for organizing and structuring data. By printing it to the console, you can gain valuable insight into how the SDK handles and enforces data validations, making it an indispensable tool for developers.

// print out the schema
console.log(JSON.stringify(migo.schema));

๐Ÿ“ Creating a new transaction

Each method the SDK exposes returns an object with the data and error properties. Which you can destructure using ES6. If an error is present the data object will be null.

To create a new transaction use the createTransaction method. Make sure to use one of the clients found in the schema.

// create a new transaction
const { data, error } = await migo.createTransaction({
    amount: 500,
    client: "elektra",
});

// console.log(data?.reference);
// console.log(data?.uid);

๐Ÿ’ณ Creating a payment intent

const { data, error } = await migo.createPaymentIntent("transactionId", payload);

// console.log(data?.challenge);
// console.log(data?.transaction);

As the payload object varies from client to client, it's important to refer to your schema object to ensure that you're using the correct structure for a payment intent. Usually the payload object contains the card information, such as card holder name, card number, CVV and expiration date (if applicable). If you don't follow the required format, the SDK will return an error.

If a challenge is required for the payment intent, it will be returned in the data object.

๐ŸฅŠ Payment intent challenge

3D Secure is a protocol used to provide an additional layer of security for online transactions. When a user makes a payment online with a card that supports 3D Secure, they may be prompted to complete an extra step to authenticate the transaction.

This extra step is typically a challenge, which can take different forms depending on the specific implementation. For example, the challenge may involve entering a one-time code sent to the user's mobile phone or email, answering a security question, or providing biometric authentication such as a fingerprint or facial recognition.

The purpose of the challenge is to verify that the user making the transaction is the authorized cardholder, and to prevent fraudulent transactions. Once the challenge is completed, the transaction can proceed if the authentication is successful.

๐Ÿค Tokenize a card

const card = {
    expMonth: '03',
    expYear: '25',
    cardFullNumber: '411111111111111',
    cardCvv: '123',
    cardHolderName: 'John',
    cardHolderLastName: 'Doe'
}

const { data, error } = await migo.tokenizeCard('transactionId', 'processor', card);

๐Ÿ”’ Get the list of tokenized cards

This method returns a list of tokenized cards associated with a specific transaction.

const { data, error } = await migo.getTokenizedCards('transactionId', 'processor');

๐Ÿงน Delete a tokenized card

const { data, error } = await migo.deleteTokenizedCard('transactionId', 'processor', 'cardId');

๐Ÿ’ฐ Refund

const { data, error } = await migo.refund('transactionId', amount);

// console.log(data?.transaction);
// console.log(data?.attempt);

๐Ÿ”™ Revert a transaction

const { data, error } = await migo.revertTransaction('transactionId');

// console.log(data?.transaction);

๐Ÿฆ Authorization and capture process

  1. The customer initiates a credit/debit card payment intent.

  2. Migo sends a request to the customer's bank (the issuer) to confirm that the customer has sufficient funds in their account to complete the transaction.

  3. If the funds are available, the issuer authorizes the payment and reserves the necessary amount in the customer's account.

  4. Migo sends a request to the merchant's bank (the acquirer) to capture the authorized amount and transfer it to the merchant's account.

  5. If the capture is successful, the payment is considered complete, and the merchant can ship the product or provide the service to the customer.

  6. To confirm a capture transaction, use the confirmCapture method to finalize the payment and transfer the funds to the merchant's account.

  7. If the confirmation is successful, the payment is considered complete, and the merchant can proceed with fulfilling the order.

  8. To cancel a capture transaction, use the cancelCapture method to reverse the payment and release the reserved funds back to the customer's account.

  9. If the cancellation is successful, the payment is considered cancelled, and the reserved funds are released back to the customer's account.

  10. Depending on the timing and processing schedules of the involved banks, it may take a few business days for the cancelled funds to become available again in the customer's account.

โœ”๏ธ Confirm capture

const { data, error } = await migo.confirmCapture('transactionId');

โŒ Cancel capture

const { data, error } = await migo.cancelCapture('transactionId');

๐ŸŸข Transaction status

const { data, error } = await migo.transactionStatus('transactionId');

// console.log(data?.transaction);

๐Ÿ“š More information

1.0.9

10 months ago

2.0.3

9 months ago

2.1.1

8 months ago

2.0.4

9 months ago

1.0.10

10 months ago

2.1.0

9 months ago

2.0.1

9 months ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago