Table Of Contents

1.8. Testing

In sandbox environment, you can force the response given to payment attempts.

1.8.1. General guidelines

Our sandbox has its own antifraud checks, which means that if you want to try several payments, or do some load/concurrency testing, we recommend you to:

  • Use a random email address every time. To do so, the easiest is to use address tags. The most common way to do this is to append a ‘+’ to the local part of the email, followed by anything (like a timestamp), e.g. yourname+1395846197@yourmail.com.
  • Generate a random card number every time. (if what you’re testing are creditcard payments)
  • If you are using the server-2-server flow, generate a random IP for each request

Sample PHP code to generate random IPs

<?php

public function getRandomIp($publicOnly = true)
{
    // See http://en.wikipedia.org/wiki/Reserved_IP_addresses
    $reserved = array(0, 100, 127, 169, 198, 203, 224, 225, 226, 227, 228, 229, 230, 231,
                        232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244,
                        245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255);
    $skip = array_merge($reserved, $publicOnly?array(10, 172, 192):array());
    $ip = array();
    do {
        $ip[0] = rand(1, 255);
    } while (in_array($ip[0], $skip));
    $ip[1] = rand(0, 255);
    $ip[2] = rand(0, 255);
    $ip[3] = rand(0, 255);
    return implode('.', $ip);
}

1.8.2. Creditcard payments

  • Card Number: Any 16 digits card number starting with ‘4’ (VISA) or ‘5’ (Mastercard) that passes the LUHN test

  • Security Code: The validation follows the scheme of the card used, so any 3 digits for VISA/MC, or 4 digits for Amex

  • Expiration Date:
    • SUCCESS payment, without 3DS redirection: 01/2019
    • SUCCESS payment, with 3DS redirection: 01/2028 (This should be tested when implementing the server-2-server flow)
    • FAILED payment, without 3DS redirection: 02/2019
    • FAILED payment, with 3DS redirection: 02/2028 (This should be tested when implementing the server-2-server flow)
    • ERROR mandate: 12/2019

Sample PHP code to generate fake card numbers

<?php

function isLuhnNum($num, $length=null) {
    if (empty($length)) {
        $length = strlen($num);
    }
    $tot = 0;
    for($i = $length - 1; $i >= 0; $i--) {
        $digit = substr($num, $i, 1);
        if ((($length - $i) % 2) == 0) {
            $digit = $digit*2;
            if ($digit > 9) {
                $digit = $digit-9;
            }
        }
        $tot += $digit;
    }
    return (($tot % 10) === 0);
}


function getCardNumber () {
    $cardNumber = str_pad('4'.rand('10', '99').date('U'), 15, '0', STR_PAD_RIGHT);
    for ($i=0; $i<10; $i++) {
        if (isLuhnNum($cardNumber.$i)) {
            return $cardNumber.$i;
        }
    }
    return null;
}

print getCardNumber() . "\n";

1.8.3. iDEAL payments

iDeal can be tested by providing different payment amounts giving a different result per amount value. Also note that iDEAL is not a recurring payment method, meaning that you will not be able to take further payments without having the customer inserting his bank details.

  • Payment amount:
    • SUCCESS payment with amount - 1.00
    • CANCELLED payment with amount - 2.00
    • FAILED payment with amount - 3.00 (expired failure category)
    • OPEN payment with amount - 4.00
    • FAILED payment with amount - 5.00