Payments API

Create a payment

POST

Create and authorize a payment for a given customer order. You should provide a payment method token here to avoid PCI implications.

If only a payment method token is passed, the values passed with the Client Session is used to determine the amount, currency etc. Note: amount, currencyCode and orderId are required during payment creation. Make sure to pass these fields when creating a client session, or if not yet available, when creating a payment.

All fields provided on this request will take preference over any field on the order associated with the client session. E.g. if you pass amount on this request, it will override the amount on the order associated with the Client Session. Parameters that are not on this request will be fetched from previously created Client Session and merged. E.g. if you specify customer.billingAddress in Client Session and then pass customer.emailAddress data with this request, it will automatically merge the customer fields and use both billingAddress and emailAddress for later calculations.

Headers

X-Idempotency-KeystringOptional
Optional key to make the request idempotent. Enables a safe retry of a request without risking the user being charged or refunded multiple times. The idempotency key must be generated by the client and needs to be unique for every new request.

Request

This endpoint expects an object.
paymentMethodToken
stringRequired
The payment method token used to authorize the payment.
orderId
stringOptional
Your reference for the payment.
currencyCode
enumOptional

The 3-letter currency code in ISO 4217 format. e.g. use USD for US dollars.

amount
integerOptional

The amount you would like to charge the customer, in minor units. e.g. for $7, use 700.

Some currencies, such as Japanese Yen, do not have minor units. In this case you should use the value as it is, without any formatting. For example for ¥100, use 100. The minimum amount is 0.

order
objectOptional
More information associated with the order.
customerId
stringOptional

A unique identifier for your customer. This attribute is required if paymentMethod.vaultOnSuccess is set to True.

customer
objectOptional
More information associated with the customer.
metadata
map from strings to anyOptional

Additional data to be used throughout the payment lifecycle.

A dictionary of key-value pairs where the values can only be strings or integers.

e.g. {"productId": 1001, "merchantId": "a13bsd62s"}

paymentMethod
objectOptional
Enable certain options associated with the payment method.

Response

This endpoint returns an object
id
stringOptional

The unique payment ID.

You can use this ID to retrieve the payment details, or perform downstream operations.

date
datetimeOptional
The date and time at which the payment was created in UTC format.
dateUpdated
datetimeOptional
The date and time of the last payment update in UTC format.
status
enumOptional
cardTokenType
enumOptional

The type of card token used for the payment.

Only applies for card payments.

Allowed values: CARD_PANNETWORK_TOKENPROCESSOR_TOKEN
orderId
stringOptional
Your reference for the payment.
currencyCode
enumOptional

The 3-letter currency code in ISO 4217 format. e.g. use USD for US dollars.

amount
integerOptional
The amount you charged the customer, in minor units.
order
objectOptional
More information associated with the order.
customerId
stringOptional
The unique identifier for your customer.
customer
objectOptional
More information associated with the customer.
metadata
map from strings to anyOptional
Additional data to be used throughout the payment lifecycle.
paymentMethod
objectOptional
The payment method options provided in the request, as well as the token used to process the payment.
processor
objectOptional
More information associated with the payment processor, including the processor name.
requiredAction
objectOptional
Required action to perform in order to resume the payment workflow. This can be requiring a 3DS check from the customer for instance.
statusReason
objectOptional

Check this field for more information regarding the payment’s status. This is especially useful when the status is DECLINED or FAILED.

transactions
list of objectsOptional

A list summarizing the transactions that occurred while processing the payment.

Note: a refund is a separate transaction and so will appear in this transactions list if a refund was performed.

riskData
objectOptional
Risk data associated with this payment.

Errors

