Ginger Payments

API basics

How to connect to the Ginger Payments API, authenticate your requests and handle responses and errors.

Connect securely

The API is only available over HTTPS with TLS 1.2 or newer. This protects your customers' data on its way between your server and Ginger Payments.

Most modern HTTP clients support TLS 1.2 by default. If you use an old library or an old version of a programming language, update it.

All requests go to https://api.dev.gingerpayments.com, followed by the path of the endpoint, such as /v1/orders/. Card data for server-to-server payments goes to the card vault at https://tokens.dev.gingerpayments.com.

Authenticate

Authenticate every request with HTTP Basic authentication. Your project's API key is the username, and the password is empty.

Most HTTP clients handle Basic authentication for you. With cURL:

curl https://api.dev.gingerpayments.com/v1/merchants/self/projects/self/ \
  --user "$API_KEY:"

If your client doesn't support Basic authentication, build the Authorization header yourself: encode your API key followed by a colon (:) with Base64. For the API key hunter2, you encode hunter2:, which results in this header:

Authorization: Basic aHVudGVyMjo=

Keep your API key secret

The API key gives full access to your project. Only use it from your server. Never put it in a browser, mobile app or public repository.

HTTP status codes

The API uses standard HTTP status codes.

CodeNameMeaning
200OKThe request succeeded. The response body contains the requested data.
201CreatedThe resource has been created.
202AcceptedThe request has been accepted, but processing isn't finished yet.
204No ContentThe request succeeded. The response has no body.
400Bad RequestThe request is invalid. Check the parameters and the body.
401UnauthorizedAuthentication failed or is missing. Check your API key.
403ForbiddenYou don't have permission for this action.
404Not FoundThe resource doesn't exist.
409ConflictThe request conflicts with the current state of the resource.
422Unprocessable EntityThe request is well-formed, but validation failed.
429Too Many RequestsYou've exceeded the rate limit. Try again later.
500Internal Server ErrorSomething unexpected went wrong on the server.
502Bad GatewayAn upstream service returned an invalid response.
503Service UnavailableThe service is temporarily unavailable. Try again later.
504Gateway TimeoutAn upstream service didn't respond in time.

Handle 2xx responses

A 2xx response means Ginger Payments received and accepted your request. It doesn't mean the payment succeeded: check the status in the response.

For example, when you start a card payment:

  1. The API responds with 200 OK or 201 Created. Ginger Payments has your request and processes the payment, but the outcome isn't known yet.
  2. The card issuer declines the card. No money is collected.
  3. Ginger Payments sends a webhook because the order status changed.
  4. You retrieve the order. The status is error, and the reason field briefly explains why. See Error reasons.

Handle 4xx and 5xx responses

Ginger Payments doesn't accept or store your request when:

  • the request doesn't pass validation;
  • the request violates a security constraint;
  • the request violates a configuration constraint, such as a payment method that isn't active for your project;
  • an internal error occurs at Ginger Payments.

You receive an error response that describes the problem. Handle it as an exception in your code. Rejected requests aren't charged.

Error response

An error response contains an error object:

{
  "error": {
    "status": 400,
    "type": "RefundError",
    "value": "Cannot refund more (500) than the remaining order amount (0)"
  }
}
FieldTypeDescription
statusIntegerThe HTTP status code.
typeStringThe type of error. See the table below.
valueStringA short explanation of the problem.

Common error types:

TypeMeaning
ValidationErrorThe request doesn't match the API schema, for example a missing or invalid field.
MissingInformationToCreateTransactionInformation needed to create the transaction is missing.
TransactionAlreadyStartedThe transaction has already started and can't be started again.
CanNotCancelTransactionThe transaction can't be cancelled in its current state.
RefundErrorThe refund isn't possible, for example because it exceeds the remaining amount.
FailedToFetchTransactionInformationThe transaction information couldn't be retrieved.
ServerErrorAn unexpected error occurred at Ginger Payments.

On this page