PHPackages                             gajus/strading - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. gajus/strading

ActiveLibrary[API Development](/categories/api)

gajus/strading
==============

Secure Trading Web Services API abstraction.

0.9.1(11y ago)012.3k↓71.6%4[1 issues](https://github.com/gajus/strading/issues)[1 PRs](https://github.com/gajus/strading/pulls)BSD-3-ClausePHPPHP &gt;=5.3

Since Apr 25Pushed 9y ago1 watchersCompare

[ Source](https://github.com/gajus/strading)[ Packagist](https://packagist.org/packages/gajus/strading)[ Docs](https://github.com/gajus/strading)[ RSS](/packages/gajus-strading/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (2)Versions (3)Used By (0)

Strading
========

[](#strading)

[![Build Status](https://camo.githubusercontent.com/ddc09ce204d8738d4f51c70e43c348f8779684272d6d34a2c8664a457f6c10e6/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f67616a75732f7374726164696e672f6d61737465722e737667)](https://travis-ci.org/gajus/strading)[![Coverage Status](https://camo.githubusercontent.com/3a53644f9da34bf2adde581ba4931ccfb16cd4d5d2a49e06aaaaf724d3190b26/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f67616a75732f7374726164696e672f6d61737465722e737667)](https://coveralls.io/r/gajus/strading?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/834043345da83bd3c0f4a733c36adf1cec997d05c90e95f81d5cf6ffb2e8bfe7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f67616a75732f7374726164696e672e737667)](https://packagist.org/packages/gajus/strading)

Secure Trading Web Services API abstraction.

Documentation
-------------

[](#documentation)

1. [Instantiating Strading](#instantiating-strading)
2. [Load request template](#load-request-template)
3. [Populate the template](#populate-the-template)
4. [Make request](#make-request)
5. [Interpret response](#interpret-response)

To learn about the different types of requests and the required attributes, refer to the Secure Trading [Web Services API documentation](http://www.securetrading.com/support/document/category/web-services/).

### Instantiating Strading

[](#instantiating-strading)

[Service](./Service.php) is used to construct [Request](./Request.php) using existing templates and to pre-populate them with your API credentials.

```
/**
 * @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', 'api@anuary.com', '93gbjdMR');
```

### Load Request template

[](#load-request-template)

Requests templates to process card and PayPal transactions come with the library:

- [paypal/order](./src/template/paypal/order.xml)
- [paypal/auth](./src/template/paypal/auth.xml)
- [card/refund](./src/template/cart/refund.xml)
- [card/auth](./src/template/card/auth.xml)
- [transactionquery](./src/template/paypal/transactionquery.xml)

To make a new template, copy over the full request XML from the respective Secure Trading documentation.

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

The above example has initialised [Request](./src/Request.php) using the "card/auth" template.

### Populate the Template

[](#populate-the-template)

Template is populated from an array, where each array key refers to an existing node.

```
/**
 * 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' => 'foo@bar.baz',
    'name' => [
        'first' => 'Foo',
        'last' => 'Bar'
    ],
    'payment' => [
        'pan' => '4111110000000211',
        'securitycode' => '123',
        'expirydate' => '10/2031'
    ],
    'payment[type]' => 'VISA'
],'/requestblock/request/billing');
```

The above example is using "/requestblock/request/billing" namespace to refer to a specific XML node. Do this to reduce the amount of array nesting.

To preview the request, you can retrive the `SimpleXMLElement`:

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

The above will produce:

```

    api@anuary.com

            100
            foo@bar.baz

                Bar
                Foo

                10/2031
                4111110000000211
                123

            test_github53934
            ECOM

```

The XML nodes that were not populated and did not have a default value in the template, were stripped away from the request XML.

You can populate the request over several itterations.

```
$auth->populate([
    'merchant' => [
        'orderreference' => 'gajus-0000001'
    ],
    'customer' => [
        'name' => [
                'first' => 'Foo',
                'last' => 'Bar'
            ],
        'email' => 'foo@bar.baz'
    ]
], '/requestblock/request');
```

The above will produce:

```

    api@anuary.com

            gajus-0000001

            foo@bar.baz

                Bar
                Foo

            100
            foo@bar.baz

                Bar
                Foo

            10/2031
            4111110000000211
            123

            test_github53934
            ECOM

```

Methods to dump XML are for debugging only. You do not need to deal with XML when making the request or handling the response.

### Changing the template directory

[](#changing-the-template-directory)

The location of your request templates can be changed by calling the `setTemplateDirectory()` method.

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

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

### Make Request

[](#make-request)

Make the request and capture the `Response`:

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

If HTTP response is not `200`, then `Gajus\Strading\Exception\RuntimeException` will be thrown. This will happen if you provide invalid authentication credentials or your credentials do not grant you access to the API endpoint.

### Interpret Response

[](#interpret-response)

[Response](./src/Response.php) class abstracts the response XML.

```
/**
 * 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 include "paypal_token" parameter.
 *
 * @return array
 */
public function getTransaction ();

/**
 * This information is available when response type is "ERROR".
 *
 * @return null|Gajus\Strading\Error
 */
public function getError ();

/**
 * This information is available in response to the "paypal/order" request.
 *
 * @return null|string URL to redirect the client to.
 */
public function getRedirectUrl () {
    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();
}
```

#### Error

[](#error)

In case `Response` type is "ERROR", the `getError` method will return an instance of `Gajus\Strading\Error`.

```
/**
 * @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;
}
```

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 93.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~295 days

Total

2

Last Release

4157d ago

PHP version history (2 changes)0.1.0PHP &gt;=5.4

0.9.1PHP &gt;=5.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/b46b18abe058b038c677a9fa4aa6c39de7597196fb72a11add1f11600412a0e5?d=identicon)[gajus](/maintainers/gajus)

---

Top Contributors

[![gajus](https://avatars.githubusercontent.com/u/973543?v=4)](https://github.com/gajus "gajus (68 commits)")[![chrisnharvey](https://avatars.githubusercontent.com/u/619298?v=4)](https://github.com/chrisnharvey "chrisnharvey (5 commits)")

---

Tags

apipaymentgatewaymerchantsecure trading

### Embed Badge

![Health badge](/badges/gajus-strading/health.svg)

```
[![Health](https://phpackages.com/badges/gajus-strading/health.svg)](https://phpackages.com/packages/gajus-strading)
```

###  Alternatives

[mollie/mollie-api-php

Mollie API client library for PHP. Mollie is a European Payment Service provider and offers international payment methods such as Mastercard, VISA, American Express and PayPal, and local payment methods such as iDEAL, Bancontact, SOFORT Banking, SEPA direct debit, Belfius Direct Net, KBC Payment Button and various gift cards such as Podiumcadeaukaart and fashioncheque.

60216.0M85](/packages/mollie-mollie-api-php)[mollie/laravel-mollie

Mollie API client wrapper for Laravel &amp; Mollie Connect provider for Laravel Socialite

3624.5M36](/packages/mollie-laravel-mollie)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
