Snipcart API Endpoints
The base url for the custom payment gateway API is https://payment.snipcart.com/api
/validate
/payment-session
/payment
Validate public token
GET
/public/custom-payment-gateway/validate?publicToken=<SOME_TOKEN>
This is important to prevent fraudulent payments
When calling your API, we will always send a publicToken
. Use this endpoint to validate the request was made by our API.
This token should always be validated to prevent fraudulent attempts.
Request
publicToken
string
- Required
The public key of an ongoing payment sessions.
curl --request GET \
--url 'https://payment.snipcart.com/api/public/custom-payment-gateway/validate?publicToken=<SOME_TOKEN>' \
Retrieve a payment session
GET
/public/custom-payment-gateway/payment-session?publicToken=<SOME_TOKEN>
Retrieves the payment session from the publicToken.
Request
publicToken
string
- Required
The public key of an ongoing payment sessions.
curl --request GET \
--url 'https://payment.snipcart.com/api/public/custom-payment-gateway/payment-session?publicToken=<SOME_TOKEN>' \
Response
id
Guid
The payment session's Id.
invoice
Invoice
The session's invoice
paymentAuthorizationRedirectUrl
string
The url to redirect to once the checkout flow is completed.
{
"invoice": {
"shippingAddress": {
"name": "John Doe",
"streetAndNumber": "123 Street",
"postalCode": "12345",
"country": "US",
"city": "Cuppertino",
"region": null
},
"billingAddress": {
"name": "John Doe",
"streetAndNumber": "123 Street",
"postalCode": "12345",
"country": "US",
"city": "Cuppertino",
"region": null
},
"email": "john.doe@example.com",
"language": "en",
"currency": "usd",
"amount": 409.29,
"targetId": "226086da-57be-4b92-b950-5fd632be7767",
"items": [
{
"name": "Rosy-Fingered Dawn at Louse Point",
"unitPrice": 49.95,
"quantity": 1,
"type": "Physical",
"rateOfTaxIncludedInPrice": 0,
"amount": 49.95
},
...
]
},
"id":"b2eb036a-842ee242-0d2d-4fad-bc9a-de16411fc6d1",
"paymentAuthorizationRedirectUrl":"https://example.com#/checkout",
}
Create payment
POST
/private/custom-payment-gateway/payment
Creates a payment for the payment session (confirms the payment)
Request
HeadersAuthorization
string
- RequiredBearer <YOUR_SECRET_API_KEY>
The authorization request header is used to validate your credentials with the server. Its value must be a bearer token that contains your secret API key.
Content-Type
string
- Requiredapplication/json
Our API only accepts application/json content type, so you must always specify the application/json
content type in each request you make.
BodypaymentSessionId
string
- Required
The ID of the payment session
state
"processing" | "processed" | "invalidated" | "failed"
- Required
The current state of the payment. Possible values are: processing
, processed
, invalidated
and failed
.
transactionId
string
- Required
The unique ID of the transaction. The payment gateway often provides this.
error
Error
Represents the error message you want to display to the customer inside the payment step if applicable.
Errorcode
string
- Required
This is used to used to localize the message in the cart.message
string
This is used as a fallback when no match is found for code
instructions
string
Additional instructions you want to display to your customer inside the order confirmation screen.
links
Links
Linksrefunds
string
This will be called when a refund is issued via the merchant dashboard
curl --request POST \
--url https://payment.snipcart.com/api/private/custom-payment-gateway/payment \
--header 'Authorization: Bearer <YOUR_SECRET_API_KEY>' \
--header 'content-type: application/json' \
--data '{
"paymentSessionId": "5e921d3b-8756-4fd0-87e9-c72f946535ed",
"state": "failed",
"error": {
"code": "card_declined",
"message": "Your card was declined"
}
}'
Webhooks
Those are the API endpoints you will need to create to integrate your own Payment gateway. Our API will call them with a publicToken
in the request body.
Don't forget to validate the request by using the /validate
endpointpayment-methods
refund
Payment methods
The first important endpoint your API should have is one returning the available payment methods. When a client checkouts, we will call your API endpoint to show them the available payment methods.
We will send a POST
request to the payment method URL
specified in the merchant dashboard.
We expect to receive an array of PaymentMethod
.
Request
Method POST
Bodyinvoice
Invoice
The invoice of the current order
publicToken
string
Used to validate the request was made by Snipcart
mode
"test" | "live"
The order's mode.
{
"invoice": {
"shippingAddress": {
"name": "John Doe",
"streetAndNumber": "123 Street",
"postalCode": "12345",
"country": "US",
"city": "Cuppertino",
"region": null
},
"billingAddress": {
"name": "John Doe",
"streetAndNumber": "123 Street",
"postalCode": "12345",
"country": "US",
"city": "Cuppertino",
"region": null
},
"email": "john.doe@example.com",
"language": "en",
"currency": "usd",
"amount": 409.29,
"targetId": "226086da-57be-4b92-b950-5fd632be7767",
"items": [
{
"name": "Rosy-Fingered Dawn at Louse Point",
"unitPrice": 49.95,
"quantity": 1,
"type": "Physical",
"rateOfTaxIncludedInPrice": 0,
"amount": 49.95
},
...
]
},
"publicToken": "<JWT_TOKEN>",
"mode": "test"
}
Response
BodyPaymentMethods[]
- Required
The available payment methods for the current order.
PaymentMethodid
string
- Required
This is the id of the payment method.
name
string
- Required
The name of the payment method (this will be shown during the checkout phase)
checkoutUrl
string
- Required
The url of your checkout page.
iconUrl
string
If you'd like to show an icon instead of a name during the checkout phase, you can set it here.
Note that only the name or the icon will be shown, not both
[
{
"id": "snipcart_custom_gatway_1",
"name": "Custom gateway 1",
"checkoutUrl": "https://snipcart.com/checkout_gateway_1",
},
{
"id": "snipcart_custom_gatway_2",
"name": "Custom gateway 2",
"checkoutUrl": "https://snipcart.com/checkout_gateway_2",
"iconUrl": "https://snipcart.com/checkout_gateway_2/icon.png"
}
]
Refund
This is the refund endpoint you can provide when confirming the payment with our api. When refunding a client from the merchant dashboard, this endpoint will be called.
Request
Method POST
BodypaymentId
string
The payment we want to refund.
amount
number
The amount to want to refund.
{
"paymentId": "d3031d89-e428-4cb8-bf0e-74b883466736",
"amount": 20.75
}
Response
refundId
Guid
The id of the refund.
{
"body": {
"refundId": "940bb5bc-13f7-4d02-987f-fad12ab98ebb"
}
}
Types
Invoice
shippingAddress
Address
The order's shipping address.
billingAddress
Address
The order's billing address.
email
string
The client's email address.
language
string
The cart's language.
currency
string
The order's currency.
amount
number
The order's grand total.
targetId
Guid
The cart's ID
items
Item[]
The order's items.
{
"shippingAddress": {
...
},
"billingAddress": {
...
},
"email": "john.doe@example.com",
"language": "en",
"currency": "usd",
"amount": 409.29,
"targetId": "226086da-57be-4b92-b950-5fd632be7767",
"items": [
...
]
}
Address
name
string
Recipient's full name (first name and last name)
streetAndNumber
string
Street and civic street number.
postalCode
string
country
string
city
string
{
"name": "John Doe",
"streetAndNumber": "123 Street",
"postalCode": "12345",
"country": "US",
"city": "Cuppertino",
"region": null
}
Item
name
string
unitPrice
number
The price of the item
quantity
number
type
"Physical" | "Digital" | "Tax" | "Shipping" | "Discount"
Represents the item type.
rateOfTaxIncludedInPrice
number
amount
number
The quantity
* unitPrice
{
"name": "Rosy-Fingered Dawn at Louse Point",
"unitPrice": 49.95,
"quantity": 1,
"type": "Physical",
"rateOfTaxIncludedInPrice": 0,
"amount": 49.95
}