PHP

Introduction

This guide describes how to connect to our webservices, using our PHP library. It only covers the creation and submission of an order. Information and examples of other operations, like capture, cancel and refund, can be found in the package.

Include library using Composer

1) Include the AfterPay PHP Library by using Composer. If you are not familiar with using Composer, read this article with the basics about PHP Composer: http://culttt.com/2013/01/07/what-is-php-composer/. The AfterPay PHP Library can be found on packagist.org as “Payintegrator/Afterpay” (Details and releasenotes: link). The library can be included by the following command:

composer require payintegrator/afterpay

2) Next make sure you are using the Autoloader:

require 'vendor/autoload.php';

3) Create an empty object, for example using:

$Afterpay = new AfterpayAfterpay();

This object wil be used to store the information of your order and to send an order through SOAP to our webservices.

Creating order lines

With the function $Afterpay->create_order_line you can send the specification of the order lines.

You can use this for any type of orderline, i.e.:

  • products
  • shipping fee
  • service fee
  • discount

Note: prices are to be submitted in cents, including TAX.

Below is an example of an orderline for a product.

$sku = 'PRODUCT-001';
$name = 'Product name 1';
$qty = 3;
$price = 3000; // in cents, including TAX (for discounts, use a negative number)
$tax_category = 1; // 1 = high, 2 = low, 3, zero, 4 no tax
$Afterpay->create_order_line( $sku, $name, $qty, $price, $tax_category );

Set-up address and other information

In this step you set up the general order information and configure the Afterpay object with this information. This contains the billing and shipping information and other relevant information like the ordernumber, the currency and the remote ip address of the customer.

Below is an example of a B2C order.

// Set up the bill to address
$aporder['billtoaddress']['city'] = 'Heerenveen';
$aporder['billtoaddress']['housenumber'] = '90';
$aporder['billtoaddress']['housenumberaddition'] = '5';
$aporder['billtoaddress']['isocountrycode'] = 'NL';
$aporder['billtoaddress']['postalcode'] = '8441ER';
$aporder['billtoaddress']['referenceperson']['dob'] = '1980-12-12T00:00:00';
$aporder['billtoaddress']['referenceperson']['email'] = 'test@afterpay.nl';
$aporder['billtoaddress']['referenceperson']['gender'] = 'M';
$aporder['billtoaddress']['referenceperson']['initials'] = 'A';
$aporder['billtoaddress']['referenceperson']['isolanguage'] = 'NL';
$aporder['billtoaddress']['referenceperson']['lastname'] = 'de Tester';
$aporder['billtoaddress']['referenceperson']['phonenumber'] = '0513744112';
$aporder['billtoaddress']['streetname'] = 'KR Poststraat';
// Set up the ship to address
$aporder['shiptoaddress']['city'] = 'Heerenveen';
$aporder['shiptoaddress']['housenumber'] = '90';
$aporder['shiptoaddress']['housenumberaddition'] = '5';
$aporder['shiptoaddress']['isocountrycode'] = 'NL';
$aporder['shiptoaddress']['postalcode'] = '8441ER';
$aporder['shiptoaddress']['referenceperson']['dob'] = '1980-12-12T00:00:00';
$aporder['shiptoaddress']['referenceperson']['email'] = 'test@afterpay.nl';
$aporder['shiptoaddress']['referenceperson']['gender'] = 'M';
$aporder['shiptoaddress']['referenceperson']['initials'] = 'A';
$aporder['shiptoaddress']['referenceperson']['isolanguage'] = 'NL';
$aporder['shiptoaddress']['referenceperson']['lastname'] = 'de Tester';
$aporder['shiptoaddress']['referenceperson']['phonenumber'] = '0513744112';
$aporder['shiptoaddress']['streetname'] = 'KR Poststraat';
// Set up the additional information
$aporder['ordernumber'] = 'ORDER123';
$aporder['currency'] = 'EUR';
$aporder['ipaddress'] = $_SERVER['REMOTE_ADDR'];
// Create the order object for B2C or B2B
$Afterpay->set_order( $aporder, 'B2C' );

 

Authorize and send the order

After the order object is completed, the order can be sent to AfterPay. You need the AfterPay credentials (merchantid, portfolioid and password). You also need to determine, whether the order needs to be sent to the AfterPay test, or to the production environment.

