Create a Payment

5 minute read

What is a Payment?

When the user wants to perform a purchase in you platform, you need to initiate a Payment in Ping. A Payment represents a single attempt of purchase. In this request you provide key information such as amount, payment method and recipients.


Example

Example showing how to initiate a card payment and what response you will get.

Request

curl --location 'https://sandbox.pingpayments.com/payments/api/v1/payment_orders/<YOUR-PAYMENT-ORDER-ID>/payments' \
--header 'x-api-secret: <YOUR-API-SECRET>' \
--header 'tenant_id: <YOUR-TENANT-ID>' \
--header 'Content-Type: application/json' \
--data-raw '{
    "order_items": [
      {
        "amount": 29900,
        "metadata": {},
        "name": "Test Purchase",
        "merchant_id": <YOU-MERCHANT-ID>,
        "vat_rate": "0",
        "tags": []
      }
    ],
    "payer": {
        "name": "John Doe",
    },
    "provider_method_parameters": {
        "error_url": "https://<YOUR-DOMAIN>/error/",
        "success_url": "https://<YOUR-DOMAIN>/success/",
        "cashier": {}
    }, 
    "metadata": {},
    "currency": "SEK",
    "method": "card",
    "provider": "payment_iq",
    "status_callback_url": "https://<YOUR-DOMAIN>/ping-callback/payment_status",
    "total_amount": 29900
}'

Response

{
    "id": "c7a35333-7d56-4fc7-8f68-67a7f8f7a0a3",
    "provider_method_response": {
        "pay_url": "https://piq-sandbox.pingpayments.com/pay/EdDAb27i?locale=en-US"
    }
}

Parameters

Request Parameters

NameDescription
currencyISO 4217 currency code for all underlying Payments (e.g. EUR, SEK). Must be the same as the PaymentOrder currency.
metadataMetadata from your domain. We encourage to provide as much as possible since it is useful in support cases.
methodThe payment method for the selected provider. (more information in next section)
providerThe payment provider which facilitates the payment. (more information in next section)
provider_method_parametersSpecific information required for the selected payment method. (more information in next section)
order_itemsItems of purchase and who the recipient is. See InitiatePayment for the full specification.
payerThe individual/organization which is performing the payment. Populate this as thorough as you can.
status_callback_urlThe URL which Ping will send callbacks to regarding the specific payment.
total_amountThe total amount in minor currency unit. For example 10000 represent 100 in a euro payment. This amount must sum with all the amount's in the order_item list.

Response Parameters

NameDescription
idThe ID of the Payment.
provider_method_responseInformation forwarded from the payment provider. In the example above this includes a url to a checkout.

Selecting a Payment Method

To select and successfully initiate a payment with a specific payment method three fields are relevant, provider, method and provider_method_parameters

By combining provider and method you can select which payment method will be used for the payment. The provider_method_parameters is specific information for the selected payment method which the payment provider relies on.

Provider Method Mapping

ProviderMethodPayment typeDescription
swishe_commercemobile, immediateSwish e-commerce payments use the payer’s number and await confirmation in the Swish app - display a spinner prompting users to open Swish to complete.
swishm_commercemobile, immediateSwish m-commerce payments aren’t pre-seeded with the payer’s number—users scan a QR code or launch the Swish app via its URL schema to complete the payment.
payment_iqcardcard payment, immediateRegular card payments provided through PaymentIQ (Worldline).
pingdepositbank transfer, (0-2 banking days)Generic bank transfers use reference numbers; the payment completes once the funds hit your Ping account.
bankgirotautogiroaccount-to-account, bank settlements (1-2 banking daysTraditional Swedish mandate payment method, commonly used for recurring payments.

Status callback

Ping will post callbacks to the provided status_callback_urlto let you now the exact state of the payment so you can react accordingly. The possible status of a payment are INITIATED, PENDING, COMPLETED, CRASHED, ABORTED, EXPIRED, DECLINED. STOPPED, UNDERFUNDED, OVERFUNDED & FUNDED. Note that all statuses are note applicable for all payment methods, please see the table below.

Note: To ensure robust callbacks ping will make up to 20 attempts with exponential back off to make sure the callback is allays delivered.

StatusTypeDescription
INITIATEDnon-terminatedThe initial status of the callback. No callback will be sent for this status.
PENDINGnon-terminatedIf the payment is successfully initiated the status will transition to PENDING, which indicates that the payment is ongoing.
COMPLETEDterminatedThe payer has successfully paid the full amount of the payment.
CRASHEDterminatedThe payment crashed due to a provider error.
ABORTEDterminatedThe payer did not go through with the payment.
EXPIREDterminatedThe payment was not paid in time.
DECLINEDterminatedThe payment was declined by the provider. No callback will be sent for this status.
STOPPEDterminatedThe payment was manually stopped. This action is performed by the tenant to stop an PENDING payment. No callback will be sent for this status.
UNDERFUNDEDnon-terminatedIndicates that the payer paid less than the payment amount. This status is only relevant for ping/depositpayments.
OVERFUNDEDnon-terminatedIndicates that the payer paid more than the payment amount. This status is only relevant for ping/depositpayments.
FUNDEDnon-terminatedIndicates that the payer paid the expected payment amount. This status is only relevant for ping/depositpayments when the provider_method_parameter complete_when_funded is set to false.

Note: Once a payment is terminated, no more status-callbacks will be sent regarding that payment

If you would for example receive the status CRASHED you should indicate for the user that the payment did not go through. If the user still want's to go through with the purchase, an new payment needs to be initiated.

Authenticate the callback

Ping offers an optional callback-signature feature for added security. When enabled, you can verify that every callback truly originates from Ping and hasn’t been tampered with. See SigningKeys for more information

Note: This signature verification applies to all Ping callbacks—not just payment-status updates.


What’s Next

Once the payment is fulfilled, the next step is to CLOSE, SPLIT & SETTLE the PaymentOrder.