PHP code example of atdev / commweb

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

    

atdev / commweb example snippets


use ATDev\Commweb\PayRequest;
use ATDev\Commweb\AuthorizeRequest;
use ATDev\Commweb\CaptureRequest;
use ATDev\Commweb\VoidRequest;
use ATDev\Commweb\RefundRequest;
use ATDev\Commweb\Order;
use ATDev\Commweb\Transaction;
use ATDev\Commweb\SourceOfFundsCard;
use ATDev\Commweb\Card;

$result = (new PayRequest("MERCHANT_ID")) // Provided by gateway
    ->setApiPassword("API_PASSWORD") // Provided by gateway
    ->setOrder(new Order("SOME_ORDER_ID", 55.55, "AUD")) // Order id has to be unique, amount in money format, AUD is the only one supported now
    ->setTransaction(new Transaction("SOME_TRANSACTION_ID")) // Transaction id has to be unique
    ->setSourceOfFunds(new SourceOfFundsCard(new Card("CARD_NUMBER", "EXP_MONTH", "EXP_YEAR", "CVC"))) // Self explanatory, year is 2-digit
    ->send();

if ( ! empty($error = $result->getError()) ) {
    // Something went wrong, log it
    die($error);
}

// Successful, save order id, transaction id

$result = (new AuthorizeRequest("MERCHANT_ID")) // Provided by gateway
    ->setApiPassword("API_PASSWORD") // Provided by gateway
    ->setOrder(new Order("SOME_ORDER_ID", 55.55, "AUD")) // Order id has to be unique, amount in money format, AUD is the only one supported now
    ->setTransaction(new Transaction("SOME_TRANSACTION_ID")) // Transaction id has to be unique
    ->setSourceOfFunds(new SourceOfFundsCard(new Card("CARD_NUMBER", "EXP_MONTH", "EXP_YEAR", "CVC"))) // Self explanatory, year is 2-digit
    ->send();

if ( ! empty($error = $result->getError()) ) {
    // Something went wrong, log it
    die($error);
}

// Successful, save order id, transaction id

$result = (new VoidRequest("MERCHANT_ID")) // Provided by gateway
    ->setApiPassword("API_PASSWORD") // Provided by gateway
    ->setOrder(new Order("SOME_ORDER_ID")) // Original order id
    ->setTransaction(new Transaction("SOME_TRANSACTION_ID")) // New transaction id to be created, has to be unique
    ->setOldTransaction(new Transaction(("OLD_TRANSACTION_ID")) // Original transaction id
    ->send();

if ( ! empty($error = $result->getError()) ) {
    // Something went wrong, log it
    die($error);
}

// Successful, save order id, transaction id

$result = (new CaptureRequest("MERCHANT_ID")) // Provided by gateway
    ->setApiPassword("API_PASSWORD") // Provided by gateway
    ->setOrder(new Order("SOME_ORDER_ID")) // Original order id
    ->setTransaction(new Transaction("SOME_TRANSACTION_ID")) // New transaction id to be created, has to be unique
    ->setOldTransaction(new Transaction("OLD_TRANSACTION_ID", 55.55, "AUD")) // Original transaction id, amount to capture in money format, AUD is the only one supported now
    ->send();

if ( ! empty($error = $result->getError()) ) {
    // Something went wrong, log it
    die($error);
}

// Successful, save order id, transaction id

$result = (new RefundRequest("MERCHANT_ID")) // Provided by gateway
    ->setApiPassword("API_PASSWORD") // Provided by gateway
    ->setOrder(new Order("SOME_ORDER_ID")) // Original order id
    ->setTransaction(new Transaction("SOME_TRANSACTION_ID")) // New transaction id to be created, has to be unique
    ->setOldTransaction(new Transaction("OLD_TRANSACTION_ID", 55.55, "AUD")) // Original transaction id, amount to refund in money format, AUD is the only one supported now
    ->send();

if ( ! empty($error = $result->getError()) ) {
    // Something went wrong, log it
    die($error);
}

// Successful, save order id, transaction id