NAV Navbar
Partpay logo 625x135

Introduction

Welcome to the PayFlex Developer documentation. Here you will find documentation for integrating PayFlex as a payment option onto your e-commerce site, as well as a number of helpful marketing widgets.

Authentication

E.g. To obtain an access token:

curl -X POST \
  https://payflex-live.eu.auth0.com/oauth/token \
  -H 'content-type: application/json' \
  -d '{
  "client_id":"[client id]",
  "client_secret":"[client secret]", 
  "audience":"https://auth-production.payflex.co.za",
  "grant_type":"client_credentials"
}'

Example response

{
    "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciO.....",
    "expires_in": 86400,    
    "token_type": "Bearer"
}

PayFlex uses OAuth2 Client Credentials Flow as the primary means for authorising requests when interacting with the Merchant API

This is a multiple step process, in that the client must obtain an access token via the OAuth token endpoint, and then use this bearer token to access the PayFlex API endpoints.

Authorisation Endpoints

  Sandbox Production
Token Endpoint https://payflex.eu.auth0.com/oauth/token https://payflex-live.eu.auth0.com/oauth/token
Audience https://auth.payflex.co.za https://auth-dev.payflex.co.za

Client Id & Secret

These will be issued to you from the PayFlex support team.

Merchant API

Base Urls

Sandbox

https://api.uat.payflex.co.za/

Production

https://api.payflex.co.za/

Payment Flow

TODO: Image

Each of these steps is described in more detail below:

  1. User selects PayFlex This is typically offered as a payment option for users when they are at the stage of checkout on the merchant site.
  2. Merchant Server POSTs to PayFlex API The merchant server creates an API call to the PayFlex ‘Create Order’ endpoint. This contains:
  3. Customer details (email, name, phone number)
  4. Order details (what the customer is purchasing from the merchant site)
  5. Billing and Shipping addresses
  6. Amount (plus optional information regarding discounts / shipping / tax)
  7. RedirectUrl - this is a merchant hosted URL, to return the customer to once they have completed the PayFlex process.
  8. PayFlex API returns a token and a Redirect URL The PayFlex API returns a unique token for the order and the URL to redirect the user to.
  9. Redirect User to PayFlex payment page Redirect the user to the URL returned in step 3 from the API
  10. (As above)
  11. User Completes Payment Steps at PayFlex User completes their payment information on payflex site. This will result in a user being able to pay via PayFlex or not.
  12. User is returned to the Merchant page when complete Once user has completed the PayFlex process, they are redirected to the Merchant page. When the user is returned back to the merchant page, the URL will have the following parameters appended to the URL:
  13. paymentStatus indicates the status of the payment. Possible values are:
    • success : Payment via PayFlex completed.
    • failure : Payment not taken - PayFlex service not offered, or payment declined.
    • cancelled : User cancelled out of PayFlex process and returned to merchant site.
  14. orderId used to uniquely identify the order
  15. (Optional) Merchant Server queries PayFlex API for order information This can be used to reconcile any orders that have started, but users have not returned to the merchant site, for whatever reason.
  16. As Above
  17. Merchant site reconciles payment On receipt of a payment status (successful or otherwise), it is expected the merchant server will reconcile the order status.

Testing

In the sandbox environment, we allow simulation of a number of scenarios with the following test cases.

AML / Credit Scenarios

Scenario Full Name DOB Address D/L D/L Version
Pass Credit / AML (anything) (any DOB over 18 yo) (any valid address) AB123456 111
Fail AML (anything) (any DOB over 18 yo) (any valid address) FA123456 111
Fail Credit (anything) (any DOB over 18 yo) (any valid address) AB000012 111

Payment Scenarios

To test a successful payment, you will need to use: 4111111111111111 as the card no, any (future dated expiry) and any CVV. If you want to test a failing payment, set the order amount to $87.04

Emails

We do not send out emails from the sandbox enviornment, but if you would like accounts activated (so you can login with user/pass each time) then please contact PayFlex tech support to enable this.

Phone Numbers / SMS

We do not send out SMS’s from the sandbox environment. In order to complete a signup process, enter and valid NZ phone number. When prompted to input the SMS verification code, use 999999.

Configuration

Get Configuration

Code sample

curl -X get https://api.payflex.co.za/configuration 
  -H 'Accept: application/json' 
  -H 'Authorization: Bearer [access_token]

Endpoint

GET https://api.payflex.co.za/configuration

Request Parameters

(none)

Response Values

Example Response

{
  "minimumAmount": 50,
  "maximumAmount": 950
}
Field Type Description
minimumAmount integer Minimum order amount
maximumAmount integer Maximum order amount

Response Codes

