Judopay API client for PHP
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
cert
spec Merge branch 'UpdateDependencies-DS-1014' of github.com:Judopay/Judo-… Jan 2, 2019
src
tests Using secondary account only for the Check Card test Jan 3, 2019
vbox
.gitignore Removing lock file as it prevents Travis from building PHP version sp… Oct 1, 2018
.phpcs.xml
.travis.yml
LICENSE.txt Update LICENSE.txt Jan 6, 2016
README.md
code_check.sh
composer.json
generate_doc.sh
package-lock.json
phpunit.xml

README.md

Judopay PHP SDK Build Status

The JudoPay SDK provides you with ability to integrate card payments into your PHP project. Judo's SDK enables a faster, simpler and more secure payment experience within your app.

***Due to industry-wide security updates, versions below 2.0 of this SDK will no longer be supported after 1st Oct 2016. For more information regarding these updates, please read our blog here.***

Requirements

For the Judo PHP library in order to work correctly with your developer setup, please ensure the following requirements are met:

  • PHP 5.3.3 and above
  • PHP cURL extension
  • Composer

Getting started

1. Integration

Installation of the SDK is implemented via the Composer package manager. Add the judopay package to your composer.json file:

    "require": {
        "judopay/judopay-sdk": "~2.6"
    }

And then execute:

    $ composer install

Make sure you require the 'vendor/autoload.php' file, so that the Judopay SDK classes are available to your application. For more information on getting started with Composer, see Composer intro.

2. Setup

To start using the SDK, create a new Judopay object with your API credentials:

    $judopay = new \Judopay(
        array(
            'apiToken' => 'your-token',
            'apiSecret' => 'your-secret',
            'judoId' => 'your-judo-id'
        )
    );
3. Make a payment

To make a new payment with full card details:

    $payment = $judopay->getModel('Payment');
    $payment->setAttributeValues(
        array(
            'judoId' => 'your_judo_id',
            'yourConsumerReference' => '12345',
            'yourPaymentReference' => '12345',
            'amount' => 1.01,
            'currency' => 'GBP',
            'cardNumber' => '4976000000003436',
            'expiryDate' => '12/15',
            'cv2' => 452
        )
    );

Note: Please make sure that you are using a unique Consumer Reference for each different consumer, and a unique Payment Reference for each transaction.

You can check on the required fields and the format of each field in the Judopay REST API reference. To send the request to the API, call:

    $response = $payment->create();
4. Check the payment result

If the payment is successful, you'll receive a response array like this (see full response here):

    Array
    (
        [receiptId] => 520882
        [type] => Payment
        [createdAt] => 2014-08-18T16:28:39.6164+01:00
        [result] => Success
        ...
        [amount] => 10.00
        ...	
        [yourPaymentReference] => 12345
    )

Also important to handle different exceptions in your code. See more details in our error handling section.

    try {
        $response = $payment->create();
        if ($response['result'] === 'Success') {
            echo 'Payment succesful';
        } else {
            echo 'There were some problems while processing your payment';
        }
    } catch (\Judopay\Exception\ValidationError $e) {
        echo $e->getSummary();
    } catch (\Judopay\Exception\ApiException $e) {
        echo $e->getSummary();
    } catch (\Exception $e) {
        echo $e->getMessage();
    }

Next steps

The judo PHP SDK supports a range of customization options. For more information on using judo see our wiki documentation.

License

See the LICENSE file for license rights and limitations (MIT).