PHP code example of cimpleo / omnipay-authorizenetrecurring

1. Go to this page and download the library: Download cimpleo/omnipay-authorizenetrecurring 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/ */

    

cimpleo / omnipay-authorizenetrecurring example snippets




use Omnipay\Omnipay;
use Omnipay\AuthorizeNetRecurring;
use Omnipay\AuthorizeNetRecurring\Objects\Schedule;
use Omnipay\Common\CreditCard;

$gateway = Omnipay::create('AuthorizeNetRecurring_Recurring');

$gateway->setAuthName('API_LOGIN_ID');
$gateway->setTransactionKey('API_TRANSACTION_KEY');
$gateway->setTestMode(true);

$schedule = new Schedule([
    //For a unit of days, use an integer between 7 and 365, inclusive. For a unit of months, use an integer between 1 and 12, inclusive.
    'intervalLength' => '10',
    // use values 'days' or 'months'
    'intervalUnit' => 'days',
    // date in format 'YYYY-mm-dd'
    'startDate' => '2020-03-10',
    //To create an ongoing subscription without an end date, set totalOccurrences to "9999".
    'totalOccurrences' => '12',
    //If a trial period is specified, n using trialOccurrences
    'trialAmount' => '0.00',
    'currency' => 'USD',
    'schedule' => $schedule,
    'card' => $card
])->send();

var_dump($response->getData());
// Returns an array with the data of the created subscription, or an array with data about the error, in case of unsuccessful attempt to create a subscription

var_dump($response->isSuccessful());
// bool(true) or bool(false)

var_dump($response->getCode());
// string(6) "I00001"

var_dump($response->getMessage());
// "Successful." or "Error."



use Omnipay\Omnipay;
use Omnipay\AuthorizeNetRecurring;
use Omnipay\AuthorizeNetRecurring\Objects\Schedule;
use Omnipay\AuthorizeNetRecurring\Objects\Profile;

$gateway = Omnipay::create('AuthorizeNetRecurring_Recurring');

$gateway->setAuthName('API_LOGIN_ID');
$gateway->setTransactionKey('API_TRANSACTION_KEY');
$gateway->setTestMode(true);

$schedule = new Schedule([
// Variable schedule parameters in the same format as when creating a subscription.
]);

$profile = new Profile([
    // Payment gateway assigned ID associated with the customer profile.
    'customerProfileId' => '1505265565',
    // Payment gateway assigned ID associated with the customer payment profile.
    'customerPaymentProfileId' => '1504545622',
    //  Payment gateway-assigned ID associated with the customer shipping address.
    'customerAddressId' => '1234567890'
]);

$response = $gateway->createSubscription([
    // Variable parameters of subscriptionName, refId, amount, trialAmount or currency.
    'schedule' => $schedule,
    'profile' => $profile
])->send();

var_dump($response->getData());
// Returns an array with the data of the created subscription, or an array with data about the error, in case of unsuccessful attempt to create a subscription

var_dump($response->isSuccessful());
// bool(true) or bool(false)

var_dump($response->getCode());
// string(6) "I00001"

var_dump($response->getMessage());
// "Successful." or "Error."



use Omnipay\Omnipay;
use Omnipay\AuthorizeNetRecurring;
use Omnipay\AuthorizeNetRecurring\Objects\Schedule;
use Omnipay\Common\CreditCard;

$gateway = Omnipay::create('AuthorizeNetRecurring_Recurring');

$gateway->setAuthName('API_LOGIN_ID');
$gateway->setTransactionKey('API_TRANSACTION_KEY');
$gateway->setTestMode(true);

$schedule = new Schedule([
// Variable schedule parameters in the same format as when creating a subscription.
]);

$card = new CreditCard([
// Variable credit card parameters in the same format as when creating a subscription
]);

$response = $gateway->updateSubscription([
    // Required. The payment gateway-assigned identification number for the subscription.
    'subscriptionId' => '100748'
    // Variable parameters of subscriptionName, amount, trialAmount or  currency.
    'schedule' => $schedule,
    'card' => $card
])->send();

var_dump($response->getData());
// Returns an array with the data of the updated subscription, or an array with data about the error, in case of unsuccessful attempt to update a subscription

var_dump($response->isSuccessful());
// bool(true) or bool(false)

var_dump($response->getCode());
// string(6) "I00001"

var_dump($response->getMessage());
// "Successful." or "Error."



use Omnipay\Omnipay;
use Omnipay\AuthorizeNetRecurring;