$authorisation['merchantid'] = 'MERCHANTID';
$authorisation['portfolioid'] = 'PORTFOLIOID';
$authorisation['password'] = 'PASSWORD';
$modus = 'test'; // or 'live' for production
$Afterpay->do_request( $authorisation, $modus );

 

Processing the return object

The result of the order will be set in the object $Afterpay->order_result. You can process the order, using the information in the object. Below is an overview of possible resultIDs in the object.

ResultId Type Description Action
0 Acceptance – Payment accepted
– Order is registered
– Redirect to succespage
– Order can be processed and shipped
1 Exception – Technical error
– Order is not registered
– Show error message
– Order cannot be processed
2 Validation – One or more fields contain invalid data
– Order is not registered
– Show validation error(s)
– Provide option to correct data and submit again
– Order cannot be processed
3 Rejection – Payment rejected
– Order is registered
– Show rejection message
– Enable user to choose a different payment method
– Order cannot be processed

Example return objects

 

ResultId 0 – Accepted payment
Order-StatusCode-A-ResultId-0

ResultId 1 – Technical error
Order-ResultId-1

 

ResultId 2 – Validation error
Order-ResultId-2-MultipleMessages

ResultId 3 – Rejected payment
Order-StatusCode-W-ResultId-3

Processing messages and descriptions

Each returnobject contains an array with 1 or more

messages: these are for logging and debugging
descriptions: these are to be displayed in the webshop

foreach ($Afterpay->order_result->return->messages as $message)
{
    echo $message['message'];
}

Echo’s all the messages in the array.

foreach ($Afterpay->order_result->return->messages as $message)
{
    echo $message['description'];
}

Echo’s all the descriptions in the array.

Submit testorders

ResultId 0 – accepted payment

To check the submission of successful orders, place an testorder for each payment method with:

  • multiple products
  • discount (if possible)
  • shipping fee (if possible)
  • service fee (if allowed)
  • alternate delivery address

Below you will find the testdata that can be used.

Field Value
Gender M
First name Test
Last name Acceptatie
E-mail [your e-mailadres]
Telephone 0513744112
Zip code 8443ER
Housenumber 1
Streetname Teststraat
City Testplaats
Country Nederland
Date of birth January 1st 1990
Field Value
Gender M
First name Test
Last name Acceptatie
E-mail [your e-mailadres]
Telephone 0513744112
Zip code 8443ER
Housenumber 1
Streetname Teststraat
City Testplaats
Country Nederland
Date of birth January 1st 1990
Bankaccount NL93RABO0170100200
Field Value
First name T
Last name Acceptatie
E-mail [your e-mailadres]
Telephone 0513744112
Zip code 8443ER
Housenumber 1
Streetname Teststraat
City Testplaats
Country Nederland
Company Testbedrijf
COC number 56583052
VAT number NL001234567B01

ResultId 1 – technical error

To verify and process a technical error, place a regular order, but trigger a technical error, for example using:

  • 0 as merchantID
  • Incorrect password

ResultId 2 – validation error

To verify and process a validation error, place a regular order, but use invalid data, for example:

  • a telephone number consisting of 9 digits, i.e.: 051322334
  • a postal code using only letters, i.e.: ABCD
  • a name with number in it, i.e.: John Doe 123

ResultId 3 – rejected payment

To verify and process a rejected payment, place a regular order, but use the e-mailaddress: rejection@afterpay.nl.

AfterPay conditions

In order to pay with AfterPay, a user has to agree to the AfterPay terms & conditions. Please create a checkbox with the link to the conditions.

Method URL
B2C invoice NL https://www.afterpay.nl/nl/algemeen/betalen-met-afterpay/betalingsvoorwaarden
B2C invoice BE https://www.afterpay.be/be/footer/betalen-met-afterpay/betalingsvoorwaarden
B2B invoice NL https://www.afterpay.nl/nl/algemeen/zakelijke-partners/betalingsvoorwaarden-zakelijk
B2C direct debit NL https://www.afterpay.nl/nl/algemeen/betalen-met-afterpay/betalingsvoorwaarden

Name in checkout

Please use these names in your checkout:

Method Name in checkout
B2C invoice NL AfterPay – veilig achteraf betalen
B2C invoice BE AfterPay – veilig achteraf betalen
B2B invoice NL AfterPay – veilig achteraf betalen voor bedrijven
B2C direct debit NL AfterPay – veilig achteraf betalen (eenmalige machtiging)

