Accepting a Payment

Now that you can collect a customer's card information, you are ready to start accepting payments. This is typically done from a server's backend logic. If you imported our Postman Collection, you can follow-along with the examples by invoking the requests in the Charge folder.

The first step when accepting a payment is to create a payment request using the Create Payment API. You'll need your app-id and private-key to create one. Here's an example:

JavaScript
curl
var request = new XMLHttpRequest();
request.open('POST', 'https://api.paymentsos.com/payments');
request.setRequestHeader('Content-Type', 'application/json');
request.setRequestHeader('api-version', '1.2.0');
request.setRequestHeader('x-payments-os-env', 'test');
request.setRequestHeader('app-id', 'com.zooz.docapp');
request.setRequestHeader('private-key', 'bede7ee5-eaaq-4c9a-bc1f-617ba28256ae');
request.setRequestHeader('idempotency-key', 'cust-34532-trans-001356-p');
var body = {
  'amount': 34800,
  'currency': 'EUR',
  'statement_soft_descriptor': 'Oil lamp'};
request.send(JSON.stringify(body));
curl --compressed -X POST \
  https://api.paymentsos.com/payments \
  -H 'Content-Type: application/json' \
  -H 'api-version: 1.2.0' \
  -H 'x-payments-os-env: test' \
  -H 'app-id: com.zooz.docapp' \
  -H 'private-key: bede7ee5-eaaq-4c9a-bc1f-617ba28256ae' \
  -H 'idempotency-key: cust-34532-trans-001356-p' \
  -d '{
  "amount": 31602077,
  "currency": "EUR",
  "statement_soft_descriptor": "Oil lamp"
  }'

The next step depends on the payment flow you want to support. If you take a look at the reply body of the Create Payment API, you will notice some suggestions as to what to do next:

{
    ...
    "possible_next_actions": [
        {
            "action": "Charge",
            "href": "https://api.paymentsos.com/payments/de57b183-37f7-49ae-afe7-58d126b96e78/charges"
        },
        {
            "action": "Authorization",
            "href": "https://api.paymentsos.com/payments/de57b183-37f7-49ae-afe7-58d126b96e78/authorizations"
        },
        {
            "action": "Update Payment",
            "href": "https://api.paymentsos.com/payments/de57b183-37f7-49ae-afe7-58d126b96e78"
        }
    ]
}

Since you're just getting started, let's create a simple one-step flow in which you will use the Create Charge API to immediately transfer the amount charged to your acquiring bank. Make sure you have the card token available, since you will need it to create the charge:

JavaScript
curl
var request = new XMLHttpRequest();
request.open('POST', 'https://api.paymentsos.com/payments/{payment_id}/charges');
request.setRequestHeader('Content-Type', 'application/json');
request.setRequestHeader('api-version', '1.2.0');
request.setRequestHeader('x-payments-os-env', 'test');
request.setRequestHeader('app-id', 'com.zooz.docapp');
request.setRequestHeader('private-key', '0047c4ef-f658-4e6d-a040-5882e2285f34');
request.setRequestHeader('idempotency-key', 'cust-34532-trans-001356-c');
var body = {
  'payment_method': {
    'type': 'tokenized',
    'token': 'f2b9357d-25b1-435b-87c2-b8c00fda6faf'}};
request.send(JSON.stringify(body));
curl --compressed -X POST \
  https://api.paymentsos.com/payments/{payment_id}/charges \
  -H 'Content-Type: application/json' \
  -H 'api-version: 1.2.0' \
  -H 'x-payments-os-env: test' \
  -H 'app-id: com.zooz.docapp' \
  -H 'private-key: bede7ee5-eaaq-4c9a-bc1f-617ba28256ae' \
  -H 'idempotency-key: cust-34532-trans-001356-p' \
  -d '{
  "payment_method": {
    "type": "tokenized",
    "token": "f2b9357d-25b1-435b-87c2-b8c00fda6faf"
  }
}'

That's it! You have just accepted your first payment.

What's next?

Explore the other payment flows and operations.

results matching ""

    No results matching ""