Accept PostFinance Card with a server-side-only integration
Build your own payment form to add PostFinance Card payment to your checkout page.
Overview
PostFinance Card doesn’t require any input from the customer on the merchant website. The customer must be redirected to PostFinance to provide the required information to process the transaction. After that, the customer is redirected back to the merchants website to visualize result of the payment.
Before you begin
Before you begin- Check the basic integration requirements.
- Familiarize yourself with the general Server-side-only integration guide.
Step 1: Create a payment type resourceserver side
When creating the payment type PostFinance Card, you need to send a request to the Unzer API. The response will contain an id
, later referred to as typeId
. You need this typeId
to perform the transaction.
POST https://api.unzer.com/v1/types/post-finance-card
{}
$unzer = new Unzer('s-priv-xxxxxxxxxx');
$postFinanceCard = new PostFinanceCard();
$postFinanceCard = $unzer->createPaymentType($postFinanceCard);
Unzer unzer = new Unzer("s-priv-xxxxxxxxxx");
PostFinanceCard postFinanceCard = new PostFinanceCard();
unzer.createPaymentType(postFinanceCard );
The response looks similar to the following example:
{
"id": "s-pfc-9rxdhskuhnea",
"method": "post-finance-card",
"recurring": false,
"geoLocation": {
"clientIp": "127.0.0.143",
"countryCode": "CH"
},
}
For more details on Post Finance Card payment type creation, see API reference.
Make a payment [server side]Step 2: Make a paymentserver side
Make a charge transaction
Now, make a charge
transaction with the PostFinanceCard
typeId
that you created and the returnUrl
leading back to your shop after the payment is finished on the external page. With the charge
transaction an amount is requested but is not yet transferred. Initially the transaction will be pending and a payment
resource is created.
POST https://api.unzer.com/v1/payments/charges
{
"amount": "20",
"currency": "CHF",
"returnUrl": "https://www.my-shop-url.de/returnhandler",
"resources": {
"typeId": "s-pfc-3qujdbdjas5w"
}
}
$unzer = new UnzerSDK\Unzer('s-priv-xxxxxxxxxx');
$charge = new Charge(100.00, 'EUR', $returnUrl);
$typeId = 's-pfc-3qujdbdjas5w';
$transaction = $unzer->performCharge($charge, $typeId);
Unzer unzer = new Unzer("s-priv-xxxxxxxxxx");
Charge charge = unzer.charge(BigDecimal.ONE, Currency.getInstance("CHF"), "s-pfc-3qujdbdjas5w", new URL("https://www.my-shop-url.de/returnhandler"));
The response looks similar to the following example:
{
"id": "s-chg-1",
"isSuccess": false,
"isPending": true,
"isError": false,
"redirectUrl": "https://api.unzer.com/v1/redirect/post-finance-card/s-pfc-3qujdbdjas5w",
"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": "20.0000",
"currency": "CHF",
"returnUrl": "https://www.my-shop-url.de/returnhandler",
"date": "2021-05-10 00:51:03",
"resources": {
"paymentId": "s-pay-131937",
"traceId": "70ddf3152a798c554d9751a6d77812ae",
"typeId": "s-pfc-3qujdbdjas5w"
},
"paymentReference": "",
"processing": {
"uniqueId": "31HA07BC8157BD2BC04D483EFA914465",
"shortId": "4845.3426.1987",
"traceId": "70ddf3152a798c554d9751a6d77812ae"
}
}
For a full description of the charge
transaction, refer to the relevant server-side integration documentation page: Charge a payment (direct API calls), Charge a payment (PHP SDK), Charge a payment (Java SDK).
Forward the customer to external payment page
After you charge the PostFinanceCard
resource, implement the following flow:
- Forward the customer to the
redirectURL
returned in the response to yourcharge
request. - The customer is forwarded to the Post Finance Card payment page.
- After a successful payment or abort on the Post Finance Card page, the customer is redirected to the
returnURL
specified in the initialCharge
call.
Step 3: Check status of the paymentserver side
Step 3: Check status of the payment [server side]Once the customer is redirected to the returnUrl
, you can fetch the payment
details from the API, by using the resources.paymentId
from the charge
response above to handle the payment
according to its status. If the status of the payment
is completed
, the payment process has been finished successfully and can be considered as paid. Check all possible payment states here.
GET https://api.unzer.com/v1/payments/{payment_ID}
{
"id": "s-pay-131937",
"state": {
"id": 1,
"name": "completed"
},
"amount": {
"total": "20.0000",
"charged": "20.0000",
"canceled": "0.0000",
"remaining": "0.0000"
},
"currency": "CHF",
"orderId": "",
"invoiceId": "",
"resources": {
"customerId": "",
"paymentId": "s-pay-131937",
"basketId": "",
"metadataId": "",
"payPageId": "",
"traceId": "70ddf3152a798c554d9751a6d77812ae",
"typeId": "s-pfc-3qujdbdjas5w"
},
"transactions": [
{
"date": "2021-05-10 00:51:03",
"type": "charge",
"status": "success",
"url": "https://api.unzer.com/v1/payments/s-pay-131937/charges/s-chg-1",
"amount": "20.0000"
}
]
}
Step 4: Display the payment resultclient side
Step 4: Display the payment result [client side]Use the information from the Check status of the payment step to display the payment result to your customer.
This can be the success or error page of your shop. If something went wrong, you can use the client message from the API response and show it to the customer.
Manage paymentserver side
For more details on managing Post Finance Card payments, such as refunding them, see Manage Post Finance Card payments
Notifications
NotificationsWe recommend subscribing to the payment
event to receive notifications about any changes to the payment
resource. As soon as the event is triggered you should fetch the payment
and update the order status in your shop according to its status.
{
"event":"payment.pending",
"publicKey":"s-pub-xxxxxxxxxx",
"retrieveUrl":"https://api.unzer.com/v1/payments/s-pay-774",
"paymentId":"s-pay-774"
}
For more details on implementing webhooks
to receive notifications, see Notifications page.
Error handling
Error handlingAll requests to the API can result in an error that should be handled. Refer to the Error handling guide to learn more about Unzer API (and other) errors and handling them.
Test & go live
Test & go liveYou should always test your integration before going live. First perform test transactions using test data. Next, check against Integration checklist and Go-live checklist to make sure the integration is complete and you’re ready to go live.