|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Apache OSL-2 |
|
5
|
|
|
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace SprykerEco\Yves\AmazonPay\Plugin\Provider; |
|
9
|
|
|
|
|
10
|
|
|
use Silex\Application; |
|
11
|
|
|
use Spryker\Shared\Kernel\Store; |
|
12
|
|
|
use Spryker\Yves\Application\Plugin\Provider\YvesControllerProvider; |
|
13
|
|
|
|
|
14
|
|
|
class AmazonPayControllerProvider extends YvesControllerProvider |
|
15
|
|
|
{ |
|
16
|
|
|
const CHECKOUT = 'amazonpay_checkout'; |
|
17
|
|
|
const ENDPOINT = 'amazonpay_endpoint'; |
|
18
|
|
|
const CONFIRM_PURCHASE = 'amazonpay_confirm_purchase'; |
|
19
|
|
|
const SUCCESS = 'amazonpay_success'; |
|
20
|
|
|
const PAYMENT_FAILED = 'amazonpay_payment_failed'; |
|
21
|
|
|
|
|
22
|
|
|
const SET_ORDER_REFERENCE = 'amazonpay_set_order_reference'; |
|
23
|
|
|
const UPDATE_SHIPMENT_METHOD = 'amazonpay_update_shipment_method'; |
|
24
|
|
|
const GET_SHIPMENT_METHODS = 'amazonpay_get_shipment_methods'; |
|
25
|
|
|
|
|
26
|
|
|
const PAY_BUTTON = 'amazonpay_paybutton'; |
|
27
|
|
|
const CHECKOUT_WIDGET = 'amazonpay_checkout_widget'; |
|
28
|
|
|
|
|
29
|
|
|
const BUNDLE_NAME = 'AmazonPay'; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param \Silex\Application $app |
|
33
|
|
|
* |
|
34
|
|
|
* @return void |
|
35
|
|
|
*/ |
|
36
|
|
|
protected function defineControllers(Application $app) |
|
37
|
|
|
{ |
|
38
|
|
|
$allowedLocalesPattern = $this->getAllowedLocalesPattern(); |
|
39
|
|
|
$this->createController('/{amazonpay}/checkout', static::CHECKOUT, static::BUNDLE_NAME, 'Payment', 'checkout') |
|
40
|
|
|
->assert('amazonpay', $allowedLocalesPattern . 'amazonpay|amazonpay') |
|
41
|
|
|
->value('amazonpay', 'amazonpay'); |
|
42
|
|
|
|
|
43
|
|
|
$this->createController('/{amazonpay}/confirm/purchase', static::CONFIRM_PURCHASE, static::BUNDLE_NAME, 'Payment', 'confirmPurchase') |
|
44
|
|
|
->assert('amazonpay', $allowedLocalesPattern . 'amazonpay|amazonpay') |
|
45
|
|
|
->value('amazonpay', 'amazonpay'); |
|
46
|
|
|
|
|
47
|
|
|
$this->createController('/{amazonpay}/success', static::SUCCESS, static::BUNDLE_NAME, 'Payment', 'success') |
|
48
|
|
|
->assert('amazonpay', $allowedLocalesPattern . 'amazonpay|amazonpay') |
|
49
|
|
|
->value('amazonpay', 'amazonpay'); |
|
50
|
|
|
|
|
51
|
|
|
$this->createController('/{amazonpay}/payment-failed', static::PAYMENT_FAILED, static::BUNDLE_NAME, 'Payment', 'paymentFailed') |
|
52
|
|
|
->assert('amazonpay', $allowedLocalesPattern . 'amazonpay|amazonpay') |
|
53
|
|
|
->value('amazonpay', 'amazonpay'); |
|
54
|
|
|
|
|
55
|
|
|
// ajax |
|
56
|
|
|
$this->createController('/amazonpay/set-order-reference', static::SET_ORDER_REFERENCE, static::BUNDLE_NAME, 'Payment', 'setOrderReference'); |
|
57
|
|
|
$this->createController('/amazonpay/update-shipment-method', static::UPDATE_SHIPMENT_METHOD, static::BUNDLE_NAME, 'Payment', 'updateShipmentMethod'); |
|
58
|
|
|
$this->createController('/{amazonpay}/get-shipment-methods', static::GET_SHIPMENT_METHODS, static::BUNDLE_NAME, 'Payment', 'getShipmentMethods') |
|
59
|
|
|
->assert('amazonpay', $allowedLocalesPattern . 'amazonpay|amazonpay') |
|
60
|
|
|
->value('amazonpay', 'amazonpay'); |
|
61
|
|
|
|
|
62
|
|
|
// widgets |
|
63
|
|
|
$this->createController('/{amazonpay}/paybutton', static::PAY_BUTTON, static::BUNDLE_NAME, 'Widget', 'payButton') |
|
64
|
|
|
->assert('amazonpay', $allowedLocalesPattern . 'amazonpay|amazonpay') |
|
65
|
|
|
->value('amazonpay', 'amazonpay'); |
|
66
|
|
|
|
|
67
|
|
|
$this->createController('/{amazonpay}/checkout-widget', static::CHECKOUT_WIDGET, static::BUNDLE_NAME, 'Widget', 'checkoutWidget') |
|
68
|
|
|
->assert('amazonpay', $allowedLocalesPattern . 'amazonpay|amazonpay') |
|
69
|
|
|
->value('amazonpay', 'amazonpay'); |
|
70
|
|
|
|
|
71
|
|
|
// endpoint |
|
72
|
|
|
$this->createController('/amazonpay/endpoint', static::ENDPOINT, static::BUNDLE_NAME, 'Payment', 'endpoint'); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @return string |
|
77
|
|
|
*/ |
|
78
|
|
|
public function getAllowedLocalesPattern() |
|
79
|
|
|
{ |
|
80
|
|
|
$systemLocales = Store::getInstance()->getLocales(); |
|
81
|
|
|
$implodedLocales = implode('|', array_keys($systemLocales)); |
|
82
|
|
|
|
|
83
|
|
|
return '(' . $implodedLocales . ')\/'; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|