Using Paylinks
Pre-requisites
- An account on NGnair.
- An active merchant account. You will see an active status for ready-to-use accounts.
- An API Key. If you don't have one, follow the steps in the API Keys guide.
Creating Paylinks
API Request
curl -X 'POST' \
'https://demo-be.ngnair.com/api/gateway/createCheckoutData' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"groupID": "string",
"token": "string",
"data": {
"form": {
"pricing": {
"methodVerifyOrProcess": "process",
"lineItems": [
{
"productId": "string",
"product": {
"sku": "string",
"name": "string",
"description": "string",
"price": 0,
"isRecurring": true,
"recurringMode": "string",
"recurringInterval": 0,
"recurringFrequency": 0,
"recurringTotalCycles": 0,
"recurringTrialDays": 0,
"recurringSetupFee": 0,
"recurringRefundable": true
},
"amount": 0,
}
],
"amount": 0,
"tip": 0,
"tipType": "fixed",
"tax": 0,
"taxType": "fixed",
"discountCodes": ["string"],
"shipping": 0
},
"meta": {
"dynamic": {
"discountCodes": ["string"],
"paymentType": "card",
"tip": {
"amount": 0,
"type": "percentage"
},
"quantityAmounts": [
{
"id": "string",
"quantity": 0
}
]
},
},
"allowEdit": true,
"allowExtraDiscount": true,
"allowTip": true,
"disableCC": true,
"disableACH": true,
"validUntil": "string",
"referenceID": "string",
"onSuccessURL": "string",
"onFailureURL": "string",
"customerID": "string",
"customerPaymentID": "string",
"prefilledAddress": {
"email": "string",
"phone": "string",
"country": "string",
"state": "string",
"city": "string",
"zip": "string",
"address": "string",
"nameOnCard": "string"
},
"disableCustomAddress": true,
"disableCustomPayment": true,
"disablePreselectCard": true
}
}
}'
To breakdown the request:
-
Base URL and Headers:
https://demo-be.ngnair.com/api/gateway/createCheckoutData- This is the endpoint for creating a new paylink. The root url may change based on the environment (sandbox, production).
- The headers are set to accept JSON data.
-
Request Body:
groupID: Your merchant group identifiertoken: Your API key token. Specifically your private token.data.form: Contains the payment form configurationpricing: Payment detailsmethodVerifyOrProcess: Set to "process" for direct processinglineItems: Array of products/services. You can either:- Provide a
productIdto fetch product data from server, or - Include a complete
productobject with details - Note: If both
lineItemsandamountare provided,lineItemstakes priority productId: Unique identifier for the product (if fetching from server)product: Product detailssku: Stock keeping unitname: Product namedescription: Product descriptionprice: Product priceisRecurring: Whether this is a subscription productrecurringMode: Subscription mode (e.g., "MONTHLY", "YEARLY"). Omittable, will be treated as DAILY.recurringInterval: Interval between recurring paymentsrecurringFrequency: Number of times per intervalrecurringTotalCycles: Total number of billing cyclesrecurringTrialDays: Number of trial daysrecurringSetupFee: One-time setup feerecurringRefundable: Whether setup fee is refundable
amount: Quantity of the item
- Provide a
amount: Total transaction amounttip: Tip amount (optional)tipType: "fixed" or "percentage"tax: Tax amount (optional)taxType: "fixed" or "percentage"discountCodes: Array of applicable discount codesshipping: Shipping cost (optional)
meta: Additional metadatadynamic: Dynamic form settingsdiscountCodes: Dynamic discount codespaymentType: Preferred payment methodtip: Dynamic tip settingsquantityAmounts: Dynamic quantity settings
reference: Reference information
allowEdit: Enable/disable payment form editingallowExtraDiscount: Enable/disable discount inputallowTip: Enable/disable tippingdisableCC: Disable credit card paymentsdisableACH: Disable ACH paymentsvalidUntil: Expiration date for the paylinkreferenceID: Your internal reference numberonSuccessURL: Redirect URL after successful paymentonFailureURL: Redirect URL after failed paymentcustomerID: Existing customer IDcustomerPaymentID: Existing customer payment method IDprefilledAddress: Pre-filled customer informationdisableCustomAddress: Disable address editingdisableCustomPayment: Disable custom payment method entrydisablePreselectCard: Disable card preselection
Response
{
"data": {
"payLinkID": "string",
"paymentData": "string",
"token": "string",
"groupID": "string",
"url": "string"
},
"token": "string",
"groupID": "string",
"url": "string"
}
To breakdown the response:
- Response Body:
data: Contains the paylink detailspaymentData: Encrypted payment informationtoken: The public key that will be used to verify the paymentDatagroupID: Your merchant group identifierurl: The payment URL to share with customers
token: Same as data.tokengroupID: Same as data.groupIDurl: Same as data.url
Creating Subscription Paylinks
To create a subscription paylink, you'll need to set the recurring parameters in the product object. Here's an example:
{
"groupID": "MID-840-04-2025-000003",
"token": "your-private-token",
"data": {
"form": {
"pricing": {
"methodVerifyOrProcess": "process",
"lineItems": [
{
"product": {
"sku": "SUBSCRIPTION-001",
"name": "Premium Monthly Plan",
"description": "Access to premium features",
"price": 2999,
"isRecurring": true,
"recurringMode": "MONTHLY",
"recurringInterval": 1,
"recurringFrequency": 1,
"recurringTotalCycles": 12,
"recurringTrialDays": 7,
"recurringSetupFee": 0,
"recurringRefundable": false
},
"amount": 1
}
],
},
"referenceID": "SUB123",
"onSuccessURL": "https://your-store.com/success",
"onFailureURL": "https://your-store.com/failed"
}
}
}
In this example:
- The subscription is billed MONTHLY at $29.99
- It includes a 7-day free trial
- The subscription runs for 12 months
- No setup fee is charged
- The setup fee is not refundable
- The
recurringModeis set to "MONTHLY" (can also be "YEARLY" or omitted)
Note: The recurringMode parameter is optional. When omitted, the system will use the default recurring mode based on your account settings.
Creating Prefilled Paylinks
You can create a paylink with pre-filled customer information to streamline the checkout process:
{
"groupID": "MID-840-04-2025-000003",
"token": "your-private-token",
"data": {
"form": {
"pricing": {
"methodVerifyOrProcess": "process",
"lineItems": [
{
"product": {
"sku": "PRODUCT-001",
"name": "Premium Product",
"description": "Product description",
"price": 2999
},
"amount": 1
}
],
},
"prefilledAddress": {
"email": "customer@example.com",
"phone": "+1234567890",
"country": "US",
"state": "CA",
"city": "San Francisco",
"zip": "94105",
"address": "123 Main St",
"nameOnCard": "John Doe"
},
"disableCustomAddress": true,
"referenceID": "ORDER123",
"onSuccessURL": "https://your-store.com/success",
"onFailureURL": "https://your-store.com/failed"
}
}
}
In this example:
- Customer information is pre-filled
- Address editing is disabled
- The customer can still modify their payment information
Creating Paylinks for Existing Customers
To create a paylink for an existing customer using their saved payment method:
{
"groupID": "MID-840-04-2025-000003",
"token": "your-private-token",
"data": {
"form": {
"pricing": {
"methodVerifyOrProcess": "process",
"lineItems": [
{
"product": {
"sku": "PRODUCT-001",
"name": "Premium Product",
"description": "Product description",
"price": 2999
},
"amount": 1
}
],
},
"customerID": "CUST-123",
"customerPaymentID": "PAY-456",
"disableCustomPayment": true,
"referenceID": "ORDER123",
"onSuccessURL": "https://your-store.com/success",
"onFailureURL": "https://your-store.com/failed"
}
}
}
In this example:
- Uses an existing customer's ID
- Uses their saved payment method
- Disables custom payment method entry
- The customer can only use their saved payment method
Note: You can fetch the list of customers and their payment methods using the customer fetch list and customer get endpoints. The customer ID and payment method ID are also available in the webhook event payment_success.
Important Notes
- We highly recommend the usage of referenceID to track the payment against your own system. You can use it to see if the payment was successful or not. For example, to check if a customer already paid for your product, listen for a webhook event with the referenceID. If it has the 'payment_success' status, then the payment was successful, also take note if the 'payment_failed' status is present or a 'payment_refund' was made.
Next Steps
To intercept if the payment was succesful or failed, we will send a webhook notification to the webhook endpoint you will provide. You can find more information about this in the Webhooks guide.