PHP code example of craigpaul / moneris-api
1. Go to this page and download the library: Download craigpaul/moneris-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/ */
craigpaul / moneris-api example snippets
composer
use CraigPaul\Moneris\Moneris;
...
$id = 'store1';
$token = 'yesguy';
// optional
$params = [
'environment' => Moneris::ENV_TESTING, // default: Moneris::ENV_LIVE
'avs' => true, // default: false
'cvd' => true, // default: false
'cof' => true, // default: false
];
$gateway = (new Moneris($id, $token, $params))->connect();
use CraigPaul\Moneris\Moneris;
...
$id = 'store1';
$token = 'yesguy';
// optional
$params = [
'environment' => Moneris::ENV_TESTING, // default: Moneris::ENV_LIVE
'avs' => true, // default: false
'cvd' => true, // default: false
'cof' => true, // default: false
];
$gateway = Moneris::create($id, $token, $params);
$params = [
'order_id' => uniqid('1234-56789', true),
'amount' => '1.00',
'credit_card' => '4242424242424242',
'expiry_month' => '12',
'expiry_year' => '20',
];
$response = $gateway->purchase($params);
$params = [
'order_id' => uniqid('1234-56789', true),
'amount' => '1.00',
'credit_card' => '4242424242424242',
'expiry_month' => '12',
'expiry_year' => '20',
];
$response = $gateway->preauth($params);
$params = [
'order_id' => uniqid('1234-56789', true),
'amount' => '1.00',
'credit_card' => '4242424242424242',
'expiry_month' => '12',
'expiry_year' => '20',
];
$response = $gateway->preauth($params);
$response = $gateway->capture($response->transaction);
$params = [
'order_id' => uniqid('1234-56789', true),
'amount' => '1.00',
'credit_card' => '4242424242424242',
'expiry_month' => '12',
'expiry_year' => '20',
];
$response = $gateway->purchase($params);
$response = $gateway->void($response->transaction);
$params = [
'order_id' => uniqid('1234-56789', true),
'amount' => '1.00',
'credit_card' => '4242424242424242',
'expiry_month' => '12',
'expiry_year' => '20',
];
$response = $gateway->purchase($params);
$response = $gateway->refund($response->transaction);
$params = [
'order_id' => uniqid('1234-56789', true),
'amount' => '1.00',
'credit_card' => '4242424242424242',
'expiry_month' => '12',
'expiry_year' => '20',
];
$response = $gateway->verify($params);
$params = [
// `cvd` needs to be > uniqid('1234-56789', true),
'amount' => '1.00',
'credit_card' => $this->visa,
'expdate' => '2012',
];
$response = $gateway->verify($params); // could be purchase, preauth, etc.
$params = [
// `avs_*` keys need to be _street_name' => 'Fake Street',
'avs_zipcode' => 'X0X0X0',
'order_id' => uniqid('1234-56789', true),
'amount' => '1.00',
'credit_card' => $this->visa,
'expdate' => '2012',
];
$response = $gateway->verify($params); // could be purchase, preauth, etc.
$response = $gateway->verify($params);
if ($response->successful && !$response->failedAvs && !$response->failedCvd) {
$response = $gateway->purchase($params);
if ($response->successful) {
$receipt = $response->receipt();
} else {
$errors = $response->errors;
}
}
$response = $gateway->purchase($params);
if ($response->successful && ($response->failedAvs || $response->failedCvd)) {
$errors = $response->errors;
$response = $gateway->void($response->transaction);
} elseif (!$response->successful) {
$errors = $response->errors;
} else {
$receipt = $response->receipt();
}
$params = [
'order_id' => uniqid('1234-56789', true),
'amount' => '1.00',
'data_key' => $key,
'payment_indicator' => 'U',
'payment_information' => '2',
'issuer_id' => $issuer_id // this is optional
];
$response = $vault->purchase($params); // could be purchase, preauth, etc.
$vault = $gateway->cards();
use CraigPaul\Moneris\CreditCard;
...
$card = CreditCard::create('4242424242424242', '2012');
$response = $vault->add($card);
$card = CreditCard::create('4242424242424242', '2012');
$response = $vault->add($card);
$key = $response->receipt()->read('key');
$card->expiry = '2112';
$response = $vault->update($key, $card);
$card = CreditCard::create('4242424242424242', '2012');
$response = $vault->add($card);
$key = $response->receipt()->read('key');
$response = $vault->delete($key);
use CraigPaul\Moneris\Customer;
...
$params = [
'id' => uniqid('customer-', true),
'email' => '[email protected] ',
'phone' => '555-555-5555',
'note' => 'Customer note',
];
$customer = Customer::create($params);
$card = CreditCard::create('4242424242424242', '2012');
$card = $card->attach($customer);
$response = $vault->add($card);
use CraigPaul\Moneris\Customer;
...
$params = [
'id' => uniqid('customer-', true),
'email' => '[email protected] ',
'phone' => '555-555-5555',
'note' => 'Customer note',
];
$customer = Customer::create($params);
$card = CreditCard::create('4242424242424242', '2012');
$card = $card->attach($customer);
$response = $vault->add($card);
$key = $response->receipt()->read('key');
$card->customer->email = '[email protected] ';
$response = $vault->update($key, $card);
$params = [
'order_id' => uniqid('1234-56789', true),
'amount' => '1.00',
'credit_card' => '4242424242424242',
'expiry_month' => '12',
'expiry_year' => '20',
];
$response = $gateway->purchase($params);
$response = $vault->tokenize($response->transaction);
$card = CreditCard::create('4242424242424242', '2012');
$response = $vault->add($card);
$key = $response->receipt()->read('key');
$response = $vault->peek($key);
$receipt = $response->receipt();
$masked = $receipt->read('data')['masked_pan'];
$response = $vault->expiring();
$card = CreditCard::create('4242424242424242', '2012');
$response = $vault->add($card);
$key = $response->receipt()->read('key');
$params = [
'order_id' => uniqid('1234-56789', true),
'amount' => '1.00',
'data_key' => $key,
];
$response = $vault->purchase($params); //
$card = CreditCard::create('4242424242424242', '2012');
$response = $vault->add($card);
$key = $response->receipt()->read('key');
$params = [
'order_id' => uniqid('1234-56789', true),
'amount' => '1.00',
'data_key' => $key,
];
$response = $vault->preauth($params); //
$errors = $response->errors;
// The following example would be returned when you forget to set the `order_id` on your transaction.
$errors = [
[
'field' => 'order_id',
'code' => self::PARAMETER_NOT_SET, // 2
'title' => 'not_set'
],
];
$status = $response->status;
ERROR = -23;
INVALID_TRANSACTION_DATA = 0;
FAILED_ATTEMPT = -1;
CREATE_TRANSACTION_RECORD = -2;
GLOBAL_ERROR_RECEIPT = -3;
SYSTEM_UNAVAILABLE = -14;
CARD_EXPIRED = -15;
INVALID_CARD = -16;
INSUFFICIENT_FUNDS = -17;
PREAUTH_FULL = -18;
DUPLICATE_TRANSACTION = -19;
DECLINED = -20;
NOT_AUTHORIZED = -21;
INVALID_EXPIRY_DATE = -22;
CVD = -4;
CVD_NO_MATCH = -5;
CVD_NOT_PROCESSED = -6;
CVD_MISSING = -7;
CVD_NOT_SUPPORTED = -8;
AVS = -9;
AVS_POSTAL_CODE = -10;
AVS_ADDRESS = -11;
AVS_NO_MATCH = -12;
AVS_TIMEOUT = -13;
POST_FRAUD = -22;
$success = $response->successful
$response = $gateway->purchase($params);
$receipt = $response->receipt();
$amount = $receipt->read('amount');
amount - The amount of the transaction. (string)
authorization - The authorization code for the transaction. (string)
avs_result - The avs result code for the transaction. (string)
card - The card type used for the transaction. (string)
code - The response code for the transaction. (string)
complete - Whether the transaction had completed correctly or not. (boolean)
cvd_result - The cvd result code. (string)
data - The data related to the customer and card for the transaction. (array)
date - The date of the transaction. (string)
id - The Moneris id of the receipt. (string)
iso - The ISO code for the transaction. (string)
key - The data key used for vault transactions. (string)
message - Any relevant message provided for the transaction. (string)
reference - The reference number for the transaction. (string)
time - The time of the transaction. (string)
transaction - The Moneris id of the transaction. (string)
type - The transaction type. (string)