How to process a card payment
Make a card payment to get funds into a Mangopay wallet
Introduction
This how-to guide will take you through the steps to successfully simulate a payment by card in the Sandbox testing environment.
Prerequisites
- A
ClientId
and an API key – if you don’t have these, contact Sales to get access to the Mangopay Dashboard
Note – Postman collection contains this flow
The public Mangopay API Postman collection contains a dedicated folder with the endpoints for this how-to guide.
Get started →1. Create a user
In this guide, we’ll register a natural user to represent a private individual who just needs to make a payment on your platform.
Payers only need to provide a first name, last name, and email (see the user categories for more information).
In response, the API returns an Id
for the user, which you’ll need for the next step.
2. Create a wallet for the user
All users need a wallet to which they can pay funds, even it it is immediately transfered to another wallet (for example, to a marketplace seller).
Use the Id
of the user as the owner of the wallet:
In response, the API returns an Id
for the wallet, which you’ll need to request the payment.
3. Create a card registration
The tokenization process enables your platform to handle sensitive card details with Mangopay.
Create a Card Registration object to start this process, using the Id
of the user as the UserId
.
You also need to define the currency and type of the card at this stage.
In response, the API returns the card registration object:
From this response, you will need the following values for the next step:
AccessKey
PreregistrationData
CardRegistrationURL
4. Send data to the tokenization server
The dedicated tokenization server allows your platform to process sensitive card data without exposing you or your end users to any security risk.
Best practice - Use Mangopay’s card SDKs
Mangopay’s Checkout SDK and Vault SDK take care of the tokenization steps (Steps 2 & 3) for you, and generate a CardId
.
Simplify your integration on web, iOS, and Android.
Make a request to the CardRegistrationURL
using the previously saved AccessKey
and PreregistrationData
:
- Use
AccessKey
data for theaccessKeyRef
parameter - Use
PreregistrationData
data for thedata
parameter
You also need the end user’s card details entered on the payment page:
Property | Type | Description |
---|---|---|
cardNumber | string | The card number to be tokenized, without any separators. |
cardExpirationDate | string (Format: “MMYY”) | The expiration date of the card. |
cardCvx | string | The card verification code (on the back of the card, usually 3 digits). |
Warning - Card details must never pass via your server
For security reasons, it is strictly forbidden to send the card details to your own server. You must rely on the dedicated PCI-DSS compliant tokenization server as described below.
The content-type for this call is “application/x-www-form-urlencoded”.
In response, the API returns an encoded data string:
You’ll need this string for the next step.
5. Update the card registration with tokenization data
Update the Card Registration object by sending the data token returned by the tokenization server as the RegistrationData
.
You should also provide the cardholder’s name at this stage, which will be added to the Card object.
In response, the API returns the Card Registration object.
The CardId
is the tokenized version of the card that you can use in the next step to request the payment.
6. Get the end user’s session data
In your integration, you’ll also need to capture information from your end user’s browsing session to be able to request the payment.
In Sandbox, you can use dummy data.
IP address
You need to send the end user’s IP address in IPV4 or IPV6 format. You can collect this when the user requests the payment, or else use an IP lookup service such as Cloudfare or ipify.
Browser information
You also need to collect data about the end user’s browser.
- On a website, this data can be obtained from the browser.
- In a mobile app, you need to open a webview to fetch data from the browser (in the same way as for a website).
7. Request the payment (Direct Card PayIn)
Now that you have a CardId
, you can request the payment to the wallet using the Direct Card PayIn object.
Note - Recurring card payments and preauthorizations require other endpoints
The Direct Card PayIn object represents a one-time payment with a registered card.
For subscriptions and other recurring card payments, use the Recurring PayIn Registration object.
To reserve funds on a card for capture later, use the Preauthorization and Deposit Preauthorization objects.
Create the pay-in request using:
- The
CardId
- The IP address and browser information
- The
Id
of the User as theAuthorId
- The
Id
of the user’s Wallet as theCreditedWalletId
In your integration, when you make the payment request you also need to:
- Be ready to handle 3DS authentication (Step 6)
- Specify the page to which the user will be returned after payment (Step 7)
Read these steps before continuing with the payment request:
8. Redirect the user to 3DS protocol (if required)
Redirect the user to the SecureModeRedirectURL
value to complete strong customer authentication with the 3DS protocol, unless it is null
. If SecureModeRedirectURL
is null
, this means that 3DS is not required and no redirection is needed.
You can also use the SecureModeNeeded
boolean to determine this redirection behavior.
In Sandbox, follow the link returned in the SecureModeRedirectURL
to access the authentication simulator.
9. Return the user after payment
After the payment, whether it includes 3DS or not and whatever the outcome, the end user is returned to the SecureModeReturnURL
which you defined.
The Mangopay API returns your SecureModeReturnURL
with the Id
of the pay-in transaction attached as a query parameter in the following format:
https://www.example.com?transactionId=
Id
Mangopay updates the Status
of the pay-in to indicate a successful or failed payment depending on the outcome of the end user’s authentication.
You should set up hook notifications for the following event types to be notified of the outcome:
- PAYIN_NORMAL_SUCCEEDED
- PAYIN_NORMAL_FAILED
Once your system receives a webhook, call the GET View a PayIn endpoint (using its Id
) to confirm the result of the transaction. This allows you to customize the end user’s experience after the payment.
If the pay-in is successful, the card’s Validity
parameter is set to Valid
and it can be used for other payments at a later stage.
10. Deactivate the card (if required)
Warning - End user’s approval needed to save card details
Under no circumstances should card information be kept without the end user’s approval.
If you don’t have the end user’s approval, you need to deactivate the card systematically after use in your implementation.
Once the pay-in is successful, if the end user did not request to save their card for later, set the card’s Active
parameter to false to deactivate the card. This action is irreversible.
Note - The card can be registered multiple times
Deactivating the card will not prevent the end user from making a payment with the same card in future. You will need to go through the card registration process again.