Download the PHP package cruisedotco/trustly-client-php without Composer

On this page you can find all versions of the php package cruisedotco/trustly-client-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package trustly-client-php

Trustly PHP Client

This is an example implementation of communication with the Trustly API using PHP. It implements the standard Payments API as well as gives stubs for executing calls against the API used by the backoffice.

For full documentation on the Trustly API internals visit our developer website: http://trustly.com/developer . All information about software flows and call patters can be found on that site. The documentation within this code will only cover the code itself, not how you use the Trustly API.

This code is provided as-is, use it as inspiration, reference or drop it directly into your own project and use it.

If you find problem in the code or want to extend it feel free to fork it and send us a pull request.

This code should work with PHP 5 (>= 5.2.0). PHP modules needed are: bcmath, openssl, curl, mbstring and json.

Overview

The code provided wrappers for calling the trustly API. Create an instance of the API call with you merchant criterias and use the stubs in that class for calling the API. The API will default to communicate with https://trustly.com, override the host parameter for the constructor to comminicate with test.trustly.com instead.

When processing an incoming notification the handleNotification() method of the API will help with parsing and verifying the message signature, use notificationResponse() to build a proper response object

The examples below represent a very basic usage of the calls. A minimum of error handling around this code would be to check for the following exceptions during processing.

Example deposit call

require_once('Trustly.php');

/* Change 'test.trustly.com' to 'trustly.com' below to use the live environment */
$api = new Trustly\Api\Trustly_Api_Signed(
                $trustly_rsa_private_key,
                $trustly_username,
                $trustly_password,
                'test.trustly.com'
            );

/* Guzzle will handle our remote requests. */
$api->setGuzzle(new \GuzzleHttp\Client());

$deposit = $api->deposit(
                "$base_url/php/example.php/notification",   /* NotificationURL */
                '[email protected]',                     /* EndUserID */
                $messageid,                                 /* MessageID */
                'en_US',                                    /* Locale */
                $amount,                                    /* Amount */
                $currency,                                  /* Currency */
                'SE',                                       /* Country */
                NULL,                                       /* MobilePhone */
                NULL,                                       /* FirstName */
                NULL,                                       /* LastName */
                NULL,                                       /* NationalIdentificationNumber */
                'Test',                                     /* ShopperStatement */
                $ip,                                        /* IP */
                "$base_url/success.html",                   /* SuccessURL */
                "$base_url/fail.html",                      /* FailURL */
                NULL,                                       /* TemplateURL */
                "0",                                        /* URLTarget */
                NULL,                                       /* SuggestedMinAmount */
                NULL,                                       /* SuggestedMaxAmount */
                'trustly-client-php example/1.0'            /* IntegrationModule */
                FALSE,                                      /* HoldNotifications */
                '[email protected]',                     /* Email */
                'SE',                                       /* ShippingAddressCountry */
                '12345',                                    /* ShippingAddressPostalCode */
                'ExampleCity',                              /* ShippingAddressCity */
                '123 Main St'                               /* ShippingAddressLine1 */
                'C/O Careholder',                           /* ShippingAddressLine2 */
                NULL                                        /* ShippingAddress */
            );

$iframe_url= $deposit->getData('url');

Example notification processing

$request = $api->handleNotification($notification_body);
    # FIXME Handle the incoming notification data here
$notifyresponse = $api->notificationResponse($request, TRUE);

echo $notifyresponse->json();

Example implementation

In the example/ subdirectory is a simple implementation of a client that uses the code to make a deposit call to Trustly and processes incoming notifications. The code is well commented and contains information about what to calls that needs to be made and some caveats while doing so.

Use the built-in php webserver to give it a go (php -S localhost:8000 in the example/www directory). You need to amend example/www/php/example.php and example/example.private.pem to contain your processing account information before giving it a test spin.

Contribution / Development

Feel free to raise a pull request for changes that you may need. Any changes coming in would need to be covered with unit tests.

Thanks very much, happy open sourcing.


All versions of trustly-client-php with dependencies

PHP Build Version
Package Version
Requires ext-json Version *
ext-bcmath Version *
ext-openssl Version *
ext-curl Version *
ext-mbstring Version *
php Version >=5.2.0
guzzlehttp/guzzle Version ^6.3
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package cruisedotco/trustly-client-php contains the following files

Loading the files please wait ....