PHP code example of gajus / strading

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

    

gajus / strading example snippets


/**
 * @param string $site_reference The Merchant's Site Reference.
 * @param string $username
 * @param string $password
 * @param string $interface_url
 */
$service = new \Gajus\Strading\Service('test_github53934', '[email protected]', '93gbjdMR');

/**
 * @param string $name Request template name, e.g. "card/order".
 * @return Gajus\Strading\Request
 */
$auth = $service->request('card/auth');

/**
 * Populate XML template using data from an array.
 * 
 * @param array $data ['node name' => 'text node value', 'another node[attribute]' => 'attribute value']
 * @param string $namespace XML namespace under which the node resides, e.g. /requestblock/request
 * @return null
 */
$auth->populate([
    'amount' => 100,
    'amount[currencycode]' => 'GBP',
    'email' => '[email protected]',
    'name' => [
        'first' => 'Foo',
        'last' => 'Bar'
    ],
    'payment' => [
        'pan' => '4111110000000211',
        'securitycode' => '123',
        'expirydate' => '10/2031'
    ],
    'payment[type]' => 'VISA'
],'/requestblock/request/billing');

/**
 * Request XML stripped of empty tags without attributes.
 *
 * @return string
 */
$auth->getXML();

$auth->populate([
    'merchant' => [
        'orderreference' => 'gajus-0000001'
    ],
    'customer' => [
        'name' => [
                'first' => 'Foo',
                'last' => 'Bar'
            ],
        'email' => '[email protected]'
    ]
], '/requestblock/request');

$service->setTemplateDirectory('/my/templates/live/here');

$service->getTemplateDirectory(); // Returns: /my/templates/live/here

/**
 * Issue the request.
 *
 * @return Gajus\Strading\Response
 */
$response = $auth->request();

/**
 * Transaction abstracts access to the most generic information about the response:
 *
 * - request_reference
 * - transaction_type
 * - transaction_reference
 * - timestamp
 * - parent_transaction_reference
 * - authcode
 * - amount
 * - paypal_token
 * 
 * Presence of this data will depend on the type of the response you receive, e.g.
 * only PayPal order request will () {
    return $this->redirect_url;
}

/**
 * @return string Response type.
 */
public function getType () {
    return $this->type;
}

/**
 * @return string Raw XML response.
 */
public function getXML () {
    return $this->xml->asXML();
}

/**
 * @return string
 */
public function getCode () {
    return $this->code;
}

/**
 * @return string
 */
public function getMessage () {
    return $this->message;
}

/**
 * This tag contains one or more child elements. If the error code is "30000" (Field Error)
 * then this field will contain the field (or fields) which caused the error.
 * 
 * @todo https://github.com/gajus/strading/issues/1
 * @return string
 */
public function getData () {
    return $this->data;
}