PHP code example of academe / omnipay-authorizenetapi
1. Go to this page and download the library: Download academe/omnipay-authorizenetapi 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/ */
academe / omnipay-authorizenetapi example snippets
way = Omnipay\Omnipay::create('AuthorizeNetApi_Api');
$gateway->setAuthName('XXXXXxxxxxx');
$gateway->setTransactionKey('XXXXX99999xxxxx');
$gateway->setTestMode(true);
$creditCard = new Omnipay\Common\CreditCard([
// Swiped tracks can be provided instead, if the card is present.
'number' => '4000123412341234',
'expiryMonth' => '12',
'expiryYear' => '2020',
'cvv' => '123',
// Billing and shipping details can be added here.
]);
// Generate a unique merchant site transaction ID.
$transactionId = rand(100000000, 999999999);
$response = $gateway->authorize([
'amount' => '7.99',
'currency' => 'USD',
'transactionId' => $transactionId,
'card' => $creditCard,
// Additional optional attributes:
'customerId' => '123456',
'customerType' => \Academe\AuthorizeNet\Request\Model\Customer::CUSTOMER_TYPE_INDIVIDUAL,
'customerDriversLicense' => [
'number' => '123456',
'state' => 'NY',
'dateOfBirth' => '1967-01-01',
],
'customerTaxId' => 'TAX456',
])->send();
// Or use $gateway->purchase() to immediately capture.
var_dump($response->isSuccessful());
// bool(true)
var_dump($response->getCode());
// string(1) "1"
var_dump($response->getMessage());
// string(35) "This transaction has been approved."
var_dump($response->getTransactionReference());
// string(11) "60103474871"
$request = $gateway->authorize([
'amount' => $amount,
// etc.
'returnUrl' => 'return URL after the transaction is approved or rejected',
'cancelUrl' => 'URL to use if the user cancels the transaction',
]);
$response = $request->send();
$response->getRedirectMethod();
// Usually "POST"
$response->getRedirectUrl();
// The redirect URL or POST form action.
$response->getRedirectData()
// Array of name/value elements used to construct hidden fields
// in the POST form.
$request = $gateway->authorize([
...
// Hide the bank account form but show the credit card form.
'paymentOptionsShowCreditCard' => true,
'paymentOptionsShowBankAccount' => false,
// Change the "Pay" buton text.
'buttonOptionsText' => 'Pay now',
]);
// The main target: payment or customer
$notification->getEventTarget();
// The event subtarget. e.g. capture, fraud, void, subscription
$notification->getEventSubtarget();
// The event action. e.g. created, updated, deleted, held, approved, declined
$notification->getEventMethod();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.