Skip to content

Commit

Permalink
v2.0.0-BETA1 [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaliy Zakharov committed Jul 27, 2015
1 parent bf09e1d commit 3b74a50
Show file tree
Hide file tree
Showing 155 changed files with 5,810 additions and 6,659 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
vendor
vendor
build/artifacts
phpunit.xml
12 changes: 12 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

$finder = Symfony\CS\Finder\DefaultFinder::create()
->in(__DIR__)
->exclude('build/artifacts')
->exclude('vendor')
;

return Symfony\CS\Config\Config::create()
->fixers(array('-psr0', 'symfony', 'long_array_syntax', '-phpdoc_separation'))
->finder($finder)
;
42 changes: 0 additions & 42 deletions .scrutinizer.yml

This file was deleted.

25 changes: 18 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
language: php

php:
- 5.3.3
- 5.3
- 5.4
- 5.5
- 5.6
- 7.0
- nightly
- hhvm

before_script:
- COMPOSER_ROOT_VERSION=dev-master composer --prefer-source --dev install
sudo: false

env:
- COMPOSER_OPTS=""
- COMPOSER_OPTS="--prefer-lowest"

matrix:
allow_failures:
- php: nightly
- php: 7

install:
- travis_retry composer update $COMPOSER_OPTS --no-interaction --prefer-source

script:
- phpunit --colors --coverage-clover=coverage.clover
- if [ "`phpenv version-name`" = "5.5" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi
- if [ "`phpenv version-name`" = "5.5" ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi
- phpunit --colors --verbose --exclude-group webhook
- if [[ "`phpenv version-name`" != "5.3" && "`phpenv version-name`" != "hhvm" ]]; then phpunit --colors --verbose --group Webhook; fi

notifications:
slack: xsolla:btcuaeuOi3LBjHaV2Xrrb39U
slack: xsolla:V74WgCQlV6kas6X9SNQKl5R1
27 changes: 20 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,35 @@
# CHANGELOG
# Change Log
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## 1.1.1 (2014-08-05)
## [Unreleased](https://github.com/xsolla/xsolla-sdk-php/compare/v2.0.0-BETA1...master)

## [v2.0.0-BETA1](https://github.com/xsolla/xsolla-sdk-php/compare/v1.1.1...v2.0.0-BETA1)
### Added
* Simplified `XsollaClient` and `TokenRequest` methods for obtaining [Payment UI token](http://developers.xsolla.com/api.html#payment-ui)
* `WebhookServer` for receiving [notifications from Xsolla](http://developers.xsolla.com/api.html#notifications)
* [All API methods](http://developers.xsolla.com/api.html) available through `XsollaClient`

### Removed
* Removed all deprecated functionality from [previous API version](http://xsolla.github.io/en/)

## [v1.1.1](https://github.com/xsolla/xsolla-sdk-php/compare/v1.1.0...v1.1.1) - 2014-08-05
* add payment_amount, payment_currency to default locked parameters list for generation of paystation2 payment page url

## 1.1.0 (2014-07-24)
## [v1.1.0](https://github.com/xsolla/xsolla-sdk-php/compare/v1.0.4...v1.1.0) - 2014-07-24
* add Shopping Cart Protocol 3.0 http://xsolla.github.io/en/shopingcart3.html

## 1.0.4 (2014-06-04)
## [v1.0.4](https://github.com/xsolla/xsolla-sdk-php/compare/v1.0.3...v1.0.4) - 2014-06-04
* fix incorrect sign code for Shopping Cart Protocol 2.0
* add `$reasonCode` and `$reasonDescription` optional arguments to `PaymentStorageInterface::cancel`

## 1.0.3 (2014-04-22)
## [v1.0.3](https://github.com/xsolla/xsolla-sdk-php/compare/v1.0.2...v1.0.3) - 2014-04-22
* added missed sandbox key to UrlBuilder for sandbox-secure.xsolla.com
* fixed wrong error code for IPN requests with zero valued parameters

## 1.0.2 (2014-02-27)
## [v1.0.2](https://github.com/xsolla/xsolla-sdk-php/compare/v1.0.1...v1.0.2) - 2014-02-27
* add `$baseUrl` optional argument to `UrlBuilder::getUrl()` and `UrlBuilder::SANDBOX_URL` constant

## 1.0.1 (2014-02-25)
## [v1.0.1](https://github.com/xsolla/xsolla-sdk-php/compare/v1.0.0...v1.0.1) - 2014-02-25
* fix `description` response field name for UnprocessableRequestException handling in Shopping Cart protocol
* fix repeated notifications handling in Shopping Cart protocol
170 changes: 84 additions & 86 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,127 +1,125 @@
# [DEPRECATED] Xsolla SDK for PHP
# Xsolla SDK for PHP

[![Latest Stable Version](https://poser.pugx.org/xsolla/xsolla-sdk-php/v/stable.png)](https://packagist.org/packages/xsolla/xsolla-sdk-php)
[![Build Status](https://travis-ci.org/xsolla/xsolla-sdk-php.png?branch=master)](https://travis-ci.org/xsolla/xsolla-sdk-php)
[![Code Coverage](https://scrutinizer-ci.com/g/xsolla/xsolla-sdk-php/badges/coverage.png?s=6961fe8e4895fe6292b981f53c2ebc8f89fb1309)](https://scrutinizer-ci.com/g/xsolla/xsolla-sdk-php/)
[![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/xsolla/xsolla-sdk-php/badges/quality-score.png?s=e04a6701a560d126eef80f33f8a1181372588472)](https://scrutinizer-ci.com/g/xsolla/xsolla-sdk-php/)
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/44ae8284-c5c3-40f8-b1e3-de4093995db5/mini.png)](https://insight.sensiolabs.com/projects/44ae8284-c5c3-40f8-b1e3-de4093995db5)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/xsolla/xsolla-sdk-php/badges/quality-score.png?b=v2)](https://scrutinizer-ci.com/g/xsolla/xsolla-sdk-php)
[![Join the chat at https://gitter.im/xsolla/xsolla-sdk-php](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/xsolla/xsolla-sdk-php?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/xsolla/xsolla-sdk-php/master/LICENSE)

An official PHP SDK for interacting with [Xsolla API](http://developers.xsolla.com/api.html)
An official PHP SDK for interacting with [Xsolla API](http://developers.xsolla.com)

![Payment UI screenshot](http://xsolla.cachefly.net/img/ps3_github_new.png)

## Features

* Full customisation of Payment UI with the help of different methods of getting token.
* Client for all API methods, making your integration easy and convenient. You can use it for setting up and updating virtual currency, items and subscription plans, for managing the users balance, for checking the finance information with the help of Report API and so on.
* Convenient webhook server:
* To start you need only one callback function.
* All security checking already implemented: signature authentication and IP whitelisting.
* Full customisation of notification processing logic, if standard server class doesn’t suit you.
* SDK is built on Guzzle v3, and utilizes many of its features, including persistent connections, parallel requests, events and plugins (via Symfony2 EventDispatcher), service descriptions, over-the-wire logging, caching, flexible batching, and request retrying with truncated exponential back off.

## Requirements

* PHP 5.3.3+
* PHP 5.3.9+
* Your php.ini needs to have the date.timezone setting
* The following PHP extensions are required:
* curl
* json

## Installation

### Installing via Composer

The recommended way to install Xsolla SDK for PHP is through [Composer](http://getcomposer.org).

``` bash
$ cd /path/to/your/project
$ composer require xsolla/xsolla-sdk-php:~1.0
$ composer require xsolla/xsolla-sdk-php
```

## Usage
### Installing via Phar

### Generate URL to [Payment Page](http://xsolla.github.io/en/plugindemonstration.html)
You can [download the packaged phar](https://github.com/xsolla/xsolla-sdk-php/releases) and include it in your scripts to get started:

``` php
<?php
require '/path/to/xsolla.phar';
```

### Installing via Zip

require_once 'vendor/autoload.php';
You can [download the zip file](https://github.com/xsolla/xsolla-sdk-php/releases), unzip it into your project to a location of your choosing, and include the autoloader:

use Xsolla\SDK\Project;
use Xsolla\SDK\User;
use Xsolla\SDK\Invoice;
use Xsolla\SDK\PaymentPage\UrlBuilderFactory;
``` php
require '/path/to/xsolla-autoloader.php';
```

$project = new Project(
'4783',//demo project id
'key'//demo project secret key
);
$urlBuilderFactory = new UrlBuilderFactory($project);
## Quick Examples

$user = new User('username');
$user->setEmail('[email protected]')
->setPhone('79090000000');
### Integrate Payment UI

$invoice = new Invoice;
$invoice->setVirtualCurrencyAmount(5);
Generate Payment UI token:

$url = $urlBuilderFactory->getPayStation()
->setInvoice($invoice)
->setUser($user)
->unlockParameterForUser('email')
->setCountry('US')
->setLocale('en')
->setParameter('theme', 115)
->setParameter('description', 'Purchase description')
->getUrl();
``` php
<?php

echo $url.PHP_EOL;
use Xsolla\SDK\API\XsollaClient;

?>
$client = XsollaClient::factory(array(
'merchant_id' => MERCHANT_ID,
'api_key' => 'API_KEY'
));
$paymentUIToken = $client->createCommonPaymentUIToken(PROJECT_ID, USER_ID);
```
### Receive [Instant Payment Notification](http://xsolla.github.io/en/currency.html)

For receiving IPN requests you should implement [\Xsolla\SDK\Protocol\Storage](https://github.com/xsolla/xsolla-sdk-php/tree/master/src/Protocol/Storage) interfaces.
Also you can setup sql tables for your [protocol](http://xsolla.github.io/en/currency.html) from [resources/mysql](https://github.com/xsolla/xsolla-sdk-php/tree/master/resources/mysql) and use [\Xsolla\SDK\Protocol\Storage\Pdo](https://github.com/xsolla/xsolla-sdk-php/tree/master/src/Protocol/Storage/Pdo) classes directly or extend it.
Render Payment UI script in your page:

``` php
<?php
$demoProject = new \Xsolla\SDK\Project(
'4783',//demo project id
'key'//demo project secret key
);

$dsn = sprintf('mysql:dbname=%s;host=%s;charset=utf8', 'YOUR_DB_NAME', 'YOUR_DB_HOST');
$pdo = new \PDO($dsn, 'YOUR_DB_USER', 'YOUR_DB_PASSWORD');
$usersStorage = new \Xsolla\SDK\Protocol\Storage\Pdo\UserStorage($pdo);
$paymentsStorage = new \Xsolla\SDK\Protocol\Storage\Pdo\PaymentStandardStorage($pdo);
$ipChecker = new \Xsolla\SDK\Validator\IpChecker;
$protocolBuilder = new \Xsolla\SDK\Protocol\ProtocolFactory($demoProject, $ipChecker);
$protocol = $protocolBuilder->getStandardProtocol($usersStorage, $paymentsStorage);

$request = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
$response = $protocol->run($request);
$response->send();
<html>
<head lang="en">
<meta charset="UTF-8">
</head>
<body>
<button data-xpaystation-widget-open>Test Button</button>

<?php \Xsolla\SDK\API\PaymentUI\PaymentUIScriptRenderer::send($paymentUIToken); ?>
</body>
</html>
```
[IpChecker](https://github.com/xsolla/xsolla-sdk-php/blob/master/src/Validator/IpChecker.php) - additional security level for situations when your secret key is compromised.
It's a optional parameter for ProtocolFactory and you can skip it for development and testing environment.
If you use reverse proxy, you should set a list of trusted proxies via [Request::setTrustedProxies()](http://symfony.com/doc/current/components/http_foundation/trusting_proxies.html)

#### IPN demo
You can run IPN demo with the following commands(required php 5.4+ with built-in server):
### Receive webhooks

``` bash
$ cd /path/to/xsolla/xsolla-sdk-php
$ composer install
$ php -S localhost:9000 -t example example/ipn_standard.php > /dev/null 2>&1 &
$ # no command
$ curl 'localhost:9000'
$ # user found
$ curl 'http://localhost:9000/?command=check&v1=demo&v2=&v3=&md5=a3561b90df78828133eb285e36965419'
$ # user not found or disabled
$ curl 'http://localhost:9000/?command=check&v1=not_exist&v2=&v3=&md5=5f67cabd3cf27cac2944e7f9f762a42a'
$ # success IPN handling. Response contain payment ID
$ curl 'http://localhost:9000/?command=pay&id=1&v1=demo&v2=&v3=&date=2014-02-19+13%3A03%3A52&sum=1&md5=eae3e95e93ff64f72aeb9fadfd8f0d66'
$ # failed IPN handling. Unprocessable request error
$ curl 'http://localhost:9000/?command=pay&id=2&v1=demo&v2=&v3=&date=2014-02-19+13%3A04%3A30&sum=5&md5=3067aeb81faa883f36d27acc9d808abb'
$ # success payment cancel
$ curl 'http://localhost:9000/?command=cancel&id=3&md5=9ac4f238314b0a0dae5be98151d19f33'
```
### Examples
More examples you can find in [example](https://github.com/xsolla/xsolla-sdk-php/tree/master/example) folder.
All examples are executable and you can run them with the following commands.
``` php
<?php

``` bash
$ cd /path/to/xsolla/xsolla-sdk-php
$ composer install
$ php example/calculator.php
use Xsolla\SDK\Webhook\WebhookServer;
use Xsolla\SDK\Webhook\Message\Message;
use Xsolla\SDK\Exception\Webhook\XsollaWebhookException;

$callback = function (Message $message) {
switch ($message->getNotificationType()) {
case Message::USER_VALIDATION:
//check user existence
break;
case Message::PAYMENT:
//handle payment
break;
case Message::REFUND:
//handle refund
break;
default:
throw new XsollaWebhookException('Notification type not implemented');
}
};

$webhookServer = WebhookServer::create($callback, PROJECT_KEY); // https://merchant.xsolla.com/MERCHANT_ID/projects/PROJECT_ID/settings/connection
$webhookServer->start();
```

## Additional resources

* [Website](http://xsolla.com)
* [Documentation](http://xsolla.github.io)
* [Documentation](http://developers.xsolla.com)
* [Status](http://status.xsolla.com)
* [Support and Feedback](mailto:[email protected])
Empty file added build/artifacts/.gitkeep
Empty file.
20 changes: 20 additions & 0 deletions build/packager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

require __DIR__.'/../vendor/autoload.php';

$packager = new \Burgomaster(__DIR__.'/artifacts/staging', __DIR__.'/../');

$packager->exec('rm -rf '.__DIR__.'/artifacts/xsolla.*');

$packager->recursiveCopy('src', 'Xsolla/SDK');
$packager->recursiveCopy('vendor/guzzle/guzzle/src/Guzzle', 'Guzzle', array('php', 'pem'));
$packager->recursiveCopy('vendor/symfony/event-dispatcher', 'Symfony/Component/EventDispatcher');
$packager->recursiveCopy('vendor/symfony/http-foundation', 'Symfony/Component/HttpFoundation');

$packager->createAutoloader(array(), 'xsolla-autoloader.php');
$packager->createPhar(__DIR__.'/artifacts/xsolla.phar', null, 'xsolla-autoloader.php');
$packager->createZip(__DIR__.'/artifacts/xsolla.zip');

$packager->startSection('test-phar');
$packager->exec('php '.__DIR__.'/test-phar.php');
$packager->endSection();
13 changes: 13 additions & 0 deletions build/test-phar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

require __DIR__.'/artifacts/xsolla.phar';

use Xsolla\SDK\Webhook\WebhookServer;
use Xsolla\SDK\API\XsollaClient;

$client = XsollaClient::factory(array(
'merchant_id' => 'MERCHANT_ID',
'api_key' => 'API_KEY',
));

$webhookServer = WebhookServer::create(function () {}, 'PROJECT_SECRET_KEY');
Loading

0 comments on commit 3b74a50

Please sign in to comment.