POST
$curl -X POST https://api.sandbox.primer.io/payments \
> -H "X-API-KEY: <apiKey>" \
> -H "Content-Type: application/json" \
> -d '{
> "paymentMethodToken": "string",
> "currencyCode": "AED",
> "order": {
> "lineItems": [
> {
> "amount": 1,
> "productType": "PHYSICAL",
> "productData": {}
> }
> ],
> "countryCode": "AW",
> "retailerCountryCode": "AW",
> "fees": [
> {
> "amount": 1
> }
> ],
> "shipping": {}
> },
> "customer": {
> "billingAddress": {
> "countryCode": "AW"
> },
> "shippingAddress": {
> "countryCode": "AW"
> }
> },
> "paymentMethod": {
> "paymentType": "FIRST_PAYMENT",
> "authorizationType": "ESTIMATED"
> }
>}'
Response
1{
2 "id": "kHdEw9EG",
3 "date": "2021-02-21T15:36:16.367687",
4 "dateUpdated": "2021-02-21T15:36:17.133701",
5 "status": "AUTHORIZED",
6 "cardTokenType": "CARD_PAN",
7 "orderId": "order-abc",
8 "currencyCode": "EUR",
9 "amount": 42,
10 "order": {
11 "lineItems": [
12 {
13 "amount": 1,
14 "productType": "PHYSICAL",
15 "productData": {}
16 }
17 ],
18 "countryCode": "AW",
19 "retailerCountryCode": "AW",
20 "fees": [
21 {
22 "amount": 1
23 }
24 ],
25 "shipping": {}
26 },
27 "customerId": "customer-123",
28 "customer": {
29 "billingAddress": {
30 "countryCode": "AW"
31 },
32 "shippingAddress": {
33 "countryCode": "AW"
34 }
35 },
36 "metadata": {
37 "productId": 123,
38 "merchantId": "a13bsd62s"
39 },
40 "paymentMethod": {
41 "descriptor": "Purchase: Socks",
42 "paymentType": "SUBSCRIPTION",
43 "paymentMethodToken": "heNwnqaeRiqvY1UcslfQc3wxNjEzOTIxNjc4",
44 "isVaulted": true,
45 "analyticsId": "VtkMDAxZW5isH0HsbbNxZ3lo",
46 "paymentMethodType": "PAYMENT_CARD",
47 "paymentMethodData": {
48 "first6Digits": "411111",
49 "last4Digits": "1111",
50 "expirationMonth": "12",
51 "expirationYear": "2030",
52 "cardholderName": "John Biggins",
53 "network": "Visa",
54 "isNetworkTokenized": false,
55 "binData": {
56 "network": "VISA",
57 "issuerCountryCode": "AW",
58 "issuerCurrencyCode": "AED",
59 "regionalRestriction": "UNKNOWN",
60 "accountNumberType": "UNKNOWN",
61 "accountFundingType": "UNKNOWN",
62 "prepaidReloadableIndicator": "NOT_APPLICABLE",
63 "productUsageType": "UNKNOWN",
64 "productCode": "VISA",
65 "productName": "VISA"
66 }
67 },
68 "threeDSecureAuthentication": {
69 "responseCode": "NOT_PERFORMED",
70 "reasonCode": "GATEWAY_UNAVAILABLE"
71 },
72 "authorizationType": "FINAL"
73 },
74 "processor": {
75 "name": "STRIPE",
76 "processorMerchantId": "acct_stripe_1234",
77 "amountCaptured": 0,
78 "amountRefunded": 0
79 },
80 "requiredAction": {
81 "name": "3DS_AUTHENTICATION",
82 "description": "string"
83 },
84 "statusReason": {
85 "type": "APPLICATION_ERROR",
86 "declineType": "SOFT_DECLINE",
87 "code": "ERROR"
88 },
89 "transactions": [
90 {
91 "date": "string",
92 "amount": 1,
93 "currencyCode": "AED",
94 "processorMerchantId": "acct_stripe_1234",
95 "transactionType": "SALE",
96 "processorTransactionId": "54c4eb5b3ef8a",
97 "processorName": "STRIPE",
98 "processorStatus": "AUTHORIZED",
99 "processorStatusReason": {
100 "type": "APPLICATION_ERROR",
101 "declineType": "SOFT_DECLINE",
102 "code": "ERROR"
103 },
104 "cardTokenType": "CARD_PAN"
105 }
106 ],
107 "riskData": {
108 "fraudChecks": {
109 "source": "FRAUD_PROVIDER",
110 "preAuthorizationResult": "THREE_DS",
111 "postAuthorizationResult": "ACCEPT"
112 },
113 "cvvCheck": {
114 "source": "PROCESSOR",
115 "result": "MATCHED"
116 },
117 "avsCheck": {
118 "source": "PROCESSOR",
119 "result": {
120 "streetAddress": "NOT_MATCHED",
121 "postalCode": "NOT_VERIFIED"
122 }
123 }
124 }
125}