Accept Payments
To accept a payment, create a transaction using our API, our client Javascript library. Every transaction includes a link that can be used to complete payment.
Popup
Socialpay Popup provides a simple and convenient payment flow for web. It can be integrated in five easy steps, making it the easiest way to start accepting payments. See demo of the payment methods on the checkout here.
Collect customer information.
To initialize the transaction, you'll need to pass information such as email, first name, last name amount, order_id, etc. You can also pass any other additional information in the custom_fields
object field. Here is the full list of parameters you can pass:
Param | Required? | Description |
---|---|---|
public_key | Yes | Your public key from social pay. |
Yes | Email address of customer | |
first_name | Yes | First name of customer |
last_name | Yes | Last name of customer |
order_id | Yes | Order id for payment |
fee_bearer | Yes | Fee bearer for the payment (client/merchant) |
amount_charge | Yes | Amount charged for payment |
cryptocurrency_type | Yes | Crypto currency type used for the payment. |
redirect_url | No | Redirect url for the payment. |
custom_fields | No | objects containing any extra information you want recorded in the transaction. |
callback | No | Function that runs when payment is successful. This should ideally be a script that uses the verify endpoint on the Social Pay API to check the status of the transaction. |
onClose | No | Javascript function that is called if the customer closes the payment window instead of making a payment. |
The customer information can be retrieved from your database if you already have it stored, or from a form like in the example below:
In this sample, notice how:
The Social Pay inline JavaScript is included using a
script
tag. This is how you import Social Pay into your code.The amount here can be hardcoded if you want to charge a specific amount.
The
Pay
button has been tied to anonClick
function called payWithSocialPay. This is the action that causes the Social Pay popup to load.
Initialize transaction
When you have all the details needed to initiate the transaction, the next step is to tie them to the JavaScript function that passes them to Social Pay and displays the checkout popup modal.
Important notes
The
public_key
field here takes your social pay public_ key.The
cryptocurrency_type
should be the coin symbol e.g $GARY, $DRIVE e.t.c.It's ideal to generate a unique
order_id
from your system for every transaction to avoid duplicate attempts.The
callback
method is called when payment has been completed successfully on the Social Pay checkout. See the next section to see for how to handle the callback.the
onClose
method is called if the user closes the modal without completing payment.
Handle the callback method.
The callback method is fired when the transaction is successful. This is where you include any action you want to perform when the transaction is successful.
The recommended next step here is to verify payment to confirm the status.
Helpful Tip
To verify the transaction, you have to set up a route or page on your server that you pass the transaction reference to. Then from your server, you call the Social Pay verify endpoint to confirm the status of the transaction, and the response is returned to your frontend.
There are 2 ways you can call your server from the callback function
Make an AJAX request to the endpoint on your server that handles the transaction verification
2. Redirect to the server URL by setting a window.location
to the URL where the verification endpoint is set on your server.
Warning
Never call the Social Pay API directly from your front-end to avoid exposing your secret key on the frontend. All requests to the Social Pay API should be initiated from your server, and your frontend gets the response from your server.
Verify the Transaction
After payment is made, the next step is to verify the transaction. Here's how to verify transactions with Social Pay
Handle Webhook
When a payment is successful, Social Pay sends a webhook event to your webhook URL. You can learn more here.
Redirect
Here, you call the Initialize TransactionAPI from your server to generate a checkout link, then redirect your users to the link so they can pay. After payment is made, the users are returned to your website at the redirect_url
Collect customer information
To initialize the transaction, you'll need to pass information such as email, first name, last name amount, oder_id
, etc.
The customer information can be retrieved from your database, session or cookie if you already have it stored, or from a form like in the example below.
Initialize transaction
When a customer clicks the payment action button, initialize a transaction by making a POST request to our API. Pass the email, amount and any other parameters to the Initialize TransactionAPI endpoint.
If the API call is successful, we will return a URL which you will redirect to for the customer to input their payment information to complete the transaction and the transaction reference which you would use to verify the payment status.
Verify Transaction
If the transaction is successful, Social Pay will redirect the user back to a redirect_url
you set. . In the example above, the user will be redirected to. https://your_website.com?order=order_id use the order id to retrieve the transaction reference that was sent earlier and use that to call the verify endpoint to confirm the status of the transaction.
It's very important that you call the Verify endpoint to confirm the status of the transactions before delivering value. Just because the redirect_url
was visited doesn't prove that transaction was successful.
Last updated