Skip to content

Commit

Permalink
Added support EET, updated examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Frantisek Sichinger committed Feb 13, 2017
1 parent 02608e8 commit 35fd946
Show file tree
Hide file tree
Showing 8 changed files with 234 additions and 5 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
/bin/
!/bin/jenkins.sh
/var/
/phpunit.xml
/phpunit.xml
.idea
/vendor
composer.phar
composer.sh
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@

# Changelog

## v1.2.0

* Added [EET](https://help.gopay.com/cs/tema/propojeni-do-eet/jak-bude-fungovat-napojeni-gopay-do-eet) Support

## v1.1.1

* Fix `GoPay\Definition\Payment\BankSwiftCode::KOMERCNI_BANKA`
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ API | SDK method |
[Create pre-authorized payment](https://doc.gopay.com/en/#pre-authorized-payment) | `$gopay->createPayment(array $payment)` |
[Charge of pre-authorized payment](https://doc.gopay.com/en/#charge-of-pre-authorized-payment) | `$gopay->captureAuthorization($id)` |
[Cancellation of the pre-authorized payment](https://doc.gopay.com/en/#cancellation-of-the-pre-authorized-payment) | `$gopay->voidAuthorization($id)` |

### SDK response? Has my call succeed?

SDK returns wrapped API response. Every method returns
Expand Down Expand Up @@ -161,7 +160,8 @@ Type | Description |
[Token scope](/src/Definition/TokenScope.php) | Authorization scope for [OAuth2](https://doc.gopay.com/en/?php#oauth) |
[Payment enums](/src/Definition/Payment) | Enums for creating payment |
[Response enums](/src/Definition/Response) | Result of creating payment, executing payment operations |

[ItemType enums](/src/Definition/Payment/PaymentItemType.php) | Type of an item |
[VatRate enums](/src/Definition/Payment/VatRate.php) | VatRate of an item |
### Framework integration

* [Symfony2](/examples/symfony.md)
Expand Down
182 changes: 182 additions & 0 deletions examples/create-payment-eet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
<?php

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

use GoPay\Definition\Language;
use GoPay\Definition\Payment\Currency;
use GoPay\Definition\Payment\PaymentInstrument;
use GoPay\Definition\Payment\BankSwiftCode;
use GoPay\Definition\Payment\VatRate;
use GoPay\Definition\Payment\PaymentItemType;

$gopay = GoPay\payments([
'goid' => '8761908826',
'clientId' => '[email protected]',
'clientSecret' => 'VpnJVcTn',
'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' => '[email protected]',
'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
],
'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
]
]);

$response = $gopay->createPayment([
'payer' => [
'contact' => ['first_name' => 'Zbynek',
'last_name' => 'Zak',
'email' => '[email protected]',
'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
],
'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'
]
]);

$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
],
'additional_params' => [[
'name' => 'invoicenumber',
'value' => '2016001004'
]]
]);
10 changes: 10 additions & 0 deletions src/Definition/Payment/PaymentItemType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace GoPay\Definition\Payment;

class PaymentItemType
{
const ITEM = 'ITEM';
const DISCOUNT = 'DISCOUNT';
const DELIVERY = 'DELIVERY';
}
11 changes: 11 additions & 0 deletions src/Definition/Payment/VatRate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace GoPay\Definition\Payment;

class VatRate
{
const RATE_1 = 0;
const RATE_2 = 10;
const RATE_3 = 15;
const RATE_4 = 21;
}
2 changes: 1 addition & 1 deletion src/GoPay.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function buildUrl($urlPath)
{
static $urls = [
true => 'https://gate.gopay.cz/',
false => 'https://gw.sandbox.gopay.com/'
false => 'http://gopay-gw:8180/gp/'
];
return $urls[(bool) $this->getConfig('isProductionMode')] . $urlPath;
}
Expand Down
20 changes: 19 additions & 1 deletion src/Payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ 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 + [
Expand All @@ -30,11 +43,16 @@ public function getStatus($id)
return $this->api("/{$id}", GoPay::FORM);
}

public function refundPayment($id, $amount)
private function refundPayment($id, $amount)
{
return $this->api("/{$id}/refund", GoPay::FORM, ['amount' => $amount]);
}

private function refundPaymentEET($id, array $payment)
{
return $this->api("/{$id}/refund", GoPay::JSON, $payment);
}

public function createRecurrence($id, array $payment)
{
return $this->api("/{$id}/create-recurrence", GoPay::JSON, $payment);
Expand Down

0 comments on commit 35fd946

Please sign in to comment.