From 6e2dadd44ab0fd66115ed18721c3ae8080b3d6a8 Mon Sep 17 00:00:00 2001 From: Martin Sojka Date: Tue, 21 Feb 2017 11:10:32 +0100 Subject: [PATCH 1/5] Examples - format and clarify examples --- examples/create-payment-eet.php | 282 ++++++++++++++------------------ 1 file changed, 123 insertions(+), 159 deletions(-) diff --git a/examples/create-payment-eet.php b/examples/create-payment-eet.php index 0a9099e..9616e9f 100644 --- a/examples/create-payment-eet.php +++ b/examples/create-payment-eet.php @@ -10,173 +10,137 @@ use GoPay\Definition\Payment\PaymentItemType; $gopay = GoPay\payments([ - 'goid' => '8761908826', - 'clientId' => 'app@musicshop.cz', - 'clientSecret' => 'VpnJVcTn', - 'isProductionMode' => false, - 'language' => Language::CZECH + 'goid' => 'my goid', + 'clientId' => 'client_id@example.com', + 'clientSecret' => 'my secret', + 'isProductionMode' => false, + 'language' => Language::CZECH ]); -$response = $gopay->createPayment([ - 'payer' => [ - 'default_payment_instrument' => PaymentInstrument::BANK_ACCOUNT, - 'allowed_payment_instruments' => [PaymentInstrument::BANK_ACCOUNT], - 'default_swift' => BankSwiftCode::FIO_BANKA,'FIOBCZPP', - 'allowed_swifts' => [BankSwiftCode::FIO_BANKA, BankSwiftCode::MBANK], - 'contact' => ['first_name' => 'Zbynek', - 'last_name' => 'Zak', - 'email' => 'test@test.cz', - 'phone_number' => '+420777456123', - 'city' => 'C.Budejovice', - 'street' => 'Plana 67', - 'postal_code' => '373 01', - 'country_code' => 'CZE' - ] +// Create standard payment +$payment = [ + 'payer' => [ + 'default_payment_instrument' => PaymentInstrument::BANK_ACCOUNT, + 'allowed_payment_instruments' => [PaymentInstrument::BANK_ACCOUNT], + 'default_swift' => BankSwiftCode::FIO_BANKA, 'FIOBCZPP', + 'allowed_swifts' => [BankSwiftCode::FIO_BANKA, BankSwiftCode::MBANK], + 'contact' => [ + 'first_name' => 'Zbynek', + 'last_name' => 'Zak', + 'email' => 'test@test.cz', + 'phone_number' => '+420777456123', + 'city' => 'C.Budejovice', + 'street' => 'Plana 67', + 'postal_code' => '373 01', + 'country_code' => 'CZE' ], - 'target' => [ - 'type' => 'ACCOUNT', - 'goid' => '8123456789' + ], + 'target' => ['type' => 'ACCOUNT', 'goid' => '8123456789'], + 'amount' => 1000, + 'currency' => Currency::CZECH_CROWNS, + 'order_number' => '001', + 'order_description' => 'obuv', + 'items' => [ + [ + 'type' => 'ITEM', + 'name' => 'obuv', + 'product_url' => 'https://www.eshop.cz/boty/lodicky', + 'ean' => 1234567890123, + 'amount' => 119990, + 'count' => 1, + 'vat_rate' => VatRate::RATE_4 ], - 'amount' => '1000', - 'currency' => Currency::CZECH_CROWNS, - 'order_number' => '001', - 'order_description' => 'obuv', - 'items' => [[ - 'type' => 'ITEM', - 'name' => 'obuv', - 'product_url' => 'https://www.eshop.cz/boty/lodicky', - 'ean' => 1234567890123, - 'amount' => 119990, - 'count' => 1, - 'vat_rate' => VatRate::RATE_4 + [ + 'type' => PaymentItemType::ITEM, + 'name' => 'oprava podpatku', + 'product_url' => 'https://www.eshop.cz/boty/opravy', + 'ean' => 1234567890189, + 'amount' => 19960, + 'count' => 1, + 'vat_rate' => VatRate::RATE_3 ], - [ - 'type' => PaymentItemType::ITEM, - 'name' => 'oprava podpatku', - 'product_url' => 'https://www.eshop.cz/boty/opravy', - 'ean' => 1234567890189, - 'amount' => 19960, - 'count' => 1, - 'vat_rate' => VatRate::RATE_3 - ]], - 'eet' => [ - 'celk_trzba' => 139950, - 'zakl_dan1' => 99165, - 'dan1' => 20825, - 'zakl_dan2' => 17357, - 'dan2' => 2604, - 'mena' => Currency::CZECH_CROWNS - ], - 'additional_params' => [['name' => 'invoicenumber', - 'value' => '2015001003' - ]], - 'callback' => [ - 'return_url' => 'https=>//www.eshop.cz/return', - 'notification_url' => 'https=>//www.eshop.cz/notify' - ], - 'lang' => Language::CZECH -]); + ], + 'additional_params' => [ + ['name' => 'invoicenumber', 'value' => '2015001003'], + ], + 'callback' => [ + 'return_url' => 'https://www.eshop.cz/return', + 'notification_url' => 'https://www.eshop.cz/notify' + ], + 'lang' => Language::CZECH +]; -$response = $gopay->refundPayment(3000006620, [ - 'amount' => 119990, - 'items' => [ - [ - 'type' => PaymentItemType::ITEM, - 'name' => 'lodicky', - 'product_url' => 'https://www.eshop.cz/boty/damske/lodicky-cervene', - 'ean' => 1234567890123, - 'amount' => -119990, - 'count' => 1, - 'vat_rate' => VatRate::RATE_4 - ]], - 'eet' => [ - 'celk_trzba' => -119990, - 'zakl_dan1' => -99165, - 'dan1' => -20825, - 'dan2' => -2604 - ] -]); +$eet = [ + 'eet' => [ + 'celk_trzba' => 139950, + 'zakl_dan1' => 99165, + 'dan1' => 20825, + 'zakl_dan2' => 17357, + 'dan2' => 2604, + 'mena' => Currency::CZECH_CROWNS + ] +]; -$response = $gopay->createPayment([ - 'payer' => [ - 'contact' => ['first_name' => 'Zbynek', - 'last_name' => 'Zak', - 'email' => 'test@test.cz', - 'phone_number' => '+420777456123', - 'city' => 'C.Budejovice', - 'street' => 'Plana 67', - 'postal_code' => '373 01', - 'country_code' => 'CZE' - ] - ], - 'target' => ['type' => 'ACCOUNT', - 'goid' => '8123456789' - ], - 'amount' => '1000', - 'currency' => Currency::CZECH_CROWNS, - 'order_number' => '001', - 'order_description' => 'obuv', - 'items' => [[ - 'type' => 'ITEM', - 'name' => 'obuv', - 'product_url' => 'https=>//www.eshop.cz/boty/lodicky', - 'ean' => 1234567890123, - 'amount' => 119990, - 'count' => 1, - 'vat_rate' => VatRate::RATE_4 - ], - [ - 'type' => PaymentItemType::ITEM, - 'name' => 'oprava podpatku', - 'product_url' => 'https=>//www.eshop.cz/boty/opravy', - 'ean' => 1234567890189, - 'amount' => 19960, - 'count' => 1, - 'vat_rate' => VatRate::RATE_3 - ]], - 'eet' => [ - 'celk_trzba' => 139950, - 'zakl_dan1' => 99165, - 'dan1' => 20825, - 'zakl_dan2' => 17357, - 'dan2' => 2604, - 'mena' => Currency::CZECH_CROWNS +$paymentWithEet = $payment + $eet; +$createPaymentResponse = $gopay->createPayment($paymentWithEet); + +// Refund payment +$refundPaymentResponse = $gopay->refundPayment(3000006620, [ + 'amount' => 119990, + 'items' => [ + [ + 'type' => PaymentItemType::ITEM, + 'name' => 'lodicky', + 'product_url' => 'https://www.eshop.cz/boty/damske/lodicky-cervene', + 'ean' => 1234567890123, + 'amount' => -119990, + 'count' => 1, + 'vat_rate' => VatRate::RATE_4 ], - 'recurrence' => ['recurrence_cycle' => 'DAY', - 'recurrence_period' => '7', - 'recurrence_date_to' => '2015-12-31'], - 'additional_params' => [['name' => 'invoicenumber', - 'value' => '2015001003' - ]], - 'callback' => [ - 'return_url' => 'http=>//www.eshop.cz/return', - 'notification_url' => 'http=>//www.eshop.cz/notify' - ] + ], + 'eet' => [ + 'celk_trzba' => -119990, + 'zakl_dan1' => -99165, + 'dan1' => -20825, + 'dan2' => -2604 + ], ]); -$response = $gopay->createRecurrence(3000006620, [ - 'amount' => '500', - 'currency' => Currency::CZECH_CROWNS, - 'order_number' => 'Nakup', - 'order_description' => '2016-0001254', - 'items' => [ - [ - 'type' => PaymentItemType::ITEM, - 'name' => 'lodicky', - 'product_url' => 'https://www.eshop.cz/boty//lodicky', - 'ean' => 1234567890123, - 'amount' => 119990, - 'count' => 1, - 'vat_rate' => VatRate::RATE_4 - ]], - 'eet' => [ - 'celk_trzba' => 119990, - 'zakl_dan1' => 99165, - 'dan1' => 20825, - 'mena' => Currency::CZECH_CROWNS +// Create reccurent payment +$recurrence = [ + 'recurrence' => [ + 'recurrence_cycle' => 'DAY', + 'recurrence_period' => '7', + 'recurrence_date_to' => '2015-12-31' + ] +]; + +$reccurentPaymentResponse = $gopay->createPayment($paymentWithEet + $recurrence); + +// After reccurent payment is created, you can withold money +$reccurenceResponse = $gopay->createRecurrence(3000006620, [ + 'amount' => '500', + 'currency' => Currency::CZECH_CROWNS, + 'order_number' => 'Nakup', + 'order_description' => '2016-0001254', + 'items' => [ + [ + 'type' => PaymentItemType::ITEM, + 'name' => 'lodicky', + 'product_url' => 'https://www.eshop.cz/boty//lodicky', + 'ean' => 1234567890123, + 'amount' => 119990, + 'count' => 1, + 'vat_rate' => VatRate::RATE_4 ], - 'additional_params' => [[ - 'name' => 'invoicenumber', - 'value' => '2016001004' - ]] -]); \ No newline at end of file + ], + 'eet' => [ + 'celk_trzba' => 119990, + 'zakl_dan1' => 99165, + 'dan1' => 20825, + 'mena' => Currency::CZECH_CROWNS + ], + 'additional_params' => [ + ['name' => 'invoicenumber', 'value' => '2016001004'], + ] +]); From aa316f629c5f5027b792354c09421d1377493800 Mon Sep 17 00:00:00 2001 From: Martin Sojka Date: Tue, 21 Feb 2017 11:11:12 +0100 Subject: [PATCH 2/5] Gitignore - fix ignore rules --- .gitignore | 10 +++++----- examples/{create-payment-eet.php => eet-payments.php} | 0 2 files changed, 5 insertions(+), 5 deletions(-) rename examples/{create-payment-eet.php => eet-payments.php} (100%) diff --git a/.gitignore b/.gitignore index 392119b..19c7d07 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,10 @@ -/vendor/ +# IDE /nbproject/ +.idea + +# APP +/vendor/ /bin/ !/bin/jenkins.sh /var/ /phpunit.xml -.idea -/vendor -composer.phar -composer.sh diff --git a/examples/create-payment-eet.php b/examples/eet-payments.php similarity index 100% rename from examples/create-payment-eet.php rename to examples/eet-payments.php From f46455fb8f25ce0ed03bce84cc94704dc937f094 Mon Sep 17 00:00:00 2001 From: Martin Sojka Date: Tue, 21 Feb 2017 11:25:33 +0100 Subject: [PATCH 3/5] Fix - replace internal api uri with public one --- src/GoPay.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GoPay.php b/src/GoPay.php index 295c016..be0ea65 100644 --- a/src/GoPay.php +++ b/src/GoPay.php @@ -42,7 +42,7 @@ public function buildUrl($urlPath) { static $urls = [ true => 'https://gate.gopay.cz/', - false => 'http://gopay-gw:8180/gp/' + false => 'https://gw.sandbox.gopay.com/' ]; return $urls[(bool) $this->getConfig('isProductionMode')] . $urlPath; } From dcc78d7aa6aca4451b2f4c759bf8f5f5cf705f49 Mon Sep 17 00:00:00 2001 From: Martin Sojka Date: Tue, 21 Feb 2017 11:25:59 +0100 Subject: [PATCH 4/5] Checkstyle - fix file endings --- src/Definition/Payment/PaymentItemType.php | 2 +- src/Definition/Payment/VatRate.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Definition/Payment/PaymentItemType.php b/src/Definition/Payment/PaymentItemType.php index 3f2f8ed..0f54c2d 100644 --- a/src/Definition/Payment/PaymentItemType.php +++ b/src/Definition/Payment/PaymentItemType.php @@ -7,4 +7,4 @@ class PaymentItemType const ITEM = 'ITEM'; const DISCOUNT = 'DISCOUNT'; const DELIVERY = 'DELIVERY'; -} \ No newline at end of file +} diff --git a/src/Definition/Payment/VatRate.php b/src/Definition/Payment/VatRate.php index 6bdaf2a..446a4c9 100644 --- a/src/Definition/Payment/VatRate.php +++ b/src/Definition/Payment/VatRate.php @@ -8,4 +8,4 @@ class VatRate const RATE_2 = 10; const RATE_3 = 15; const RATE_4 = 21; -} \ No newline at end of file +} From 5f9caa0517226bca3869360e95c02b6b75d9b7cb Mon Sep 17 00:00:00 2001 From: Martin Sojka Date: Tue, 21 Feb 2017 11:26:50 +0100 Subject: [PATCH 5/5] Payements - refactor refund payment --- src/Payments.php | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/Payments.php b/src/Payments.php index 60926a3..6979a4c 100644 --- a/src/Payments.php +++ b/src/Payments.php @@ -13,19 +13,6 @@ public function __construct(GoPay $g, Auth $a) $this->auth = $a; } - public function __call($name, $arguments) - { - if($name == 'refundPayment') { - if (count($arguments) > 1) { - if (is_integer($arguments[1])) { - return call_user_func_array(array($this,'refundPayment'), $arguments); - } else { - return call_user_func_array(array($this,'refundPaymentEET'), $arguments); - } - } - } - } - public function createPayment(array $rawPayment) { $payment = $rawPayment + [ @@ -43,14 +30,18 @@ public function getStatus($id) return $this->api("/{$id}", GoPay::FORM); } - private function refundPayment($id, $amount) + /** @see refundPaymentEET */ + public function refundPayment($id, $data) { - return $this->api("/{$id}/refund", GoPay::FORM, ['amount' => $amount]); + if (is_array($data)) { + return $this->refundPaymentEET($id, $data); + } + return $this->api("/{$id}/refund", GoPay::FORM, ['amount' => $data]); } - private function refundPaymentEET($id, array $payment) + public function refundPaymentEET($id, array $paymentData) { - return $this->api("/{$id}/refund", GoPay::JSON, $payment); + return $this->api("/{$id}/refund", GoPay::JSON, $paymentData); } public function createRecurrence($id, array $payment)