grandmasterx/safecharge

Extension for integration SafeCharge in yii2 project

Installs: 2 195

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0

Type:yii2-extension

v1.0.1 2017-11-23 07:44 UTC

This package is not auto-updated.

Last update: 2024-04-28 01:34:46 UTC


README

SafeCharge’s REST API SDK for PHP provides developer tools for accessing Safecharge's REST API. SafeCharge’s REST API is a simple, easy to use, secure and stateless API, which enables online merchants and service providers to process consumer payments through SafeCharge’s payment gateway. The API supports merchants of all levels of PCI certification, from their online and mobile merchant applications, and is compatible with a large variety of payment options, i.e. payment cards, alternative payment methods, etc. For SafeCharge REST API documentation, please see: https://www.safecharge.com/docs/api/

Requirements

PHP 5.4 or later.

Installation

Installation via Composer

composer require grandmasterx/safecharge

Manual

If you do not wish to use Composer, you can download the latest release. Then include the init.php file.

require_once('/path/to/safecharge-sdk/init.php');

Dependencies

The PHP SDK require the following extension in order to work properly:

Configuration

Client

$client = new \grandmasterx\safecharge\api\RestClient([
    'environment'       => \grandmasterx\safecharge\api\Environment::TEST,
    'merchantId'        => '<your merchantId>',
    'merchantSiteId'    => '<your merchantSiteId>',
    'merchantSecretKey' => '<your merchantSecretKey>',
]);

Or

$client = new \grandmasterx\safecharge\api\RestClient();
$config = $client->getConfig();
$config->setEnvironment(\grandmasterx\safecharge\api\Environment::TEST);
$config->setMerchantId('<your merchantId>');
$config->setMerchantSiteId('<your merchantSiteId>');
$config->setMerchantSecretKey('<your merchantSecretKey>');

Logger

Logger can be configured with a PSR-3 compatible logger .

Example with Monolog

$logger = new Monolog\Logger('safecharge-php-sdk');
$logger->pushHandler(new Monolog\Handler\StreamHandler('path/to/log', Monolog\Logger::DEBUG));
$client->setLogger($logger);

Example

Safecharge's PHP SDK appends merchantId, merchantSiteId, timestamp and checksum in the request.

<?php
$client = new \grandmasterx\safecharge\api\RestClient([
    'environment'       => \grandmasterx\safecharge\api\Environment::TEST,
    'merchantId'        => '<your merchantId>',
    'merchantSiteId'    => '<your merchantSiteId>',
    'merchantSecretKey' => '<your merchantSecretKey>',
]);

$authenticationService = new \grandmasterx\safecharge\api\services\AuthenticationManagement($client);

$authenticationResponse = $authenticationService->getSessionToken([
    'clientRequestId' => '1'
]);

$openOrderParams = [
    'sessionToken'      => $authenticationResponse['sessionToken'],
    'currency'          => 'USD',
    'amount'            => "10",
    'amountDetails'     => [
        "totalShipping" => "0",
        "totalHandling" => "0",
        "totalDiscount" => "0",
        "totalTax"      => "0"
    ],
    'items'             => [
        [
            "id"       => "1",
            "name"     => "name",
            "price"    => "10",
            "quantity" => "1"
        ]
    ],
];

$orderService = new \grandmasterx\safecharge\api\services\OrdersManagement($client);

$openOrderResponse = $orderService->openOrder($openOrderParams);