PHP code example of jinexus / worldpayus-restapi-sdk-php
1. Go to this page and download the library: Download jinexus/worldpayus-restapi-sdk-php 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/ */
jinexus / worldpayus-restapi-sdk-php example snippets
use JiNexus\WorldpayUs\WorldpayUs;
$secureNet = '1811021'; // This is just a sample value and must be replace with your own secure net value
$secureKey = 'vj8iZ0cHYTEX'; // This is just a sample value and must be replace with your own secure key
$config = [
'publicKey' => '13ab2cd4-5efg-67hi-8jka-910l1112m8', // This is just a sample value and must be replace with your own public key
'developerApplication' => [
'developerId' => '12345678', // This is just a sample value and must be replace with your own developer ID
'version' => '1.2',
],
];
// Create an Instance
$worldpayUs = new WorldpayUs($secureNet, $secureKey, $config);
// Set your origin in order to successfully use tokenization, this is most likely your base URI.
$worldpayUs->setOrigin($this->getBaseUrl());
// Set the gateway URL, I'll be using the demo API that WorldpayUS provided.
$worldpayUs->setGatewayUrl('https://gwapi.demo.securenet.com/api');
// Set your own HTTP Verb. Values are: 'POST', 'GET', 'PUT', 'PATCH' and 'DELETE' (Default: POST)
$worldpayUs->setVerb('POST');
$data = [
'amount' => 11.00,
'card' => [
'number' => '4444 3333 2222 1111',
'cvv' => '999',
'expirationDate' => '07/2021',
'address' => [
'line1' => '123 Main St.',
'city' => 'Austin',
'state' => 'TX',
'zip' => '78759',
'country' => 'US',
],
'firstName' => 'Jim',
'lastName' => 'Test',
],
'extendedInformation' => [
'typeOfGoods' => 'PHYSICAL',
],
];
$response = $worldpayUs->authorize($data);
$result = json_decode($response, true);
$data = [
'amount' => 11.00,
'transactionId' => 'REPLACE ME',
];
$response = $worldpayUs->capture($data);
$result = json_decode($response, true);
$data = [
'amount' => 11.00,
'card' => [
'number' => '4444 3333 2222 1111',
'cvv' => '999',
'expirationDate' => '07/2021',
'address' => [
'line1' => '123 Main St.',
'city' => 'Austin',
'state' => 'TX',
'zip' => '78759',
'country' => 'US',
],
],
'extendedInformation' => [
'typeOfGoods' => 'PHYSICAL',
],
];
$response = $worldpayUs->charge($data);
$result = json_decode($response, true);
$data = [
'amount' => 11.00,
'paymentVaultToken' => [
'customerId' => '2000007',
'paymentMethodID' => '1',
],
'vaultCredentials' => [
'secureNetId' => '7004183',
'secureNetKey' => 'xyzabcdefghi',
],
'extendedInformation' => [
'typeOfGoods' => 'PHYSICAL',
],
];
$response = $worldpayUs->charge($data);
$result = json_decode($response, true);
$data = [
'amount' => 11.00,
'paymentVaultToken' => [
'paymentMethodId' => '1211121',
'publicKey' => $worldpayUs->config['publicKey'],
],
'addToVault' => true,
'extendedInformation' => [
'typeOfGoods' => 'PHYSICAL',
],
];
$response = $worldpayUs->charge($data);
$result = json_decode($response, true);
$response = $worldpayUs->closeBatch();
$result = json_decode($response, true);
$batchId = 'REPLACE ME';
$response = $worldpayUs->retrieveCloseBatch($batchId);
$result = json_decode($response, true);
$response = $worldpayUs->retrieveCurrentBatch();
$result = json_decode($response, true);
$data = [
'transactionId' => 'REPLACE ME',
];
$response = $worldpayUs->refund($data);
$result = json_decode($response, true);
$data = [
'transactionId' => 'REPLACE ME',
];
$response = $worldpayUs->void($data);
$result = json_decode($response, true);
$data = [
'firstName' => 'Juan',
'lastName' => 'dela Cruz',
'phone' => '512-122-1211',
'emailAddress' => '[email protected] ',
'sendEmailReceipts' => true,
'notes' => 'This is test notes',
'address' => [
'line1' => '123 Main St.',
'city' => 'Austin',
'state' => 'TX',
'zip' => '78759',
'country' => 'US',
],
'company' => 'Test company',
'userDefinedFields' => [
[
'udfname' => 'udf1',
'udfvalue' => 'udf1_value',
],
[
'udfname' => 'udf2',
'udfvalue' => 'udf2_value',
],
[
'udfname' => 'udf3',
'udfvalue' => 'udf3_value',
],
],
];
$response = $worldpayUs->createCustomer($data);
$result = json_decode($response, true);
$customerId = 'REPLACE ME WITH EXISTING CUSTOMER ID';
$response = $worldpayUs->retrieveCustomer($customerId);
$result = json_decode($response, true);
$customerId = 'REPLACE ME WITH EXISTING CUSTOMER ID';
$data = [
'customerId' => $customerId,
'firstName' => 'Updated First Name',
'lastName' => 'Updated Last Name',
'phone' => '512-111-1111',
'emailAddress' => '[email protected] ',
'sendEmailReceipts' => true,
'notes' => 'This is test notes',
'address' => [
'line1' => '123 Main St.',
'city' => 'Austin',
'state' => 'TX',
'zip' => '78759',
'country' => 'US',
],
'company' => 'Test company update',
'userDefinedFields' => [
[
'udfname' => 'udf1',
'udfvalue' => 'udf1_value',
],
[
'udfname' => 'udf2',
'udfvalue' => 'udf2_value',
],
[
'udfname' => 'udf3',
'udfvalue' => 'udf3_value',
],
],
];
$response = $worldpayUs->updateCustomer($customerId, $data);
$result = json_decode($response, true);
$customerId = 'REPLACE ME WITH EXISTING CUSTOMER ID';
$data = [
'customerId' => $customerId,
'card' => [
'number' => '4444 3333 2222 1111',
'cvv' => '999',
'expirationDate' => '07/2021',
'address' => [
'line1' => '123 Main St.',
'city' => 'Austin',
'state' => 'TX',
'zip' => '78759',
'country' => 'US',
],
'firstName' => 'Jim',
'lastName' => 'Test',
],
'phone' => '512-250-7865',
'notes' => 'Create a vault account',
'accountDuplicateCheckIndicator' => 0,
'primary' => true,
'userDefinedFields' => [
[
'udfname' => 'udf1',
'udfvalue' => 'udf1_value',
],
[
'udfname' => 'udf2',
'udfvalue' => 'udf2_value',
],
[
'udfname' => 'udf3',
'udfvalue' => 'udf3_value',
],
],
];
$response = $worldpayUs->createPaymentAccount($customerId, $data);
$result = json_decode($response, true);
$customerId = 'REPLACE ME WITH EXISTING CUSTOMER ID';
$paymentMethodId = 'REPLACE ME WITH EXISTING PAYMENT METHOD ID';
$response = $worldpayUs->retrievePaymentAccount($customerId, $paymentMethodId);
$result = json_decode($response, true);
$customerId = 'REPLACE ME WITH EXISTING CUSTOMER ID';
$paymentMethodId = 'REPLACE ME WITH EXISTING PAYMENT METHOD ID';
$data = [
'customerId' => $customerId,
'paymentMethodId' => $paymentMethodId,
'card' => [
'number' => '4444 3333 2222 1111',
'cvv' => '999',
'expirationDate' => '07/2021',
'address' => [
'line1' => '123 Main St.',
'city' => 'Austin',
'state' => 'TX',
'zip' => '78759',
'country' => 'US',
],
'firstName' => 'Jim',
'lastName' => 'Updated',
],
'phone' => '512-250-7865',
'notes' => 'Update a vault account',
'accountDuplicateCheckIndicator' => 0,
'primary' => true,
'userDefinedFields' => [
[
'udfname' => 'udf1',
'udfvalue' => 'udf1_value',
],
[
'udfname' => 'udf2',
'udfvalue' => 'udf2_value',
],
[
'udfname' => 'udf3',
'udfvalue' => 'udf3_value',
],
[
'udfname' => 'udf4',
'udfvalue' => 'udf4_value',
],
],
];
$response = $worldpayUs->updatePaymentAccount($customerId, $paymentMethodId, $data);
$result = json_decode($response, true);
$customerId = 'REPLACE ME WITH EXISTING CUSTOMER ID';
$paymentMethodId = 'REPLACE ME WITH EXISTING PAYMENT METHOD ID';
$data = [
'customerId' => $customerId,
'paymentMethodId' => $paymentMethodId,
];
$response = $worldpayUs->deletePaymentAccount($customerId, $paymentMethodId, $data);
$result = json_decode($response, true);
$data = [
'firstName' => 'REPLACE ME',
'lastName' => 'REPLACE ME',
'phone' => 'REPLACE ME',
'emailAddress' => '[email protected] ',
'sendEmailReceipts' => true,
'notes' => 'This is test notes',
'address' => [
'line1' => '123 Main St.',
'city' => 'Austin',
'state' => 'TX',
'zip' => '78759',
'country' => 'US',
],
'company' => 'Test company',
'userDefinedFields' => [
[
'udfname' => 'udf1',
'udfvalue' => 'udf1_value',
],
[
'udfname' => 'udf2',
'udfvalue' => 'udf2_value',
],
[
'udfname' => 'udf3',
'udfvalue' => 'udf3_value',
],
],
'customerDuplicateCheckIndicator' => 1,
'card' => [
'number' => '4444 3333 2222 1111',
'cvv' => '999',
'expirationDate' => '07/2021',
'address' => [
'line1' => '123 Main St.',
'city' => 'Austin',
'state' => 'TX',
'zip' => '78759',
'country' => 'US',
],
'firstName' => 'REPLACE ME',
'lastName' => 'REPLACE ME',
],
'primary' => true,
'accountDuplicateCheckIndicator' => 1,
];
$response = $worldpayUs->createCustomerPaymentAccount($data);
$result = json_decode($response, true);
$customerId = 'REPLACE ME WITH EXISTING CUSTOMER ID';
$paymentMethodId = 'REPLACE ME WITH EXISTING PAYMENT METHOD ID';
$data = [
'customerId' => $customerId,
'paymentMethodId' => $paymentMethodId,
'firstName' => 'REPLACE ME',
'lastName' => 'REPLACE ME',
'phone' => 'REPLACE ME',
'emailAddress' => '[email protected] ',
'sendEmailReceipts' => true,
'notes' => 'This is updated test notes',
'company' => 'Test company',
'customerDuplicateCheckIndicator' => 1,
'card' => [
'number' => '4444 1111 1111 1111',
'cvv' => '999',
'expirationDate' => '08/2021',
'address' => [
'line1' => '123 Main St.',
'city' => 'Austin',
'state' => 'TX',
'zip' => '78749',
'country' => 'US',
],
'firstName' => 'REPLACE ME',
'lastName' => 'REPLACE ME',
],
'primary' => true,
'accountDuplicateCheckIndicator' => 1,
];
$response = $worldpayUs->updateCustomerPaymentAccount($data);
$result = json_decode($response, true);
bash
$ composer