├── .github └── workflows │ └── tests.yml ├── .gitignore ├── .scrutinizer.yml ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── chkipper.json ├── composer.json ├── hidev.yml ├── history.md ├── phpunit.xml.dist ├── src ├── Gateway.php └── Message │ ├── AbstractRequest.php │ ├── CompletePurchaseRequest.php │ ├── CompletePurchaseResponse.php │ ├── PurchaseRequest.php │ └── PurchaseResponse.php ├── tests ├── _bootstrap.php └── unit │ ├── GatewayTest.php │ └── Message │ ├── CompletePurchaseRequestTest.php │ ├── CompletePurchaseResponseTest.php │ ├── PurchaseRequestTest.php │ └── PurchaseResponseTest.php └── version /.github/workflows/tests.yml: -------------------------------------------------------------------------------- 1 | name: Tests 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | PHPUnit: 7 | runs-on: ubuntu-latest 8 | strategy: 9 | matrix: 10 | php: ['7.4', '8.0', '8.1'] 11 | coverage-driver: [pcov] 12 | name: PHP ${{ matrix.php }} 13 | steps: 14 | - name: Checkout 15 | uses: actions/checkout@v2 16 | 17 | - name: Install PHP 18 | uses: shivammathur/setup-php@v2 19 | with: 20 | php-version: ${{ matrix.php }} 21 | extensions: gmp 22 | coverage: pcov 23 | tools: composer:v2, infection 24 | 25 | - name: Cache Composer packages 26 | id: composer-cache 27 | uses: actions/cache@v2 28 | with: 29 | path: vendor 30 | key: ${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} 31 | 32 | - name: Update composer 33 | run: composer self-update 34 | 35 | - name: Composer install 36 | if: steps.composer-cache.outputs.cache-hit != 'true' 37 | run: composer install -n 38 | 39 | - run: vendor/bin/phpunit 40 | env: 41 | XDEBUG_MODE: coverage 42 | 43 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # local config 2 | /.env 3 | /hidev-local.yml 4 | 5 | # IDE & OS files 6 | .*.swp 7 | .DS_Store 8 | .buildpath 9 | .idea 10 | .project 11 | .settings 12 | /lsp 13 | Thumbs.db 14 | nbproject 15 | 16 | # composer internals 17 | /composer.lock 18 | /vendor 19 | 20 | # php-cs-fixer cache 21 | .php_cs.cache 22 | 23 | # phpunit generated files 24 | .phpunit.result.cache 25 | coverage.clover 26 | 27 | # Binaries 28 | chkipper.phar 29 | composer.phar 30 | ocular.phar 31 | php-cs-fixer.phar 32 | phpstan.phar 33 | phpunit-skelgen.phar 34 | phpunit.phar 35 | 36 | # hidev internals 37 | /.hidev/composer.json 38 | /.hidev/composer.lock 39 | /.hidev/runtime 40 | /.hidev/vendor 41 | -------------------------------------------------------------------------------- /.scrutinizer.yml: -------------------------------------------------------------------------------- 1 | checks: 2 | php: 3 | code_rating: true 4 | duplication: true 5 | tools: 6 | php_code_coverage: 7 | enabled: true 8 | external_code_coverage: 9 | timeout: 600 10 | build: 11 | nodes: 12 | analysis: 13 | tests: { override: [php-scrutinizer-run] } 14 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | php: 3 | 0: 7.1 4 | 1: 5.6 5 | 2: 7 6 | 4: hhvm 7 | dist: trusty 8 | cache: 9 | directories: 10 | - $HOME/.composer/cache 11 | before_install: 12 | - 'composer self-update' 13 | - 'composer --version' 14 | - 'wget http://hiqdev.com/hidev/hidev.phar -O hidev.phar && chmod a+x hidev.phar' 15 | - './hidev.phar --version' 16 | - './hidev.phar travis/before-install' 17 | matrix: 18 | allow_failures: 19 | - 20 | php: hhvm 21 | sudo: false 22 | install: 23 | - './hidev.phar travis/install' 24 | script: 25 | - './hidev.phar travis/script' 26 | after_script: 27 | - './hidev.phar travis/after-script' 28 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## [Under development] 2 | 3 | ## [3.0.0] - 2019-10-17 4 | 5 | ## [0.1.0] - 2018-07-10 6 | 7 | ## [Development started] - 2017-10-03 8 | 9 | ## [3.0.1] - 2022-03-08 10 | 11 | ## [dev] - 2022-03-08 12 | 13 | [@hiqsol]: https://github.com/hiqsol 14 | [sol@hiqdev.com]: https://github.com/hiqsol 15 | [@SilverFire]: https://github.com/SilverFire 16 | [d.naumenko.a@gmail.com]: https://github.com/SilverFire 17 | [@tafid]: https://github.com/tafid 18 | [andreyklochok@gmail.com]: https://github.com/tafid 19 | [@BladeRoot]: https://github.com/BladeRoot 20 | [bladeroot@gmail.com]: https://github.com/BladeRoot 21 | [Under development]: https://github.com/hiqdev/omnipay-bitpay/compare/0.1.0...HEAD 22 | [0.1.0]: https://github.com/hiqdev/omnipay-bitpay/releases/tag/0.1.0 23 | [3.0]: https://github.com/hiqdev/omnipay-bitpay/compare/0.1.0...3.0 24 | [3.0.0]: https://github.com/hiqdev/omnipay-bitpay/compare/0.1.0...3.0.0 25 | [Development started]: https://github.com/hiqdev/omnipay-bitpay/compare/3.0.1...Development started 26 | [3.0.1]: https://github.com/hiqdev/omnipay-bitpay/compare/dev...3.0.1 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright © 2017-2018, HiQDev (http://hiqdev.com/) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BitPay driver for Omnipay PHP payment libray 2 | 3 | [![GitHub Actions](https://github.com/hiqdev/omnipay-bitpay/workflows/Tests/badge.svg)](https://github.com/hiqdev/omnipay-bitpay/actions) 4 | [![Latest Stable Version](https://poser.pugx.org/hiqdev/omnipay-bitpay/v/stable)](https://packagist.org/packages/hiqdev/omnipay-bitpay) 5 | [![Total Downloads](https://poser.pugx.org/hiqdev/omnipay-bitpay/downloads)](https://packagist.org/packages/hiqdev/omnipay-bitpay) 6 | 7 | [Omnipay](https://github.com/omnipay/omnipay) is a framework agnostic, multi-gateway payment 8 | processing library for PHP 7.1+. 9 | 10 | This package implements [BitPay](https://bitpay.com/) support for Omnipay. 11 | 12 | ## Installation 13 | 14 | The preferred way to install this library is through [composer](http://getcomposer.org/download/). 15 | 16 | Either run 17 | 18 | ```sh 19 | php composer.phar require "hiqdev/omnipay-bitpay" 20 | ``` 21 | 22 | or add 23 | 24 | ```json 25 | "hiqdev/omnipay-bitpay": "*" 26 | ``` 27 | 28 | to the require section of your composer.json. 29 | 30 | ## License 31 | 32 | This project is released under the terms of the MIT [license](LICENSE). 33 | Read more [here](http://choosealicense.com/licenses/mit). 34 | 35 | Copyright © 2017-2018, HiQDev (http://hiqdev.com/) 36 | -------------------------------------------------------------------------------- /chkipper.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hiqdev/omnipay-bitpay", 3 | "authors": { 4 | "hiqsol": { 5 | "name": "Andrii Vasyliev", 6 | "role": "Project lead", 7 | "email": "sol@hiqdev.com", 8 | "github": "https://github.com/hiqsol", 9 | "homepage": "http://hipanel.com/" 10 | }, 11 | "SilverFire": { 12 | "name": "Dmitry Naumenko", 13 | "role": "Lead backend developer", 14 | "email": "d.naumenko.a@gmail.com", 15 | "github": "https://github.com/SilverFire", 16 | "homepage": "http://silverfire.me/" 17 | }, 18 | "tafid": { 19 | "name": "Andrey Klochok", 20 | "role": "Lead frontend developer", 21 | "email": "andreyklochok@gmail.com", 22 | "github": "https://github.com/tafid", 23 | "homepage": "http://hiqdev.com/" 24 | }, 25 | "BladeRoot": { 26 | "name": "Yuriy Myronchuk", 27 | "role": "QA Lead", 28 | "email": "bladeroot@gmail.com", 29 | "github": "https://github.com/BladeRoot", 30 | "homepage": "http://hiqdev.com/" 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hiqdev/omnipay-bitpay", 3 | "type": "library", 4 | "description": "BitPay driver for Omnipay PHP payment libray", 5 | "keywords": [ 6 | "omnipay", 7 | "bitpay", 8 | "php", 9 | "merchant", 10 | "payment" 11 | ], 12 | "homepage": "https://github.com/hiqdev/omnipay-bitpay", 13 | "license": "MIT", 14 | "support": { 15 | "email": "support@hiqdev.com", 16 | "source": "https://github.com/hiqdev/omnipay-bitpay", 17 | "issues": "https://github.com/hiqdev/omnipay-bitpay/issues", 18 | "wiki": "https://github.com/hiqdev/omnipay-bitpay/wiki", 19 | "forum": "http://forum.hiqdev.com/" 20 | }, 21 | "authors": [ 22 | { 23 | "name": "Andrii Vasyliev", 24 | "role": "Project lead", 25 | "email": "sol@hiqdev.com", 26 | "homepage": "http://hipanel.com/" 27 | }, 28 | { 29 | "name": "Dmitry Naumenko", 30 | "role": "Lead backend developer", 31 | "email": "d.naumenko.a@gmail.com", 32 | "homepage": "http://silverfire.me/" 33 | }, 34 | { 35 | "name": "Andrey Klochok", 36 | "role": "Lead frontend developer", 37 | "email": "andreyklochok@gmail.com", 38 | "homepage": "http://hiqdev.com/" 39 | }, 40 | { 41 | "name": "Yuriy Myronchuk", 42 | "role": "QA Lead", 43 | "email": "bladeroot@gmail.com", 44 | "homepage": "http://hiqdev.com/" 45 | } 46 | ], 47 | "require": { 48 | "omnipay/common": "^3.0", 49 | "bitpay/sdk-light": "^2.0" 50 | }, 51 | "require-dev": { 52 | "omnipay/tests": "^4.0", 53 | "bitpay/sdk-light": "dev-master as 2.0" 54 | }, 55 | "extra": { 56 | "branch-alias": { 57 | "dev-master": "3.0.x-dev" 58 | } 59 | }, 60 | "autoload": { 61 | "psr-4": { 62 | "Omnipay\\BitPay\\": "src", 63 | "Omnipay\\BitPay\\Tests\\": "tests" 64 | } 65 | }, 66 | "repositories": [ 67 | { 68 | "type": "git", 69 | "url": "https://github.com/SilverFire/php-bitpay-light-client" 70 | } 71 | ], 72 | "config": { 73 | "allow-plugins": { 74 | "hiqdev/composer-config-plugin": true 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /hidev.yml: -------------------------------------------------------------------------------- 1 | package: 2 | type: library 3 | name: omnipay-bitpay 4 | title: BitPay driver for Omnipay PHP payment libray 5 | hedaline: 'Omnipay: BitPay' 6 | license: MIT 7 | keywords: omnipay, bitpay, php, merchant, payment 8 | description: | 9 | [Omnipay](https://github.com/omnipay/omnipay) is a framework agnostic, multi-gateway payment 10 | processing library for PHP 5.3+. 11 | 12 | This package implements [BitPay](https://bitpay.com/) support for Omnipay. 13 | 14 | -------------------------------------------------------------------------------- /history.md: -------------------------------------------------------------------------------- 1 | ## [Under development] 2 | 3 | ## [3.0.0] - 2019-10-17 4 | 5 | - [1bb3a5a] 2019-10-17 Update to Omnipay v3 [@SilverFire] 6 | 7 | ## [0.1.0] - 2018-07-10 8 | 9 | - [f267533] 2018-07-10 hideved [@SilverFire] 10 | - [6ba8cd3] 2018-07-10 Updated BitPay client depenency not to rely on deprecated ext-mcrypt [@SilverFire] 11 | - [63a7da8] 2017-11-28 Changed PurchaseRequest to cast amount to float to prevent exception in php-bitpay layer when currency is BTC [@SilverFire] 12 | - [c3ce408] 2017-11-27 Fixed CompletePurchaseResponse::getTransactionReference() [@SilverFire] 13 | - [46c14a1] 2017-10-17 CompletePurchaseRequest requires transactionId instead of transactionReference [@SilverFire] 14 | - [9750eb0] 2017-10-12 Return string from CompletePurchaseResponse::getAmount() [@SilverFire] 15 | - [abb9741] 2017-10-10 Flipped transactionId and transactionReference [@SilverFire] 16 | - [1b2d26a] 2017-10-04 Implemented request signing [@SilverFire] 17 | - [9667898] 2017-10-03 Basic implemetation [@SilverFire] 18 | - [0083c82] 2017-10-03 Updated composer.json [@SilverFire] 19 | - [6eb6c6a] 2017-10-03 first commit [@SilverFire] 20 | 21 | ## [Development started] - 2017-10-03 22 | 23 | ## [3.0.1] - 2022-03-08 24 | 25 | - [d38134c] 2022-03-08 Bump to 3.0.1 [@SilverFire] 26 | 27 | ## [dev] - 2022-03-08 28 | 29 | [@hiqsol]: https://github.com/hiqsol 30 | [sol@hiqdev.com]: https://github.com/hiqsol 31 | [@SilverFire]: https://github.com/SilverFire 32 | [d.naumenko.a@gmail.com]: https://github.com/SilverFire 33 | [@tafid]: https://github.com/tafid 34 | [andreyklochok@gmail.com]: https://github.com/tafid 35 | [@BladeRoot]: https://github.com/BladeRoot 36 | [bladeroot@gmail.com]: https://github.com/BladeRoot 37 | [6eb6c6a]: https://github.com/hiqdev/omnipay-bitpay/commit/6eb6c6a 38 | [Under development]: https://github.com/hiqdev/omnipay-bitpay/compare/0.1.0...HEAD 39 | [f267533]: https://github.com/hiqdev/omnipay-bitpay/commit/f267533 40 | [6ba8cd3]: https://github.com/hiqdev/omnipay-bitpay/commit/6ba8cd3 41 | [63a7da8]: https://github.com/hiqdev/omnipay-bitpay/commit/63a7da8 42 | [c3ce408]: https://github.com/hiqdev/omnipay-bitpay/commit/c3ce408 43 | [46c14a1]: https://github.com/hiqdev/omnipay-bitpay/commit/46c14a1 44 | [9750eb0]: https://github.com/hiqdev/omnipay-bitpay/commit/9750eb0 45 | [abb9741]: https://github.com/hiqdev/omnipay-bitpay/commit/abb9741 46 | [1b2d26a]: https://github.com/hiqdev/omnipay-bitpay/commit/1b2d26a 47 | [9667898]: https://github.com/hiqdev/omnipay-bitpay/commit/9667898 48 | [0083c82]: https://github.com/hiqdev/omnipay-bitpay/commit/0083c82 49 | [0.1.0]: https://github.com/hiqdev/omnipay-bitpay/releases/tag/0.1.0 50 | [1bb3a5a]: https://github.com/hiqdev/omnipay-bitpay/commit/1bb3a5a 51 | [3.0]: https://github.com/hiqdev/omnipay-bitpay/compare/0.1.0...3.0 52 | [3.0.0]: https://github.com/hiqdev/omnipay-bitpay/compare/0.1.0...3.0.0 53 | [d38134c]: https://github.com/hiqdev/omnipay-bitpay/commit/d38134c 54 | [Development started]: https://github.com/hiqdev/omnipay-bitpay/compare/3.0.1...Development started 55 | [3.0.1]: https://github.com/hiqdev/omnipay-bitpay/compare/dev...3.0.1 56 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | ./src/ 9 | 10 | 11 | 12 | 13 | ./tests/unit/ 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/Gateway.php: -------------------------------------------------------------------------------- 1 | false, 38 | ]; 39 | } 40 | 41 | public function getToken() 42 | { 43 | return $this->getParameter('token'); 44 | } 45 | 46 | public function setToken($value) 47 | { 48 | return $this->setParameter('token', $value); 49 | } 50 | 51 | /** 52 | * @param array $parameters 53 | * @return PurchaseRequest|\Omnipay\Common\Message\AbstractRequest 54 | */ 55 | public function purchase(array $parameters = []) 56 | { 57 | return $this->createRequest(PurchaseRequest::class, $parameters); 58 | } 59 | 60 | /** 61 | * @param array $parameters 62 | * @return CompletePurchaseRequest|\Omnipay\Common\Message\AbstractRequest 63 | */ 64 | public function completePurchase(array $parameters = []) 65 | { 66 | return $this->createRequest(CompletePurchaseRequest::class, $parameters); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/Message/AbstractRequest.php: -------------------------------------------------------------------------------- 1 | getParameter('token'); 27 | } 28 | 29 | public function setToken($value) 30 | { 31 | $this->setParameter('token', $value); 32 | } 33 | 34 | /** 35 | * @return Client 36 | * @throws BitPayException 37 | */ 38 | protected function getClient(): Client 39 | { 40 | return new Client($this->getToken(), $this->getTestMode() ? Env::Test : Env::Prod); 41 | } 42 | 43 | /** 44 | * @param array $data 45 | * @return array 46 | */ 47 | protected function buildPosData($data = []) 48 | { 49 | $array = array_merge([ 50 | 'd' => time(), 51 | ], $data); 52 | 53 | return [ 54 | 'posData' => $array, 55 | ]; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Message/CompletePurchaseRequest.php: -------------------------------------------------------------------------------- 1 | validate('transactionId', 'token'); 23 | 24 | return $this->httpRequest->request->all(); 25 | } 26 | 27 | public function setId($value) 28 | { 29 | $this->setTransactionId($value); 30 | } 31 | 32 | /** 33 | * Send the request with specified data. 34 | * 35 | * @param mixed $data The data to send 36 | * 37 | * @return CompletePurchaseResponse 38 | * @throws BitPayException 39 | * @throws InvoiceQueryException 40 | */ 41 | public function sendData($data) 42 | { 43 | $invoice = $this->getClient()->getInvoice($this->getTransactionId()); 44 | 45 | return $this->response = new CompletePurchaseResponse($this, $invoice); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Message/CompletePurchaseResponse.php: -------------------------------------------------------------------------------- 1 | checkPosData(); 41 | } 42 | 43 | /** 44 | * Whether the payment is successful. 45 | * @return boolean 46 | */ 47 | public function isSuccessful() 48 | { 49 | return $this->data->getStatus() === InvoiceStatus::Confirmed || $this->data->getStatus() === InvoiceStatus::Complete; 50 | } 51 | 52 | /** 53 | * {@inheritdoc} 54 | * @return string 55 | */ 56 | public function getTransactionId() 57 | { 58 | return $this->getPosData()['posData']['u']; 59 | } 60 | 61 | /** 62 | * {@inheritdoc} 63 | * @return string 64 | */ 65 | public function getTransactionReference() 66 | { 67 | return $this->data->getId(); 68 | } 69 | 70 | /** 71 | * Retruns the transatcion status. 72 | * @return string 73 | */ 74 | public function getTransactionStatus() 75 | { 76 | return $this->data->getStatus(); 77 | } 78 | 79 | /** 80 | * @return bool 81 | */ 82 | public function isStatusExceptional() 83 | { 84 | return in_array($this->getData()->getExceptionStatus(), ['paidPartial', 'paidOver']); 85 | } 86 | 87 | /** 88 | * {@inheritdoc} 89 | * @return string 90 | */ 91 | public function getAmount() 92 | { 93 | if ($this->isStatusExceptional()) { 94 | return (string)$this->getData()->getAmount(); 95 | } 96 | 97 | return (string)$this->data->getPrice(); 98 | } 99 | 100 | /** 101 | * @return string 102 | */ 103 | public function getRequestedAmount() 104 | { 105 | return $this->data->getPrice(); 106 | } 107 | 108 | /** 109 | * {@inheritdoc} 110 | * @return string 111 | */ 112 | public function getFee() 113 | { 114 | return ''; 115 | } 116 | 117 | /** 118 | * Returns the currency. 119 | * @return string 120 | */ 121 | public function getCurrency() 122 | { 123 | return strtoupper($this->data->getCurrency()); 124 | } 125 | 126 | /** 127 | * Returns the payer "name/email". 128 | * @return string 129 | */ 130 | public function getPayer() 131 | { 132 | $buyer = $this->data->getBuyer(); 133 | 134 | return $this->getTransactionReference() . ' ' . $buyer->getName() . ' / ' . $buyer->getEmail(); 135 | } 136 | 137 | /** 138 | * Returns the payment date. 139 | * @return string 140 | */ 141 | public function getTime() 142 | { 143 | $time = $this->data->getInvoiceTime(); 144 | 145 | if ($time instanceof \DateTime) { 146 | return $time->format('c'); 147 | } 148 | 149 | return date('c', $time / 1000); // time in ms 150 | } 151 | 152 | /** 153 | * @return array 154 | */ 155 | public function getPosData() 156 | { 157 | return @json_decode($this->data->getPosData(), true); 158 | } 159 | 160 | /** 161 | * @return Invoice 162 | */ 163 | public function getData() 164 | { 165 | return parent::getData(); 166 | } 167 | 168 | protected function checkPosData() 169 | { 170 | $data = $this->getPosData(); 171 | if ($data === null || !isset($data['posData'])) { 172 | throw new InvalidResponseException('Failed to decode JSON'); 173 | } 174 | } 175 | } 176 | -------------------------------------------------------------------------------- /src/Message/PurchaseRequest.php: -------------------------------------------------------------------------------- 1 | validate( 31 | 'token', 32 | 'transactionId', 'description', 33 | 'amount', 'currency', 34 | 'returnUrl', 'notifyUrl' 35 | ); 36 | 37 | return [ 38 | 'amount' => $this->getAmount(), 39 | 'currency_code' => strtoupper($this->getCurrency()), 40 | 'notifyUrl' => $this->getNotifyUrl(), 41 | 'return' => $this->getReturnUrl(), 42 | 'item_number' => $this->getTransactionId(), 43 | 'item_name' => $this->getDescription(), 44 | ]; 45 | } 46 | 47 | /** 48 | * Send the request with specified data. 49 | * 50 | * @param mixed $data The data to send 51 | * 52 | * @return PurchaseResponse 53 | * @throws InvalidRequestException 54 | * @throws \BitPaySDKLight\Exceptions\BitPayException 55 | * @throws \BitPaySDKLight\Exceptions\InvoiceCreationException 56 | */ 57 | public function sendData($data) 58 | { 59 | $bitpay = $this->getClient(); 60 | $basicInvoice = new Invoice((float)$this->getAmount(), $this->getCurrency()); 61 | $basicInvoice->setFullNotifications(true); 62 | $basicInvoice->setRedirectURL($this->getReturnUrl()); 63 | $basicInvoice->setNotificationURL($this->getNotifyUrl()); 64 | $basicInvoice->setPosData(json_encode($this->buildPosData())); 65 | $basicInvoice->setItemDesc($this->getDescription()); 66 | 67 | $invoice = $bitpay->createInvoice($basicInvoice); 68 | 69 | return $this->response = new PurchaseResponse($this, $invoice); 70 | } 71 | 72 | /** 73 | * @param array $data 74 | * 75 | * @return array 76 | * @throws InvalidRequestException 77 | */ 78 | protected function buildPosData($data = []) 79 | { 80 | return parent::buildPosData([ 81 | 'c' => $this->getDescription(), 82 | 's' => $this->getAmount(), 83 | 'u' => $this->getTransactionId(), 84 | ]); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/Message/PurchaseResponse.php: -------------------------------------------------------------------------------- 1 | data->getUrl(); 55 | } 56 | 57 | public function getRedirectMethod() 58 | { 59 | return 'GET'; 60 | } 61 | 62 | public function getRedirectData() 63 | { 64 | return [ 65 | 'id' => $this->data->getId(), 66 | ]; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /tests/_bootstrap.php: -------------------------------------------------------------------------------- 1 | gateway = new Gateway($this->getHttpClient(), $this->getHttpRequest()); 24 | $this->gateway->setToken($this->token); 25 | $this->gateway->setTestMode($this->testMode); 26 | } 27 | 28 | public function testGateway() 29 | { 30 | $this->assertSame($this->token, $this->gateway->getToken()); 31 | $this->assertSame($this->testMode, $this->gateway->getTestMode()); 32 | } 33 | 34 | public function testCompletePurchase() 35 | { 36 | $request = $this->gateway->completePurchase(['transactionId' => $this->transactionId]); 37 | 38 | $this->assertSame($this->testMode, $request->getTestMode()); 39 | $this->assertSame($this->transactionId, $request->getTransactionId()); 40 | } 41 | 42 | public function testPurchase() 43 | { 44 | $request = $this->gateway->purchase([ 45 | 'transactionId' => $this->transactionId, 46 | 'description' => $this->description, 47 | 'currency' => $this->currency, 48 | 'amount' => $this->amount, 49 | ]); 50 | 51 | $this->assertSame($this->transactionId, $request->gettransactionid()); 52 | $this->assertSame($this->description, $request->getDescription()); 53 | $this->assertSame($this->currency, $request->getCurrency()); 54 | $this->assertSame($this->amount, $request->getAmount()); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /tests/unit/Message/CompletePurchaseRequestTest.php: -------------------------------------------------------------------------------- 1 | $this->description, 26 | 'item_number' => $this->transactionId, 27 | 'amount' => $this->amount, 28 | 'currency' => $this->currency, 29 | 'test' => $this->testMode, 30 | ]); 31 | 32 | $this->request = new CompletePurchaseRequest($this->getHttpClient(), $httpRequest); 33 | $this->request->initialize([ 34 | 'token' => $this->token, 35 | 'testMode' => $this->testMode, 36 | 'transactionId' => $this->transactionId, 37 | ]); 38 | } 39 | 40 | public function testGetData() 41 | { 42 | $data = $this->request->getData(); 43 | 44 | $this->assertSame($this->description, $data['item_name']); 45 | $this->assertSame($this->transactionId, $data['item_number']); 46 | $this->assertSame($this->amount, $data['amount']); 47 | $this->assertSame($this->currency, $data['currency']); 48 | } 49 | 50 | public function testSendData() 51 | { 52 | $data = $this->request->getData(); 53 | $response = $this->request->sendData($data); 54 | $this->assertSame(CompletePurchaseResponse::class, get_class($response)); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /tests/unit/Message/CompletePurchaseResponseTest.php: -------------------------------------------------------------------------------- 1 | request = new CompletePurchaseRequest($this->getHttpClient(), $this->getHttpRequest()); 30 | 31 | $this->request->initialize([ 32 | 'token' => $this->token, 33 | 'testMode' => $this->testMode, 34 | 'transactionId' => $this->transactionId, 35 | ]); 36 | $this->request->setId($this->transactionId); 37 | } 38 | 39 | public function testSuccess() 40 | { 41 | $invoice = new Invoice($this->amount, $this->currency); 42 | $invoice->setFullNotifications(true); 43 | $invoice->setItemDesc($this->description); 44 | $invoice->setPosData(json_encode(['posData' => ['u' => $this->transactionId]])); 45 | $invoice->setStatus($this->status); 46 | $invoice->setId($this->transactionReference); 47 | $response = new CompletePurchaseResponse($this->request, $invoice); 48 | 49 | $this->assertTrue($response->isSuccessful()); 50 | $this->assertNull($response->getMessage()); 51 | $this->assertNull($response->getCode()); 52 | $this->assertSame($this->transactionId, $response->getTransactionId()); 53 | $this->assertSame($this->transactionReference, $response->getTransactionReference()); 54 | $this->assertSame('14.01', $response->getAmount()); 55 | $this->assertStringContainsString($this->transactionReference, $response->getPayer()); 56 | $this->assertSame($this->currency, $response->getCurrency()); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /tests/unit/Message/PurchaseRequestTest.php: -------------------------------------------------------------------------------- 1 | request = new PurchaseRequest($this->getHttpClient(), $this->getHttpRequest()); 26 | $this->request->initialize([ 27 | 'token' => $this->token, 28 | 'returnUrl' => $this->returnUrl, 29 | 'notifyUrl' => $this->notifyUrl, 30 | 'description' => $this->description, 31 | 'transactionId' => $this->transactionId, 32 | 'amount' => $this->amount, 33 | 'currency' => $this->currency, 34 | 'testMode' => $this->testMode, 35 | ]); 36 | } 37 | 38 | public function testGetData() 39 | { 40 | $data = $this->request->getData(); 41 | 42 | $this->assertSame($this->amount, $data['amount']); 43 | $this->assertSame($this->returnUrl, $data['return']); 44 | $this->assertSame($this->notifyUrl, $data['notifyUrl']); 45 | $this->assertSame($this->description, $data['item_name']); 46 | $this->assertSame($this->transactionId, $data['item_number']); 47 | } 48 | 49 | public function testSendData() 50 | { 51 | $data = $this->request->getData(); 52 | $response = $this->request->sendData($data); 53 | $this->assertSame(PurchaseResponse::class, get_class($response)); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /tests/unit/Message/PurchaseResponseTest.php: -------------------------------------------------------------------------------- 1 | request = new PurchaseRequest($this->getHttpClient(), $this->getHttpRequest()); 26 | $this->request->initialize([ 27 | 'token' => $this->token, 28 | 'returnUrl' => $this->returnUrl, 29 | 'notifyUrl' => $this->notifyUrl, 30 | 'description' => $this->description, 31 | 'transactionId' => $this->transactionId, 32 | 'amount' => $this->amount, 33 | 'price' => $this->amount, 34 | 'currency' => $this->currency, 35 | 'testMode' => $this->testMode, 36 | ]); 37 | } 38 | 39 | public function testSuccess() 40 | { 41 | $response = $this->request->send(); 42 | 43 | $this->assertFalse($response->isSuccessful()); 44 | $this->assertTrue($response->isRedirect()); 45 | $this->assertNull($response->getCode()); 46 | $this->assertNull($response->getMessage()); 47 | $this->assertStringStartsWith('https://test.bitpay.com/invoice', $response->getRedirectUrl()); 48 | /** @var Invoice $invoice */ 49 | $invoice = $response->getData(); 50 | $this->assertSame($this->currency, $invoice->getCurrency()); 51 | $this->assertSame($this->amount, (string)$invoice->getPrice()); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /version: -------------------------------------------------------------------------------- 1 | omnipay-bitpay 3.0.2 2022-03-08 20:23:51 +0200 02c4a421e360a828d7e042e141d47e58c32c546c 2 | --------------------------------------------------------------------------------