PHP code example of pawnpay / merchant_api
1. Go to this page and download the library: Download pawnpay/merchant_api library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
pawnpay / merchant_api example snippets
PawnPay\Merchant\MerchantClient;
$client = new MerchantClient(
'merchant_id',
'merchant_key',
'merchant_secret',
'https://gateway.pawn-pay.com/api/v1/merchant/'
);
$response = $client->createPayer([
'this is' => 'totally wrong',
]);
$response->success === false;
$response = $client->createPayer([
'name' => 'Johnny Test',
'email' => '[email protected] ',
'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' => '[email protected] ',
'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' => '[email protected] ',
'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' => '[email protected] ',
'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);
$response = $client->getPayer($payer_id);
$raw_response = $response->getRawResponse();
$status = $raw_response->getStatusCode();
$body = $raw_response->getBody();
$headers = $raw_response->getHeaders();
$last_request = $client->getLastRequest();