Accept a payment

Learn how to accept payments with the Unzer API, with a simple example: directly charging a credit card.

Introduction

To have a quick look at the Unzer API workflow, let’s charge a credit card as a simple example.

For a more detailed tutorial on charging credit cards with the Unzer API, go to Credit card.

For more detailed tutorials on other payment methods, go to Supported payment methods.

Step 1: Create a payment type resource

First, you need to create a new payment type resource.

Let’s say this is your customer’s credit card:

  • Number: 4444333322221111
  • Expiry date: 04/25
  • Card holder: Anna Smith
  • CVC: 123

To create a payment type resource for this card, make a POST call to the types/card endpoint:

POST https://api.unzer.com/v1/types/card

{
  "number" : "4444333322221111",
  "expiryDate" : "04/25",
  "cvc": "123",
  "3ds": "false",
  "cardHolder": "Anna Smith"
}
{
    "id": "s-crd-wln5j3zcmjzi",
    "method": "card",
    "number": "444433******1111",
    "brand": "VISA",
    "cvc": "***",
    "expiryDate": "04/2025",
    "3ds": false,
    "cardHolder": "Anna Smith",
    "cardDetails": {
        "cardType": "",
        "account": "CREDIT",
        "countryIsoA2": "US",
        "countryName": "UNITED STATES",
        "issuerName": "",
        "issuerUrl": "",
        "issuerPhoneNumber": ""
      },
  	"geoLocation": {
    	"clientIp": "115.77.189.143",
    	"countryCode": "VN"
 		}
}

Step 2: Charge the payment type resource

After creating a types/card resource, you can charge it by its id. In our example, the id is s-crd-wln5j3zcmjzi: you received it in response to your first call in Step 1.

To charge the newly-created types/card resource, make a POST call to the payments/charges endpoint:

POST https://api.unzer.com/v1/payments/charges
{
  "amount": "100",
  "currency": "EUR",
  "card3ds": "false",
  "returnUrl": "https://www.unzer.com",
  "cardHolder": "Anna Smith",
  "resources": {
    "typeId": "s-crd-wln5j3zcmjzi"
  }
}
{
    "id": "s-chg-1",
    "isSuccess": true,
    "isPending": false,
    "isError": false,
    "message": {
        "code": "COR.000.100.112",
        "merchant": "Request successfully processed in 'Merchant in Connector Test Mode'",
        "customer": "Your payments have been successfully processed in sandbox mode."
    },
    "amount": "100.0000",
    "currency": "EUR",
    "returnUrl": "http://tinhte.vn",
    "date": "2020-11-04 15:41:11",
    "resources": {
        "paymentId": "s-pay-97200",
        "traceId": "4210ab81d09a0f504b45307b4d36ef00",
        "typeId": "s-crd-wln5j3zcmjzi"
    },
    "paymentReference": "",
    "processing": {
        "creatorId": "13213213344324324",
        "identification": "4684.3087.1849",
        "iban": "DE89370400440532013000",
        "bic": "COBADEFFXXX",
        "uniqueId": "31HA07BC81A7A34627C2AED4F3C3EE07",
        "shortId": "4684.3087.1849",
        "traceId": "4210ab81d09a0f504b45307b4d36ef00"
    }
}

Step 3: Get a notification

Now, you can get a webhook notification triggered by a successful charging of the card:

{
  "event":"charge.succeeded",
  "publicKey":"s-pub-xxxxxxxxxx",
  "retrieveUrl":"https://api.unzer.com/v1/payments/s-pay-97200",
  "paymentId":"s-pay-97200"
}

For more details on setting up notifications, go to Notifications.