Hide AfterPay payment methods

Total order amount

In order to prevent rejections based on the total order amount, please hide the AfterPay payment based on these conditions:

  • if total order amount < EUR 5
  • if total order amount > Max amount (please check the contract or AfterPay email)

The exception to this is the B2C invoice Belgium method. For AfterPay Belgium, the max total order amount is variable, so it should only be hidden if below the minimum amount.

Country

In order to prevent unsuccessful payments due to choosing unsupported countries, please only show the NL AfterPay payment methods if the chosen country is The Netherlands and show the BE payment methods only if the chosen country is Belgium.

 

AFTERPAY LOGO & BANNER

Below you will find the AfterPay logo and banner.

Looking for a different size? Simply click on the logo or banner and see all sizes available.

Please add the AfterPay logo on all places where payment method logo’s are shown
No logo’s of payment methods? Then you can skip this part.

The banner is a great way of showing AfterPay is now a payment option in your shop!

 

*All log’s have transparency, the white logo can be used in places where the background color is dark.

Logo AfterPay M M: 113 x 22
download PNG
M: 113 x 22
download PNG

 

*The banners are as is, no transparency, white is actually the color white.

Logo AfterPay M

AfterPay information

For each payment method, please place the explanation somewhere on your webshop. Usually, this is the page where you sum up the available payment methods.

Below you will find the text, that you can copy and paste into your webshop.

Replace the variables where needed:
– [webshop url] = the URL of your webshop

AfterPay – Achteraf betalen voor consumenten (NL/BE)

AfterPay voert voor [webshop url] het volledige achteraf betaalproces uit. Wanneer je je bestelling afrondt via AfterPay ontvang je van hen een digitaal betaaloverzicht en betaal je het orderbedrag aan AfterPay. Ter goedkeuring van je verzoek om achteraf te betalen voert AfterPay een gegevenscontrole uit. AfterPay hanteert een strikt privacybeleid zoals omschreven in het privacy statement. Mocht onverhoopt jouw verzoek tot betaling met AfterPay niet geautoriseerd worden, dan kun je jouw bestelling natuurlijk betalen met een andere betaalmethode. Wil je meer informatie over achteraf betalen met AfterPay? Ga dan naar de website van AfterPay.

AfterPay – Achteraf betalen voor bedrijven

Bij [webshop url] kun je achteraf betalen met AfterPay als zakelijke klant. Wanneer je je bestelling afrondt via AfterPay ontvang je van hen een digitaal betaaloverzicht en betaal je het orderbedrag aan AfterPay. Ter goedkeuring van je verzoek om achteraf te betalen voert AfterPay een gegevenscontrole uit. AfterPay hanteert een strikt privacybeleid zoals omschreven in het privacy statement. Mocht onverhoopt jouw verzoek tot betaling met AfterPay niet geautoriseerd worden, dan kun je jouw bestelling natuurlijk betalen met een andere betaalmethode. Wil je meer informatie over achteraf betalen met AfterPay? Ga dan naar de website van AfterPay.

Request final check

Go-live steps

Did you receive the live credentials? Then follow below steps to finish the implementation.

1. Use the live credentials and set the modus to live

$authorisation['merchantid'] = 'MERCHANTID';
$authorisation['portfolioid'] = 'PORTFOLIOID';
$authorisation['password'] = 'PASSWORD';
$modus = 'live'; // or 'live' for production
$Afterpay->do_request( $authorisation, $modus );

2. For each payment method, place an order using email addres rejection@afterpay.nl

3. Done? Reply to our last e-mail!
You can also call us on +31 (0) 20 – 7 230 230 (OPTION 2)

BPC

BPC | de Business Partner Console het Order Management systeem voor je AfterPay bestellingen.


De Business Partner Console is de plek waar je alle AfterPay orders terug kunt vinden die via je webshop bij ons zijn binnengekomen. Je hebt hiervoor een registratie e-mail ontvangen bij aanvang van de implementatie.

Je kunt hier ook je AfterPay bestellingen beheren en de uitbetaal-specificaties inzien. Op deze pagina kun je de meest gebruikte functies van de Business Partner Console terug vinden.

Controleer dus snel of je toegang werkt en of je overal bij kan!

Wil je meteen naar de login pagina? Klik dan op onderstaande knop.


Suggest Edit