diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..347a927 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/.idea/ +/composer.lock +/composer.phar +/vendor/ diff --git a/README.md b/README.md index 865e37f..edd916c 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,35 @@ # UnitPay PHP-SDK -Php sdk for [UnitPay ](https://unitpay.ru) +Php sdk for [UnitPay](https://unitpay.ru) Documentation https://unitpay.ru/doc -## Examples ## -These are just some quick examples. Check out the samples in [`/sample`](https://github.com/unitpay/php-sdk/blob/master/sample). +## Installation + +The preferred way to install this extension is through [composer](https://getcomposer.org/download/). + +Either run + +```bash +$ php composer.phar require unitpay/php-sdk +``` + +or add + +``` +"unitpay/php-sdk": "^1.0" +``` + +to the ```require``` section of your `composer.json` file. + + +## Examples + +These are just some quick examples. Check out the samples in [`/examples`](https://github.com/unitpay/php-sdk/blob/master/examples). ### Payment integration using UnitPay Form ```php setBackUrl('http://domain.com') ->setCustomerEmail('customer@domain.com') ->setCustomerPhone('79001235555') ->setCashItems(array( - new CashItem($itemName, 1, $orderSum) + new unitpay\CashItem($itemName, 1, $orderSum) )); $redirectUrl = $unitPay->form( @@ -58,7 +78,7 @@ header('Content-Type: text/html; charset=UTF-8'); * @link https://unitpay.ru/doc#initPayment */ -include ('../UnitPay.php'); +require_once('vendor/autoload.php'); // Project Data $projectId = 1; @@ -73,7 +93,7 @@ $orderSum = 900; $orderDesc = 'Payment for item "'.$itemName.'"'; $orderCurrency = 'RUB'; -$unitPay = new UnitPay($secretKey); +$unitPay = new unitpay\UnitPay($secretKey); /** * Base params: account, desc, sum, currency, projectId, paymentType @@ -134,7 +154,7 @@ if (isset($response->result->type) * * @link https://unitpay.ru/doc#confirmPayment */ -include ('../UnitPay.php'); +include ('vendor/autoload.php'); // Project Data $projectId = 1; @@ -149,7 +169,7 @@ $orderSum = 900; $orderDesc = 'Payment for item "' . $itemName . '"'; $orderCurrency = 'RUB'; -$unitPay = new UnitPay($secretKey); +$unitPay = new unitpay\UnitPay($secretKey); try { // Validate request (check ip address, signature and etc) @@ -189,25 +209,6 @@ try { } ``` -## Installation - -### Install composer package -Set up `composer.json` in your project directory: -``` -{ - "require":{"unitpay/php-sdk":"dev-master"} -} -``` - -Run [composer](http://getcomposer.org/doc/00-intro.md#installation): -```sh -$ php composer.phar install -``` - -### Direct download - -Download [last version ](https://github.com/unitpay/php-sdk/archive/master.zip) , unzip and copy to your project folder. - -## Contributing ## +## Contributing -Please feel free to contribute to this project! Pull requests and feature requests welcome! \ No newline at end of file +Please feel free to contribute to this project! Pull requests and feature requests welcome! diff --git a/composer.json b/composer.json index 6a27766..7d5544c 100644 --- a/composer.json +++ b/composer.json @@ -14,11 +14,11 @@ } ], "require":{ - "php":">=5.3.0" + "php":">=5.4.0" }, "autoload":{ - "classmap":[ - "./UnitPay.php" - ] + "psr-4": { + "unitpay\\": "src" + } } } diff --git a/sample/handler.php b/examples/handler.php similarity index 95% rename from sample/handler.php rename to examples/handler.php index c4635e7..fb791c7 100644 --- a/sample/handler.php +++ b/examples/handler.php @@ -7,9 +7,9 @@ */ require_once('./orderInfo.php'); -require_once('../UnitPay.php'); +require_once('../vendor/autoload.php'); -$unitPay = new UnitPay($secretKey); +$unitPay = new unitpay\UnitPay($secretKey); try { // Validate request (check ip address, signature and etc) diff --git a/sample/initPaymentApi.php b/examples/initPaymentApi.php similarity index 95% rename from sample/initPaymentApi.php rename to examples/initPaymentApi.php index caeb99b..74311ec 100644 --- a/sample/initPaymentApi.php +++ b/examples/initPaymentApi.php @@ -9,9 +9,9 @@ */ require_once('./orderInfo.php'); -require_once('../UnitPay.php'); +require_once('../vendor/autoload.php'); -$unitPay = new UnitPay($secretKey); +$unitPay = new unitpay\UnitPay($secretKey); /** * Base params: account, desc, sum, currency, projectId, paymentType diff --git a/sample/initPaymentForm.php b/examples/initPaymentForm.php similarity index 78% rename from sample/initPaymentForm.php rename to examples/initPaymentForm.php index 8d8d884..e8ea7ce 100644 --- a/sample/initPaymentForm.php +++ b/examples/initPaymentForm.php @@ -7,9 +7,9 @@ */ require_once('./orderInfo.php'); -require_once('../UnitPay.php'); +require_once('../vendor/autoload.php'); -$unitPay = new UnitPay($secretKey); +$unitPay = new unitpay\UnitPay($secretKey); $redirectUrl = $unitPay->form( $publicId, diff --git a/sample/orderInfo.php b/examples/orderInfo.php similarity index 100% rename from sample/orderInfo.php rename to examples/orderInfo.php diff --git a/sample/paymentInfo.php b/examples/paymentInfo.php similarity index 86% rename from sample/paymentInfo.php rename to examples/paymentInfo.php index 6a7faf3..52863fe 100644 --- a/sample/paymentInfo.php +++ b/examples/paymentInfo.php @@ -9,9 +9,9 @@ */ require_once('./orderInfo.php'); -require_once('../UnitPay.php'); +require_once('../vendor/autoload.php'); -$unitPay = new UnitPay($secretKey); +$unitPay = new unitpay\UnitPay($secretKey); $response = $unitPay->api('getPayment', [ 'paymentId' => 3403575 diff --git a/src/CashItem.php b/src/CashItem.php new file mode 100644 index 0000000..215882c --- /dev/null +++ b/src/CashItem.php @@ -0,0 +1,72 @@ +name = $name; + $this->count = $count; + $this->price = $price; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @return int + */ + public function getCount() + { + return $this->count; + } + + /** + * @return float + */ + public function getPrice() + { + return $this->price; + } +} diff --git a/UnitPay.php b/src/UnitPay.php similarity index 91% rename from UnitPay.php rename to src/UnitPay.php index 2936506..9646515 100644 --- a/UnitPay.php +++ b/src/UnitPay.php @@ -21,54 +21,7 @@ * */ - -/** - * Value object for paid goods - */ -class CashItem -{ - private $name; - - private $count; - - private $price; - - /** - * @param string $name - * @param int $count - * @param float $price - */ - public function __construct($name, $count, $price) - { - $this->name = $name; - $this->count = $count; - $this->price = $price; - } - - /** - * @return string - */ - public function getName() - { - return $this->name; - } - - /** - * @return int - */ - public function getCount() - { - return $this->count; - } - - /** - * @return float - */ - public function getPrice() - { - return $this->price; - } -} +namespace unitpay; /** * Payment method UnitPay process @@ -343,4 +296,4 @@ public function getErrorHandlerResponse($message) ) )); } -} \ No newline at end of file +}