itransact / itransact-php
This is an SDK for authenticating with iTransact's API
This package's canonical repository appears to be gone and the package has been frozen as a result.
Requires
- php: >=5.3.0
- lib/curl: 0.2
- phpunit/phpunit: >=6.0
This package is auto-updated.
Last update: 2023-12-20 05:12:04 UTC
README
As a quick helper for our PHP community to get up and running even faster in your favorite dependency manager, we have created this API / SDK wrapper specifically tailored for PHP.
More details at iTransact Developer API
Features
Usage
If there is a platform you would like to see in addition to composer for dependency management, let us know.
Composer Install
Run the following command at the root fo your project
composer require itransact/itransact-php
Packagist Link - iTransact SDK on Composer
Manual Install
Download the zip, or use git submodules to pull the SDK into your project.
Now just require iTransactSDK.php
on whichever class(es) you need to use it on.
Import Example
Here is an example implementation:
With Composer
# Wherever you are adding autoloader it should pick up the class. $loader = require_once __DIR__ . '/vendor/autoload.php'; ... # Now that its been automatically loaded, you can just call it inline or via use use iTransact\iTransactSDK\CardPayload; use iTransact\iTransactSDK\AddressPayload; use iTransact\iTransactSDK\TransactionPayload; use iTransact\iTransactSDK\iTTransaction; class Foo(){ private function Bar(){ // Put these somewhere safe, like in an environment variable $apiUsername = 'InsertApiUsername'; $apiKey = 'InsertApiKeyHere'; // Create new instances of the SDK, and if you would like you can also use the payload. $card = new CardPayload('Greg',5454545454545454,123,12,2020); $address = new AddressPayload('', '', '', '', '84025'); // Address is optional unless you are using a Loopback / Sandbox / Demo account $payload = new TransactionPayload(1234, $card, $address); // Amount, CardPayload, AddressPayload $payload->addMetadata('email', 'example@itransact.com'); // Optional $payload->setSendCustomerReceipt(true); // Optional - default: false $sdk = new iTTransaction(); // POST request to server $postResult = $sdk->postCardTransaction($transactionAmount,$apiUsername,$apiKey,$payload); } }
Without Composer
require_once('./iTransactSDK.php'); use iTransact\iTransactSDK\CardPayload; use iTransact\iTransactSDK\AddressPayload; use iTransact\iTransactSDK\TransactionPayload; use iTransact\iTransactSDK\iTTransaction; class Foo(){ private function Bar(){ // Put these somewhere safe, like in an environment variable $apiUsername = 'InsertApiUsername'; $apiKey = 'InsertApiKeyHere'; // Create new instances of the SDK, and if you would like you can also use the payload. $card = new CardPayload('Greg',5454545454545454,123,12,2020); $address = new AddressPayload('', '', '', '', '84025'); // Address is optional unless you are using a Loopback / Sandbox / Demo account $payload = new TransactionPayload(1234, $card, $address); // Amount, CardPayload, AddressPayload $payload->addMetadata('email', 'example@itransact.com'); // Optional $payload->setSendCustomerReceipt(true); // Optional - default: false $sdk = new iTTransaction(); // POST request to server $postResult = $sdk->postCardTransaction($transactionAmount,$apiUsername,$apiKey,$payload); } }
Example Response
Example successful $postResult
will return a 201 with the following fields / value types:
{ "id": "string", "amount": 0, "status": "string", "settled": "string", "instrument": "string", "metadata": [ { "key": "string", "value": "string" } ], "payment_source": { "name": "string", "default": "string", "type": "string", "expired": "string", "month": "string", "year": "string", "brand": "string", "last_four_digits": "string", "sec_code": "string" }, "credits": { "amount": 0, "state": "string" }, "credited_amount": "string" }
Example failed '$postResult' will return unathorized if $apiUsername or $apiKey don't exist on your iTransact account
{ "error": [ { "message": "Unauthorized" } ] }
Check out the files in src/iTransactJSON/Examples
for other ideas for implementation.
Testing
Unit tests on this project are run using PHPUnit. You can find each test in the src/iTransactJSON/Tests
folder
Legacy XML API
We have also included some examples for your convenience of the old legacy xml api which is now deprecated. Please use the JSON api moving forward.
You can find these files in src/iTransactXML/Examples