A PayJunction API client for php
The module can be installed using Composer:
php composer.phar require brandedcrate/payjunction:*
BrandedCrate\PayJunction fully supports PayJunction's REST API for transactions, customers and receipts. Support for other resources is on the way.
This library has no third-party dependencies.
Instantiate an instance of \BrandedCrate\PayJunction\Client which provides access to all the available resources.
use BrandedCrate\PayJunction;
$pj = new PayJunction\Client(array(
'username' => 'YOUR-USERNAME',
'password' => 'YOUR-PASSWORD',
'appkey' => 'YOUR-APP-KEY',
'endpoint' => 'test' // or 'live'
));
Any errors, including not found errors will be thrown as exceptions of type
BrandedCrate\PayJunction\Exception
. Generally, you should wrap each
PayJunction call in a try/catch block because you might have a bad request and
PayJunction might throw an error.
use BrandedCrate\PayJunction;
try {
$pj->customer()->read('doesntexist');
} catch (PayJunction\Exception $e) {
$e->getCode(); // 404
$e->getResponse()->errors; // array of errors
}
Consult the PayJunction API Documentation for information about all the available API resources and actions including what parameters can be set and example responses.
Create a transaction for a keyed credit card:
$response = $pj->transaction()->create(array(
'cardNumber' => '4444333322221111',
'cardExpMonth' => '01',
'cardExpYear' => '18',
'cardCvv' => '999',
'amountBase' => '10.00'
));
Create a transaction for a swiped credit card:
$response = $pj->transaction()->create(array(
'cardTrack' => '%B4444333322221111^First/Last^1712980100000?;4444333322221111=1712980100000?',
'amountBase' => '10.00'
));
Create a transaction for an ACH transfer:
$response = $pj->transaction()->create(array(
'achRoutingNumber' => '104000016',
'achAccountNumber' => '123456789',
'achAccountType' => 'CHECKING',
'achType' => 'PPD',
'amountBase' => '10.00',
));
Create a new transaction from a previous transaction:
$response = $pj->transaction()->create(array(
'transactionId' => '74600',
));
Void a transaction by id:
$response = $pj->transaction()->update('74600', array(
'status' => 'VOID'
));
Read a transaction by id:
$response = $pj->transaction()->read('74600');
Add signature to transaction:
$response = $pj->transaction()->addSignature('74600', array(
'signature' => '}SCRIPTEL A ST1501-PYJ 01.00.08 #_5,#<5\'#<5z#"5\'#"5=#"6t#"7m#<7/#>8,#:9\'#+a\'#|b\'$Mcz$Mdv$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J:e\'J|e[KOfrKRfwKUfzKWf,KXf-KWf-KVf,KSf\'KOfzJ:fyJYfxJRfxI+fyIYfzIQfzH+fzHZfxHVfvHSfsHQfqHPfoHPfmHPe[HQe/HRe\'HTewHVerHZenH>d=IMd-ISdzIYdxI?dxJNdxJSdzJWd-J"d=J>eoJ:etJ{ezJ|e/KNe\KOfqKPftKQfvKRfxKSfyKTfxKVfvKWftKWfrKXfq ]');
));
Read receipt data by transaction id:
$response = $pj->receipt()->read('123456');
Sent an email receipt:
$response = $pj->receipt()->email('123456', array(
'to' => 'stephen+automation@brandedcreate.com',
'replyTo' => 'foobar@whatever.com',
'requestSignature' => 'true'
));
Create a customer:
$pj->customer()->create(array(
'companyName' => 'ACME, inc.',
'email' => 'customer@acme.com',
'identifier' => 'your-custom-id',
'firstName' => 'Joe',
'jobTitle' => 'Wage Slave',
'lastName' => 'Schmoe',
'middleName' => 'Ignatius',
'phone' => '5555551212',
'phone2' => '1234567890',
'website' => 'acme.com'
));
Delete a customer:
$pj->customer()->delete('345678');
Read a customer:
$customer = $pj->customer()->read('345678');
$customer->customerId; // int(7902)
$customer->uri; // "https://api.payjunctionlabs.com/customers/7902"
Create a customer vault
$vault = $pj->customerVault()->create('345678', array(
'cardNumber' => '4242424242424242',
'cardExpMonth' => '2',
'cardExpYear' => '25'
));
$vault->vaultId; // int(44)
Read a vault
$vault = $pj->customerVault()->read('345678', '44');
Index all vaults for a customer
$vaults = $pj->customerVault()->index('345678');
Update a vault
$updatedVault = $pj->customerVault()->update('345678', '44', array(
'address' => '1600 Pennsylvania Ave NW',
'city' => 'Washington',
'state' => 'DC',
'zip' => 20500
));
Delete a vault
$result = $pj->customerVault()->delete('345678', '44'); // true
This package includes standalone unit tests and integration tests. Run them with PHPUnit or use the wrapper script to do it for you.
./bin/test
This package is released under the MIT License.