In this tutorial, we'll step through the API calls required to create a B2B payment.
In a B2B payment, you - a business or institution - are the payment originator and you're paying another business or institutional beneficiary.
While this tutorial focuses on paying a business beneficiary, the process is similar for paying an individual beneficiary. To pay an individual beneficiary, specify their beneficiaryIdentityId in the Create payment step.
There are three main steps for creating a payment where you are the originator:
- Create a quote collection for a proposed payment.
- Create payment to begin the payment process.
- Get a payment to view details about the initiated payment.
You must have the following items to be able to carry out the steps in this tutorial:
- An access token to access secured API endpoints.
- Obtain the beneficiary
identityIDusing the Get a list of identities operation.- A
beneficiaryIdentityIdidentifies the beneficiary of your payment and is required for all payments. This value is theidentityIdassociated with the identity of the beneficiary you want to pay.
- A
The API calls in this tutorial use the test environment with https://api.test.ripple.com/v2 as the base URL.
We'll begin by calling the Create quote collection operation, which returns a collection of quotes containing one or more quotes for a payment using the chosen payout method.
In this tutorial, we are sending 10,000 USD to a beneficiary in Mexico, who will receive it in MXN in their bank account.
You must include the following parameters in the request body:
quoteAmount: Set this value to10000.quoteAmountType: Set this value toSOURCE_AMOUNT.- Setting this value returns a quote for the amount you want to send and not the amount the beneficiary of this payment will receive.
sourceCurrency: Set this value toUSD.destinationCurrency: Set this value toMXN.sourceCountry: Set this value toUS.destinationCountry: Set this value toMX.payoutCategory: Set this value toBANK.payinCategory: Set this value toFUNDED.
This field must be specified if destinationCurrency is a fiat currency. If destinationCurrency is a digital asset, the destinationCountry field is not required.
{
"quoteAmount": 10000,
"quoteAmountType": "SOURCE_AMOUNT",
"sourceCurrency": "USD",
"destinationCurrency": "MXN",
"sourceCountry": "US",
"destinationCountry": "MX",
"payoutCategory": "BANK",
"payinCategory": "FUNDED"
}The response contains an array of one or more quote objects as a collection. Each quote object contains a unique quoteId and quote details such as the amount that the beneficiary will receive, foreign exchange (FX) rate, and fees.
Each quote includes an expiresAt field the indicates the expiration date and time of the quote. You must create a payment using the quoteId before it expires.
{
"quoteCollectionId": "11111111-aaaa-2222-bbbb-222222222222",
"quotes": [
{
"quoteId": "7ea3399c-1234-5678-8d8f-d320ea406630",
"quoteStatus": "ACTIVE",
"quoteAmountType": "SOURCE_AMOUNT",
"sourceAmount": 10000,
"destinationAmount": 204533.3,
"sourceCurrency": "USD",
"destinationCurrency": "MXN",
"sourceCountry": "US",
"destinationCountry": "MX",
"payoutCategory": "BANK",
"payinCategory": "FUNDED",
"adjustedExchangeRate": {
"adjustedRate": 20.4136
},
"fees": [
{
"totalFee": 14,
"feeCurrency": "USD",
"feeBreakdown": [
{
"calculatedFee": 3,
"feeName": "Example flat service fee",
"feeDescription": "Fees with unit 3$ FLAT"
},
{
"calculatedFee": 11,
"feeName": "Example BPS service fee",
"feeDescription": "Fees with unit BPS"
}
]
}
],
"createdAt": "2025-02-13T22:44:34.711Z",
"expiresAt": "2025-02-13T22:59:34.767Z"
}
]
}Now that we have the quote for the payment, it's time to create the payment using the quoteId.
To do this, we'll call the create payment operation to start the payment process.
- You must have the
quoteIdof the quote you want to accept from the create a quote response. - You must have the
identityIdof the beneficiary.
Construct the request body as follows:
quoteId: Set this value to thequoteIdyou received in the Create quote collection response.beneficiaryIdentityId: Set this value to the UUID associated with the beneficiary identity.internalId: This example usesInvoice-123.- Note : This is a required sender-created ID to use with filtering in other API operations.
purposeCode: This example usesPAYRto indicate that the Purpose of this payment is payroll.sourceOfCash: This example usesSVGSto indicate that the Source of Cash for this payment is savings.
{
"quoteId": "7ea3399c-1234-5678-8d8f-d320ea406630",
"beneficiaryIdentityId": "22222222-aaaa-2222-bbbb-222222222222",
"internalId": "Invoice-123",
"purposeCode": "PAYR",
"sourceOfCash": "SVGS"
}A success response from the API contains the paymentId and other information you can use to monitor the status of the payment.
{
"paymentId": "7ea3399c-1234-5678-8d8f-d320ea406630",
"initiatedAt": "2025-02-13T23:24:15.770Z",
"expiresAt": "2025-04-14T23:24:15.770Z",
"lastStateUpdatedAt": "2025-02-13T23:24:15.770Z",
"paymentState": "TRANSFERRING",
"originator": {
"internalId": "Invoice-123",
"sourceCountry": "US",
"sourceCurrency": "USD",
"sourceAmount": 10000,
"payin": "FUNDED"
},
"destination": {
"destinationAmount": 203766.88,
"destinationCountry": "MX",
"destinationCurrency": "MXN",
"beneficiaryIdentityId": "22222222-aaaa-2222-bbbb-222222222222",
"beneficiaryIdentityVersion": 1,
"beneficiaryIdentityNickName": "Successful Beneficiary",
"payout": "BANK"
},
"fxRate": 20.4052,
"adjustedExchangeRate": {
"adjustedRate": 20.3422
},
"fees": [
{
"totalFee": 14,
"feeCurrency": "USD"
}
],
"purposeCode": "PAYR",
"transactionDetails": {
"paymentProduct": "PAYMENTS_DIRECT",
"flowType": "B2B",
"thirdPartyPayment": false,
"businessUseCase": "FIAT_TRANSFER"
}
}Use the get payment by payment ID operation to look up the status of a payment.
Use the paymentId path parameter to specify the unique ID of the payment whose status you want to monitor.
- Test environment with simulated currency
https://api.test.ripple.com/v2/payments/{paymentId}
- Production environment
https://api.ripple.com/v2/payments/{paymentId}
- curl
- Python
curl -i -X GET \
https://api.test.ripple.com/v2/payments/7ea3399c-1234-5678-8d8f-d320ea406630 \
-H 'Authorization: Bearer <YOUR_JWT_HERE>'Check the paymentState field in the response for the current payment state.
{
"paymentId": "7ea3399c-1234-5678-8d8f-d320ea406630",
"initiatedAt": "2025-02-13T23:24:15.770Z",
"expiresAt": "2025-04-14T23:24:15.770Z",
"lastStateUpdatedAt": "2025-02-13T23:24:15.770Z",
"paymentState": "INITIATED",
"originator": {
"internalId": "Invoice-123",
"sourceCountry": "US",
"sourceCurrency": "USD",
"sourceAmount": 10000,
"payin": "FUNDED"
},
"destination": {
"destinationAmount": 203766.88,
"destinationCountry": "MX",
"destinationCurrency": "MXN",
"beneficiaryIdentityId": "22222222-aaaa-2222-bbbb-222222222222",
"beneficiaryIdentityVersion": 1,
"beneficiaryIdentityNickName": "Successful Beneficiary",
"payout": "BANK"
},
"fxRate": 20.4052,
"fees": [
{
"totalFee": 14,
"feeCurrency": "USD"
}
],
"purposeCode": "PAYR"
}In addition to getting the current state of a payment, you can also use the get state transitions operation to see when the payment transitioned between states.
- Test environment with simulated currency
https://api.test.ripple.com/v2/payments/{paymentId}/states
- Production environment
https://api.ripple.com/v2/payments/{paymentId}/states
- curl
- Python
curl -i -X GET \
https://api.test.ripple.com/v2/payments/7ea3399c-1234-5678-8d8f-d320ea406630/states \
-H 'Authorization: Bearer <YOUR_JWT_HERE>'Examine the response to view the state transitions.
{
"stateTransitions": [
{
"updatedFrom": "QUOTED",
"updatedTo": "INITIATED",
"updatedAt": "2025-02-21T15:32:34.557Z"
},
{
"updatedFrom": "INITIATED",
"updatedTo": "VALIDATING",
"updatedAt": "2025-02-21T15:32:38.380Z"
},
{
"updatedFrom": "VALIDATING",
"updatedTo": "TRANSFERRING",
"updatedAt": "2025-02-21T15:32:49.552Z"
},
{
"updatedFrom": "TRANSFERRING",
"updatedTo": "COMPLETED",
"updatedAt": "2025-02-21T15:34:54.496Z"
}
]
}