5
5
use Magento \Framework \Controller \ResultFactory ;
6
6
use Magento \Sales \Model \Order ;
7
7
use Xendit \M2Invoice \Enum \LogDNALevel ;
8
+ use Magento \Framework \UrlInterface ;
8
9
9
10
class CCMultishipping extends AbstractAction
10
11
{
11
12
public function execute ()
12
13
{
14
+ $ objectManager = \Magento \Framework \App \ObjectManager::getInstance ();
15
+ $ customerSession = $ objectManager ->get ('Magento\Customer\Model\Session ' );
16
+
13
17
try {
14
18
$ rawOrderIds = $ this ->getRequest ()->getParam ('order_ids ' );
15
19
$ method = $ this ->getRequest ()->getParam ('preferred_method ' );
@@ -19,6 +23,12 @@ public function execute()
19
23
$ tokenId = '' ;
20
24
$ orders = [];
21
25
26
+ if ($ method === 'cc_subscription ' && !$ customerSession ->isLoggedIn ()) {
27
+ $ message = 'You must logged in to use this payment method ' ;
28
+ $ this ->getLogger ()->info ($ message );
29
+ return $ this ->redirectToCart ($ message );
30
+ }
31
+
22
32
foreach ($ orderIds as $ key => $ value ) {
23
33
$ order = $ this ->getOrderFactory ()->create ();
24
34
$ order ->load ($ value );
@@ -76,7 +86,7 @@ public function execute()
76
86
return $ this ->processFailedPayment ($ orderIds , $ charge ['failure_reason ' ]);
77
87
}
78
88
}
79
- else if ($ method === 'cchosted ' || $ method === 'cc_installment ' ) {
89
+ else if ($ method === 'cchosted ' || $ method === 'cc_installment ' || $ method === ' cc_subscription ' ) {
80
90
$ requestData = array (
81
91
'order_number ' => $ rawOrderIds ,
82
92
'amount ' => $ transactionAmount ,
@@ -88,10 +98,10 @@ public function execute()
88
98
'platform_callback_url ' => $ this ->_url ->getUrl ('xendit/checkout/cccallback ' ) . '?order_ids= ' . $ rawOrderIds
89
99
);
90
100
91
- if ($ method === 'cc_installment ' ) {
92
- $ billingAddress = $ orders [0 ]->getBillingAddress ();
93
- $ shippingAddress = $ orders [0 ]->getShippingAddress ();
101
+ $ billingAddress = $ orders [0 ]->getBillingAddress ();
102
+ $ shippingAddress = $ orders [0 ]->getShippingAddress ();
94
103
104
+ if ($ method === 'cc_installment ' ) {
95
105
$ firstName = $ billingAddress ->getFirstname () ?: $ shippingAddress ->getFirstname ();
96
106
$ country = $ billingAddress ->getCountryId () ?: $ shippingAddress ->getCountryId ();
97
107
$ billingDetails = array (
@@ -111,6 +121,15 @@ public function execute()
111
121
112
122
$ requestData ['is_installment ' ] = "true " ;
113
123
$ requestData ['billing_details ' ] = json_encode ($ billingDetails , JSON_FORCE_OBJECT );
124
+ } else if ($ method === 'cc_subscription ' ) {
125
+ $ requestData ['payment_type ' ] = 'CREDIT_CARD_SUBSCRIPTION ' ;
126
+ $ requestData ['is_subscription ' ] = "true " ;
127
+ $ requestData ['subscription_callback_url ' ] = $ this ->getDataHelper ()->getXenditSubscriptionCallbackUrl (true );
128
+ $ requestData ['payer_email ' ] = $ billingAddress ->getEmail ();
129
+ $ requestData ['subscription_option ' ] = json_encode (array (
130
+ 'interval ' => $ this ->getDataHelper ()->getSubscriptionInterval (),
131
+ 'interval_count ' => $ this ->getDataHelper ()->getSubscriptionIntervalCount ()
132
+ ), JSON_FORCE_OBJECT );
114
133
}
115
134
116
135
$ hostedPayment = $ this ->requestHostedPayment ($ requestData );
@@ -126,7 +145,7 @@ public function execute()
126
145
$ this ->addCCHostedData ($ orders , $ hostedPayment );
127
146
128
147
// redirect to hosted payment page
129
- $ redirect = " https://tpi-ui.xendit.co /hosted-payments/$ hostedPaymentId?hp_token= $ hostedPaymentToken " ;
148
+ $ redirect = $ this -> getDataHelper ()-> getUiUrl () . " /hosted-payments/ $ hostedPaymentId?hp_token= $ hostedPaymentToken " ;
130
149
$ resultRedirect = $ this ->getRedirectFactory ()->create ();
131
150
$ resultRedirect ->setUrl ($ redirect );
132
151
0 commit comments