PHPackages                             beyntech/safecharge-php - 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. beyntech/safecharge-php

ActiveLibrary

beyntech/safecharge-php
=======================

A PHP client library for accessing SafeCharge API

2.0.3(6y ago)1551MITPHPPHP &gt;=5.4

Since Oct 4Pushed 6y agoCompare

[ Source](https://github.com/BeynTech/safecharge-php)[ Packagist](https://packagist.org/packages/beyntech/safecharge-php)[ Docs](https://github.com/SafeChargeInternational/safecharge-php)[ RSS](/packages/beyntech-safecharge-php/feed)WikiDiscussions master Synced today

READMEChangelog (3)Dependencies (2)Versions (14)Used By (0)

SafeCharge REST API SDK for PHP
===============================

[](#safecharge-rest-api-sdk-for-php)

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:

Requirements
------------

[](#requirements)

PHP 5.4 or later.

Installation
============

[](#installation)

### Installation via Composer

[](#installation-via-composer)

```
composer require safecharge-international/safecharge-php
```

### Manual

[](#manual)

If you do not wish to use Composer, you can download the [latest release](https://github.com/SafeChargeInternational/safecharge-php/releases). Then include the `init.php` file.

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

Dependencies
------------

[](#dependencies)

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

- [`curl`](https://secure.php.net/manual/en/book.curl.php)
- [`json`](https://secure.php.net/manual/en/book.json.php)

Configuration
-------------

[](#configuration)

### Client

[](#client)

```
$client = new \SafeCharge\Api\RestClient([
    'environment'       => \SafeCharge\Api\Environment::TEST,
    'merchantId'        => '',
    'merchantSiteId'    => '',
    'merchantSecretKey' => '',
]);
```

If your hash algorithm is md5 you should add parameter 'hashAlgorithm' with value 'md5' in the above array.

Or

```
$client = new \SafeCharge\Api\RestClient();
$config = $client->getConfig();
$config->setEnvironment(\SafeCharge\Api\Environment::TEST);
$config->setMerchantId('');
$config->setMerchantSiteId('');
$config->setMerchantSecretKey('');
```

If your hash algorithm is md5 add the following code right after the one above:

```
$config->setHashAlgorithm('md5');
```

### Logger

[](#logger)

Logger can be configured with a [PSR-3 compatible logger](http://www.php-fig.org/psr/psr-3/) .

#### Example with Monolog

[](#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
-------

[](#example)

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

```