Code Reason
200 OK
401 Unauthorized

Order

Product Select

Code sample

curl -X post https://api.payflex.co.za/order/productSelect
  -H 'content-type: application/json' 
  -H 'authorization: Bearer [access_token]'
  -d '{
  "amount": 105.00,
  "consumer": {
    "phoneNumber": "64274123456",
    "givenNames": "James",
    "surname": "Smith",
    "email": "abc123.test@payflex.co.za"
  },
  "billing": {
    "addressLine1": "23 Duncan Tce",
    "addressLine2": "",
    "suburb": "Kilbirnie",
    "city": "Wellilngton",
    "postcode": "1000",
    "state": ""
  },
  "shipping": {
    "addressLine1": "23 Duncan Tce",
    "addressLine2": "",
    "suburb": "Kilbirnie",
    "city": "Wellilngton",
    "postcode": "1000",
    "state": ""
  },
  "description": "",
  "items": [
    {
      "description": "test",
      "name": "test",
      "sku": "test",
      "quantity": 1,
      "price": 100.00
    }
  ],
  "merchant": {
    "redirectConfirmUrl": "http://merchantsite.com/confirm",
    "redirectCancelUrl": "http://merchantsite.com/cancel",
    "statusCallbackUrl": "http://merchantsite.com/callback"
  },
  "merchantReference": "test",
  "taxAmount": 0,
  "shippingAmount": 5
}'

Endpoint

POST https://api.payflex.co.za/order/productSelect

Request Parameters

Field Type Description
amount number Amount for order to be charged to consumer.
consumer
    phoneNumber string optional
    givenNames string optional
    surname string optional
    email string optional
billing
    addressLine1 string optional
    addressLine2 string optional
    suburb string optional
    city string optional
    postcode string optional
    state string optional
shipping
    addressLine1 string optional
    addressLine2 string optional
    suburb string optional
    city string optional
    postcode string optional
    state string optional
description string optional A description of the order
items array (below) optional Optional array of order items
    description string optional
    name string optional
    sku string optional
    quantity integer optional
    price number optional
merchant
    redirectConfirmUrl string required
    redirectCancelUrl string required
    statusCallbackUrl string optional
merchantReference string required The merchant’s id/reference that this order corresponds to
taxAmount number optional The included tax amount after applying all discounts. ,
shippingAmount number optional The shipping amount.

Response

Example Response

{
    "token": "00fbfe84-600f-44e6-9894-953ccd42a2d1",
    "expiryDateTime": "2017-08-02T03:35:32.9915516Z",
    "redirectUrl": "https://checkout.payflex.co.za/checkout?token=00fbfe84...",
    "orderId": "2f549b62-5e66-4f2e-8c7c-f5497fa17142",
    "orderItemCacheKey": "OrderItem-FX3M"
}
Field Type Description
token string The order token, used to poll order status from PayFlex GET /order operation
expiryDateTime dateTime The time (utc) the token expires
redirectUrl string The URL to redirect the user to, in order to complete the PayFlex payment process
orderId Id to identify order
orderItemCacheKey Key to indentify temporary storage of order

Response Codes

Code Reason
200 OK
400 The request is malformed
401 Unauthorised

Product Select Order

Code sample

curl -X post https://api.payflex.co.za/order/productSelectOrder
  -H 'content-type: application/json' 
  -H 'authorization: Bearer [access_token]'
  -d '{
  { 
    "orderItemCacheKey": "OrderItem-A7EU89",
    "productType": "PayNow",
    "isNewCustomer": true    
}
}'

Endpoint

POST https://api.payflex.co.za/order/productSelectOrder

Request Parameters

Field Type Description
orderItemCacheKey string required Unique Order key to identify an order,
productType string required Type defined for payment option,
isNewCustomer bool required To identify customer is new or existing.

Response

Example Response

{
    "token": "6af12d91-1d73-48a8-a5fd-16b7c1f7e7b3",
    "expiryDateTime": "2019-05-17T10:03:43.9852741Z",
    "redirectUrl": "/checkout?token=6af12d91-1d73-48a8-a5fd-16b7c1f7e7b3&...",
    "orderId": "2f549b62-5e66-4f2e-8c7c-f5497fa17142",
    "orderItemCacheKey": null
}
Field Type Description
token string The order token, used to poll order status from PayFlex GET /order operation
expiryDateTime dateTime The time (utc) the token expires
redirectUrl string The URL to redirect the user to, in order to complete the PayFlex payment process
orderId Id to identify order

Response Codes

Code Reason
200 OK
400 The request is malformed
401 Unauthorised

Get Order

Request Sample

