pawnpay / merchant_api
An API adapter for gateway.pawn-pay.com
Requires
- php: >=7.3.0
- ext-json: *
- guzzlehttp/guzzle: >=6.3
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.15
- fzaninotto/faker: ^1.4
- phpunit/phpunit: ^9.0
- vlucas/phpdotenv: ^3.5
This package is auto-updated.
Last update: 2025-04-20 00:31:44 UTC
README
About
An API adapter for gateway.pawn-pay.com
Table of Contents
- Installation
- Usage
- Initialize
- Checking For Success
- Payers
- Payment Methods
- Transactions
- Batches
- Webhooks
- Debugging
- Testing
- License
Installation
Require the pawnpay/merchant_api
package in your composer.json:
$ composer require pawnpay/merchant_api
Usage
For a full list of the API specs please see our API Documentation
Initialize
<?php require_once 'vendor/autoload.php'; use PawnPay\Merchant\MerchantClient; $client = new MerchantClient( 'merchant_id', 'merchant_key', 'merchant_secret', 'https://gateway.pawn-pay.com/api/v1/merchant/' );
Checking For Success
Validate the request completed successfully
<?php $response = $client->createPayer([ 'this is' => 'totally wrong', ]); $response->success === false;
Create Payer
$response = $client->createPayer([ 'name' => 'Johnny Test', 'email' => 'j.test@example.com', 'phone' => '+19544941234', 'address' => [ 'street' => '1234 Test St.', 'city' => 'Townsville', 'state' => 'GA', 'postal' => 30380, 'country' => 'USA', ], ]); $payer_id = $response->payer->id;
Update Payer
$response = $client->updatePayer($payer_id, [ 'name' => 'Johnny Test', 'email' => 'j.test@example.com', 'phone' => '+19544941234', 'address' => [ 'street' => '1234 Test St.', 'city' => 'Townsville', 'state' => 'GA', 'postal' => 30380, 'country' => 'USA', ], ]);
Delete Payer
$success = $client->deletePayer($payer_id);
Create Payment Method
$response = $client->createMethod($payer_id, [ 'name' => 'Test Visa', 'type' => 'credit', 'sub_type' => 'visa', 'account_name' => 'Test Cardholder', 'account' => '4242424242424242', 'exp' => '0124', 'cvv' => '123', 'address' => [ 'street' => '1234 Test St.', 'city' => 'Townsville', 'state' => 'GA', 'postal' => 30380, 'country' => 'USA', ], ]); $method_id = $response->method->id;
Update Payment Method
$response = $client->updateMethod($method_id, [ 'name' => 'Test Update', 'address' => [ 'street' => '43211 Test St.', ], ]);
Get Payment Methods
$response = $client->getMethods($payer_id); $methods = $response->methods;
Delete Payment Method
$success = $client->deleteMethod($method_id);
Authorize Transaction
$response = $client->authorize([ 'amount' => 1134, 'currency' => 'USD', 'payer' => [ 'name' => 'Johnny Test', 'email' => 'j.test@example.com', 'phone' => '+19544941234', 'address' => [ 'street' => '1234 Test St.', 'city' => 'Townsville', 'state' => 'GA', 'postal' => 30380, 'country' => 'USA', ], ], 'payment_method' => [ 'name' => 'Test Visa', 'type' => 'credit', 'sub_type' => 'visa', 'account_name' => 'Test Cardholder', 'account' => '4242424242424242', 'exp' => '0124', 'cvv' => '123', 'address' => [ 'street' => '1234 Test St.', 'city' => 'Townsville', 'state' => 'GA', 'postal' => 30380, 'country' => 'USA', ], ], 'invoice' => [ 'number' => 'I-0001', 'total' => 1134, 'description' => 'Invoice description', 'items' => [ [ 'name' => 'Invoice item', 'description' => 'Invoice item description', 'quantity' => 1, 'price' => 1134, ], ], 'discounts' => [], ], ]); $trans_id = $response->transaction->id;
Capture Transaction
$response = $client->capture($trans_id);
Process Transaction
$response = $client->process([ 'amount' => 1134, 'currency' => 'USD', 'payer' => [ 'name' => 'Johnny Test', 'email' => 'j.test@example.com', 'phone' => '+19544941234', 'address' => [ 'street' => '1234 Test St.', 'city' => 'Townsville', 'state' => 'GA', 'postal' => 30380, 'country' => 'USA', ], ], 'payment_method' => [ 'name' => 'Test Visa', 'type' => 'credit', 'sub_type' => 'visa', 'account_name' => 'Test Cardholder', 'account' => '4242424242424242', 'exp' => '0124', 'cvv' => '123', 'address' => [ 'street' => '1234 Test St.', 'city' => 'Townsville', 'state' => 'GA', 'postal' => 30380, 'country' => 'USA', ], ], 'invoice' => [ 'number' => 'I-0001', 'total' => 1134, 'description' => 'Invoice description', 'items' => [ [ 'name' => 'Invoice item', 'description' => 'Invoice item description', 'quantity' => 1, 'price' => 1134, ], ], 'discounts' => [], ], ]); $trans_id = $response->transaction->id;
Reverse Transaction
$response = $client->reverse($trans_id);
Get Transaction
$response = $client->getTransaction($trans_id);
Get Batches
$response = $client->listBatches(); $batch_id = $response->batches[0]->id;
Batch Transactions
$response = $client->getBatch($batch_id); $first_tran = $response->transactions[0];
Create Webhook
$response = $client->createWebhook( 'transaction.created', 'https://www.example.com/webhooks' ); $hook_id = $response->webhook->id;
Update Webhook
$response = $client->updateWebhook( $hook_id, 'transaction.created', 'https://www.example.com/webhooks' );
Get Webhook
$response = $client->getWebhook($hook_id);
Delete Webhook
$success = $client->deleteWebhook($hook_id);
List Webhooks
$response = $client->listWebhooks('transaction.created'); $webhooks = $response->webhooks;
Validate Webhook
$timestamp = $_SERVER['HTTP_TIMESTAMP']; $token = $_SERVER['HTTP_TOKEN']; $request_signature = $_SERVER['HTTP_SIGNATURE']; $valid = $client->validateWebhook($timestamp, $token, $request_signature);
Debugging
The raw HTTP Client response which implements \Psr\Http\Message\ResponseInterface
is accessible in each response.
This contains all the information about the response, status codes, headers, etc.
$response = $client->getPayer($payer_id); $raw_response = $response->getRawResponse(); $status = $raw_response->getStatusCode(); $body = $raw_response->getBody(); $headers = $raw_response->getHeaders();
The last request is stored as an array in the MerchantClient instance.
$last_request = $client->getLastRequest();
Testing
Install the dev-dependencies and put your testing credentials in a .env file according to .env.example
API_URL=https://gateway.pawn-pay.com/api/v1/merchant/ MERCHANT_ID=testing MERCHANT_KEY=testing1234 MERCHANT_SECRET=SECRET_BOIZ
Then run
$ composer test
License
This package is released under the MIT License. See the bundled LICENSE file for details.