$gateway = Omnipay::create('AuthorizeNetRecurring_Recurring');

$gateway->setAuthName('API_LOGIN_ID');
$gateway->setTransactionKey('API_TRANSACTION_KEY');
$gateway->setTestMode(true);

$response = $gateway->cancelSubscription([
    // Required. The payment gateway-assigned identification number for the subscription.
    'subscriptionId' => '100748',
    // If 



use Omnipay\Omnipay;
use Omnipay\AuthorizeNetRecurring;

$gateway = Omnipay::create('AuthorizeNetRecurring_Recurring');

$gateway->setAuthName('API_LOGIN_ID');
$gateway->setTransactionKey('API_TRANSACTION_KEY');
$gateway->setTestMode(true);

$response = $gateway->getSubscription([
    // Required. The payment gateway-assigned identification number for the subscription.
    'subscriptionId' => '100748',
    // If case of unsuccessful attempt to update a subscription

var_dump($response->isSuccessful());
// bool(true) or bool(false)

var_dump($response->getCode());
// string(6) "I00001"

var_dump($response->getMessage());
// "Successful." or "Error."



use Omnipay\Omnipay;
use Omnipay\AuthorizeNetRecurring;

$gateway = Omnipay::create('AuthorizeNetRecurring_Recurring');

$gateway->setAuthName('API_LOGIN_ID');
$gateway->setTransactionKey('API_TRANSACTION_KEY');
$gateway->setTestMode(true);

$response = $gateway->getSubscriptionStatus([
    // Required. The payment gateway-assigned identification number for the subscription.
    'subscriptionId' => '100748',
    // If 



use Omnipay\Omnipay;
use Omnipay\AuthorizeNetRecurring;
use Omnipay\AuthorizeNetRecurring\Objects\Search;

$gateway = Omnipay::create('AuthorizeNetRecurring_Recurring');

$gateway->setAuthName('API_LOGIN_ID');
$gateway->setTransactionKey('API_TRANSACTION_KEY');
$gateway->setTestMode(true);

$search = new Search([
    // Valid Values:
    // 'cardExpiringThisMonth', 'subscriptionActive', 'subscriptionInactive', or 'subscriptionExpiringThisMonth'
    'searchType' => 'subscriptionActive',
    // One of the following: 'id', 'name', 'status' 'createTimeStampUTC' 'lastName' 'firstName' 'accountNumber' (ordered by last four digits) 'amount' or 'pastOccurences'
    'orderBy' => 'id',
    // Sort the results in descending order. Valid values 'true' or 'false'
    'orderDescending' => 'true',
    // The number of transactions per page. You can request up to 1000 subscriptions per page of results.
    'limit' => '1000',
    // The number of the page to return results from. For example, if you use a limit of 100, setting offset to 1 will return the first 100 subscriptions, setting offset to 2 will return the second 100 subscriptions, and so forth.
    'offset' => '1'
]);

$response = $gateway->getSubscriptionList([
    // If 



use Omnipay\Omnipay;
use Omnipay\AuthorizeNetRecurring;

$gateway = Omnipay::create('AuthorizeNetRecurring_Recurring');

$gateway->setAuthName('API_LOGIN_ID');
$gateway->setTransactionKey('API_TRANSACTION_KEY');
$gateway->setTestMode(true);

$response = $gateway->getCustomer([
    // Payment gateway-assigned ID associated with the customer profile.
    'customerProfileId' => '1505272217',
    // When set to true, this optional field requests that the issuer number (IIN) be 



use Omnipay\Omnipay;
use Omnipay\AuthorizeNetRecurring;
use Omnipay\AuthorizeNetRecurring\Objects\BankAccount;

$gateway = Omnipay::create('AuthorizeNetRecurring_Recurring');

$gateway->setAuthName('API_LOGIN_ID');
$gateway->setTransactionKey('API_TRANSACTION_KEY');
$gateway->setTestMode(true);

$bankAccount = new BankAccount([
    // The type of bank account used for the eCheck.Net transaction. The value of accountType must be valid for the echeckType value submitted.
    // Valid values: 'checking', 'savings', or 'businessChecking'.
    'accountType' => 'checking',
    // The ABA routing number. Numeric string, up to 9 digits.
    'routingNumber' => '123456789',
    // The bank account number. Numeric string, up to 17 digits.
    'accountNumber' => '12345678901234567',
    // String, up to 22 characters. Name of the person who holds the bank account.
    'nameOnAccount' => 'Name',
    // The type of eCheck transaction. The value of accountType must be valid for the echeckType value submitted. For recurring payments, do not use TEL, ARC, or BOC.
    // Valid Values: 'PPD', 'WEB', or 'CCD'. 
    'echeckType' => 'PPD',
    // String, up to 50 characters. The name of the bank.
    'bankName' => 'Bank',
    'billingFirstName' => 'John',
    'billingLastName' => 'Doe'
    // Also here can be specified all other billing abd shipping parameters:
    //'billingCompany', 'billingAddress', 'billingCity', 'billingState', 'billingZip', 'billingCountry',
    //'shippingFirstName', 'shippingLastName', 'shippingCompany', 'shippingAddress', 'shippingCity', 'billingState', 'shippingZip', 'shippingCountry'.
]);

$response = $gateway->createSubscription([
    // ... Other subscription data ... 
    'bankAccount' => $bankAccount
])->send();



use Omnipay\Omnipay;
use Omnipay\AuthorizeNetRecurring;
use Omnipay\AuthorizeNetRecurring\Objects\OpaqueData;

$gateway = Omnipay::create('AuthorizeNetRecurring_Recurring');

$gateway->setAuthName('API_LOGIN_ID');
$gateway->setTransactionKey('API_TRANSACTION_KEY');
$gateway->setTestMode(true);

$opaqueData = new OpaqueData([
    // Specifies how the request should be processed. The value of dataDescriptor is based on the source of the value of dataValue. String, 128 characters.
    'dataDescriptor' => 'COMMON.ACCEPT.INAPP.PAYMENT',
    // Base64 encoded data that contains encrypted payment data. The payment gateway expects the encrypted payment data and meta data for the encryption keys. String, 8192 characters.
    'dataValue' => 'Base64 encoded data',
    'billingFirstName' => 'John',
    'billingLastName' => 'Doe'
    // Also here can be specified all other billing abd shipping parameters:
    //'billingCompany', 'billingAddress', 'billingCity', 'billingState', 'billingZip', 'billingCountry',
    //'shippingFirstName', 'shippingLastName', 'shippingCompany', 'shippingAddress', 'shippingCity', 'billingState', 'shippingZip', 'shippingCountry'.
]);

$response = $gateway->createSubscription([
    // ... Other subscription data ... 
    'opaqueData' => $opaqueData
])->send();



use Omnipay\Omnipay;
use Omnipay\AuthorizeNetRecurring;
use Omnipay\AuthorizeNetRecurring\Objects\Order;

$gateway = Omnipay::create('AuthorizeNetRecurring_Recurring');

$gateway->setAuthName('API_LOGIN_ID');
$gateway->setTransactionKey('API_TRANSACTION_KEY');
$gateway->setTestMode(true);

$order = new Order([
    // Merchant-assigned invoice number for the subscription. The invoice number will be associated with each payment in the subscription. String, up to 20 characters.
    'invoiceNumber' => '12345678901234567890',
    // Merchant-provided description of the subscription. The description will be associated with each payment in the subscription.
    'description' => 'Description'
]);

$response = $gateway->createSubscription([
    // ... Other subscription data ... 
    'order' => $order
])->send();



use Omnipay\Omnipay;
use Omnipay\AuthorizeNetRecurring;
use Omnipay\AuthorizeNetRecurring\Objects\Customer;

$gateway = Omnipay::create('AuthorizeNetRecurring_Recurring');

$gateway->setAuthName('API_LOGIN_ID');
$gateway->setTransactionKey('API_TRANSACTION_KEY');
$gateway->setTestMode(true);

$customer = new Customer([
    // Type of customer.
    // Valid values: 'individual' or 'business'.
    'type' => '',
    // The unique customer ID used to represent the customer associated with the transaction. If you use customer IDs, your solution should generate the customer ID and send it with your transaction requests. Authorize.Net does not generate customer IDs.
    // String, up to 20 characters. Use alphanumeric characters only, without spaces, dashes, or other symbols.
    'id' => '12345678901234567890',
    // The customer’s valid email address.
    'email' => '[email protected]',
    // Phone number associated with customer’s billing address. String, up to 25 characters.
    'phoneNumber' => '+1 (123) 555-12-34',
    // Fax number associated with customer’s billing address. String, up to 25 characters.
    'faxNumber' => '+1 (123) 555-12-34'
]);

$response = $gateway->createSubscription([
    // ... Other subscription data ... 
    'customer' => $customer
])->send();