curl -X get https://api.payflex.co.za/order?token=string \
  -H 'Accept: application/json'
  -H 'Authorization: Bearer [access_token]'

Endpoint

GET https://api.payflex.co.za/order

Request Parameters

Field Type Description
token string (required) order token when creating the order during the Create Order step

Response

Example Response

{
    "orderId": "8eb068f..",
    "orderStatus": "Created",
    "amount": 105,
    "consumer": null,
    "billing": {
        "addressLine1": "23 Duncan Tce",
        "addressLine2": "",
        "suburb": "Kilbirnie",
        "city": "",
        "postcode": "1000",
        "state": null
    },
    "shipping": {
        "addressLine1": "23 Duncan Tce",
        "addressLine2": "",
        "suburb": "Kilbirnie",
        "city": "",
        "postcode": "1000",
        "state": null
    },
    "description": null,
    "items": [
        {
            "description": null,
            "name": "test",
            "sku": "test",
            "quantity": 1,
            "price": 100
        }
    ],
    "merchant": {
        "redirectConfirmUrl": null,
        "redirectCancelUrl": null,
        "statusCallbackUrl": null
    },
    "merchantReference": "test",
    "taxAmount": 10,
    "shippingAmount": 5,
    "token": "1eea52..."
}
Field Type Description
amount number Amount for order to be charged to consumer.
orderId string A unique reference for the order. This value will need to be persisted onto the client side, for the purposes of refunds
orderStatus string A status representing the status of an order on PayFlex.
Created: The order has been created on PayFlex, but not yet completed.
Approved: Payment has been successfuly taken/approved on PayFlex.
Declined: The the payment process on PayFlex was not successful
Abandoned: User abandoned PayFlex process before first payment is taken. Orders will tranisition to this state after a maximum of one hour.
consumer
    phoneNumber string optional
    givenNames string optional
    surname string optional
    email string optional
billing
    addressLine1 string optional
    addressLine2 string optional
    suburb string optional
    city string optional
    postcode string optional
    state string optional
shipping
    addressLine1 string optional
    addressLine2 string optional
    suburb string optional
    city string optional
    postcode string optional
    state string optional
description string optional A description of the order
items array (below) optional Optional array of order items
    description string optional
    name string optional
    sku string optional
    quantity integer optional
    price number optional
merchant
    redirectConfirmUrl string required
    redirectCancelUrl string required
merchantReference string required The merchant’s id/reference that this order corresponds to
taxAmount number optional The included tax amount after applying all discounts. ,
shippingAmount number optional The shipping amount.

Response Codes

Code Reason
200 OK
400 The request is malformed
401 Unauthorised
404 Order is not found

Refund

Example Request

curl -X post https://api.payflex.co.za/order/{orderId}/refund \
  -H 'Content-Type: application/json'
  -H 'authorization: Bearer [access_token]'
  -d '{
    "requestId": "c6f32647-03b1-4206-818f-c2e2fe8ae7f8",
    "amount": 1,
    "merchantRefundReference": "c6f32647-03b1-4206-818f-c2e2fe8ae7f8"
    }'

The resource is idempotent if a unique requestId is provided.

Endpoint

POST https://api.payflex.co.za/order/{orderId}/refund

orderId is the orderId returned from the Get Order operation

Request Parameters

Field Type Description
requestId string optional A client created unique request ID required for safe retries. It is recommended that the client generate a GUID as this ID must be globally unique to the merchant
amount number required The refund amount. The refund amount can not exceed the associated order
merchantRefundReference string optional Merchant refund reference.

Response Body

N/A

Response Codes

Code Reason
200 OK
400 The request is malformed
401 Unauthorised
404 Order Not found
422 A 422 occurs when the request was well formed, but the system is unable to process the request. Scenarios:
The sum of all refunds, including the new refund, exceed the (original) order amount. OR
The refund with merchantRefundReference has already been applied. OR
The refund request is otherwise invalid.
e.g. merchantRefundReference is required OR the refund amount is invalid OR the order was never completed and is not eligible for a refund

Update Merchant Reference

Example Request

curl -X PUT 
  https://api.payflex.co.za/order/{orderId}/merchantReference
  -H 'authorization: Bearer [access_token]' 
  -H 'content-type: application/json' 
  -d '{
        "merchantReference": "03942300934"
    }'

This endpoint allows an order have it’s merchantReference changed after the order has been accepted and payment taken via PayFlex.

Endpoint

PUT https://api.payflex.co.za/order/{orderId}/merchantReference

orderId is the orderId returned from the Get Order operation

Request Parameters

Field Type Description
merchantReference New merchant reference for the order

Response Body

N/A

Response Codes

Code Reason
200 OK
401 Unauthorised
404 Order Not found

