An API adapter for gateway.pawn-pay.com
- Installation
- Usage
- Initialize
- Checking For Success
- Payers
- Payment Methods
- Transactions
- Batches
- Webhooks
- Debugging
- Testing
- License
Require the pawnpay/merchant_api
package in your composer.json:
$ composer require pawnpay/merchant_api
For a full list of the API specs please see our API Documentation
<?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/'
);
Validate the request completed successfully
<?php
$response = $client->createPayer([
'this is' => 'totally wrong',
]);
$response->success === false;
$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;
$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',
],
]);
$success = $client->deletePayer($payer_id);
$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;
$response = $client->updateMethod($method_id, [
'name' => 'Test Update',
'address' => [
'street' => '43211 Test St.',
],
]);
$response = $client->getMethods($payer_id);
$methods = $response->methods;
$success = $client->deleteMethod($method_id);
$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;
$response = $client->capture($trans_id);
$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;
$response = $client->reverse($trans_id);
$response = $client->getTransaction($trans_id);
$response = $client->listBatches();
$batch_id = $response->batches[0]->id;
$response = $client->getBatch($batch_id);
$first_tran = $response->transactions[0];
$response = $client->createWebhook(
'transaction.created',
'https://www.example.com/webhooks'
);
$hook_id = $response->webhook->id;
$response = $client->updateWebhook(
$hook_id,
'transaction.created',
'https://www.example.com/webhooks'
);
$response = $client->getWebhook($hook_id);
$success = $client->deleteWebhook($hook_id);
$response = $client->listWebhooks('transaction.created');
$webhooks = $response->webhooks;
$timestamp = $_SERVER['HTTP_TIMESTAMP'];
$token = $_SERVER['HTTP_TOKEN'];
$request_signature = $_SERVER['HTTP_SIGNATURE'];
$valid = $client->validateWebhook($timestamp, $token, $request_signature);
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();
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
This package is released under the MIT License. See the bundled LICENSE file for details.