Lightbox Checkout

The lightbox checkout allows a more seamless experience at the checkout stage. Rather than being redirected to PayFlex, it allows the PayFlex checkout process to be loaded in a lightbox within the merchant site.

Mobile Devices

NB: Mobile devices are not supported for this experience, given the limited screen size, but the lightbox will detect the device used, and will redirect users who are on a mobile device.

Script

Example <script> head tag

    <head>
        <script src="https://checkout.payflex.co.za/assets/sandbox/payflex-sandbox-v1.js"></script>
    </head>

Example dynamically loading script:

    function appendSandboxScript() {
        var el = document.createElement("script");
        el.setAttribute("src", "https://checkout.payflex.co.za/assets/sandbox/payflex-sandbox-v1.js");
        document.getElementsByTagName("head")[0].appendChild(el);
    }

There are 2 options to load the script onto the page, either by adding a <script> element to their checkout page <head>, OR dynamically add the script element when the CHECKOUT button has been clicked:

Flow

Example PayFlex intitialisation

    // CHECKOUT button clicked.
    // Initiate the payflex checkout.
    PayFlex.checkout({
        orderToken: token, // <--- token is the returned when creating an order.
        success: function () {
            // TODO: Handle a successful checkout.
            alert("Success");
        },
        cancel: function () {
            // TODO: Handle a cancelled checkout.
            alert("Cancelled");
        }
    });

Merchant should POST to https://checkout.payflex.co.za/order as stipulated in the POST /order endpoint, to create an order. The response will include the token to be used with the checkout process.

When the customer clicks the CHECKOUT button activate the PayFlex checkout with the PayFlex javascript object:

Widgets

PayFlex offers merchants a number of helpful & informative widgets, which display more information about the product to site customers. The widgets are really easy to load onto the relevant pages, and should be able to completed by most merchant site admins.

If you are having any issues implementing these on your site, please contact support@payflex.co.za

Simple Usage - Caluclator / More Info

Example script tag

<script async src="https://widgets.payflex.co.za/your-merchant-name/payflex-widget-0.1.0.js?type=calculator&min=50&max=400&amount=300" type="application/javascript"></script>

Simply insert a <script> tag, as defined below, onto the part of the page that is the right place for this to be displayed.

Base Url : https://widgets.payflex.co.za/your-merchant-name/partpay-widget-0.1.0.js?type=calculator

Parameters

Name Description
min Your minimum PayFlex amount
max Your maximum PayFlex amount
amount The order or cart amount

Demo

(*item / cart worth $300)

Shopify

When using this widget in Shopify, you can pass the following values for the amount parameters.

Parameters

Shopify Page Value
Cart {{ cart.total_price | divided_by: 100.0 }}
Product {{ current_variant.price | divided_by: 100.0 }}

i.e. <script async src="https://widgets.payflex.co.za/partpay-widget-0.1.0.js?type=calculator&min=50&max=400&amount={{ current_variant.price | divided_by: 100.0 }}" type="application/javascript"></script>

WooCommerce

When using this widget on WooCommerce, you can pass the following values for the amount parameters.

Parameters

WooCommerce Page Value
Cart WC()->cart->cart_contents_total;
Product WC()->product-> get_price();

i.e (product page). <script async src="https://widgets.payflex.co.za/partpay-widget-0.1.0.js?type=calculator&min=50&max=400&amount=<?php echo $product->get_price(); ?>" type="application/javascript"></script>

Errors

Error codes are returned in the following format:

Basic Errors

Basic Error Response

{
  "message": "The request is invalid",
  "isValid": false,
  "errors": []
}

The most basic error has a message and an indication that the request was invalid.

Errors with Error Codes

Error Response with Error Code

400 Bad Request

PayFlex-Error: AboveMaximumPreApprovalAmount

{
  "errorCode": "AboveMaximumPreApprovalAmount",
  "message": "The request is invalid",
  "isValid": false,
  "errors": []
}

Some errors can include an error code. If an error code is present, it will be provided in the body of the response as well as a custom PayFlex-Error header.

The following is an error from POST /pos/order where the customer approval code entered has been approved for an amount that is less than the requested order amount.

Other validation errors.

Validation Error Response

400 Bad Request
{
  "message": "'Amount' must be greater than '0'.",
  "isValid": false,
  "errors": [
    {
      "propertyName": "createOrderModel.amount",
      "errorMessages": [
        "'Amount' must be greater than '0'."
      ]
    }
  ]
}

A generic validation error can be a 400 Bad Request or a 422 Unprocessable Entity

The following is an error from POST /pos/order where the order amount was incorrect.

Please note that if there are multiple validation errors, the message property is populated with just the first message.