Skip to content

Commit 56c9938

Browse files
Merge pull request #71 from xendit/TPI-3202/TPI-3217/remove-cc-installment
TPI-3217: Remove CC Installment
2 parents 02b04b7 + 6324a4b commit 56c9938

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+117
-1204
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# CHANGELOG
22

3+
## 2.7.0 (2021-02-01)
4+
5+
Improvements:
6+
7+
- Move Cards Payment Method to Invoice
8+
39
## 2.6.0 (2021-01-19)
410

511
Improvements:

Xendit/M2Invoice/Controller/Checkout/CCCallback.m22.php

-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ public function execute()
8181
$order->save();
8282
}
8383
$payment->setAdditionalInformation('token_id', $hostedPayment['token_id']);
84-
$payment->setAdditionalInformation('xendit_installment', $hostedPayment['installment']);
8584

8685
$this->processSuccessfulTransaction(
8786
$order,

Xendit/M2Invoice/Controller/Checkout/CCCallback.m23.php

-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ public function execute()
8585
$order->save();
8686
}
8787
$payment->setAdditionalInformation('token_id', $hostedPayment['token_id']);
88-
$payment->setAdditionalInformation('xendit_installment', $hostedPayment['installment']);
8988

9089
$this->processSuccessfulTransaction(
9190
$order,

Xendit/M2Invoice/Controller/Checkout/CCMultishipping.php

+2-56
Original file line numberDiff line numberDiff line change
@@ -63,41 +63,7 @@ public function execute()
6363
return $this->_redirect('multishipping/checkout/success');
6464
}
6565

66-
if ($method === 'cc') {
67-
$requestData = array(
68-
'token_id' => $tokenId,
69-
'card_cvn' => $cvn,
70-
'amount' => $transactionAmount,
71-
'external_id' => $this->getDataHelper()->getExternalId($rawOrderIds),
72-
'return_url' => $this->getDataHelper()->getThreeDSResultUrl($rawOrderIds, true)
73-
);
74-
75-
$charge = $this->requestCharge($requestData);
76-
77-
$chargeError = isset($charge['error_code']) ? $charge['error_code'] : null;
78-
if ($chargeError == 'EXTERNAL_ID_ALREADY_USED_ERROR') {
79-
$newRequestData = array_replace($requestData, array(
80-
'external_id' => $this->getDataHelper()->getExternalId($rawOrderIds, true)
81-
));
82-
$charge = $this->requestCharge($newRequestData);
83-
}
84-
85-
$chargeError = isset($charge['error_code']) ? $charge['error_code'] : null;
86-
if ($chargeError == 'AUTHENTICATION_ID_MISSING_ERROR') {
87-
return $this->handle3DSFlow($requestData, $payment, $orderIds, $orders);
88-
}
89-
90-
if ($chargeError !== null) {
91-
return $this->processFailedPayment($orderIds, $chargeError);
92-
}
93-
94-
if ($charge['status'] === 'CAPTURED') {
95-
return $this->processSuccessfulPayment($orders, $payment, $charge);
96-
} else {
97-
return $this->processFailedPayment($orderIds, $charge['failure_reason']);
98-
}
99-
}
100-
else if ($method === 'cchosted' || $method === 'cc_installment' || $method === 'cc_subscription') {
66+
if ($method === 'cc_subscription') {
10167
$requestData = array(
10268
'order_number' => $rawOrderIds,
10369
'amount' => $transactionAmount,
@@ -112,27 +78,7 @@ public function execute()
11278
$billingAddress = $orders[0]->getBillingAddress();
11379
$shippingAddress = $orders[0]->getShippingAddress();
11480

115-
if ($method === 'cc_installment') {
116-
$firstName = $billingAddress->getFirstname() ?: $shippingAddress->getFirstname();
117-
$country = $billingAddress->getCountryId() ?: $shippingAddress->getCountryId();
118-
$billingDetails = array(
119-
'given_names' => ($firstName ?: 'N/A'),
120-
'surname' => ($billingAddress->getLastname() ?: null),
121-
'email' => ($billingAddress->getEmail() ?: null),
122-
'phone_number' => ($billingAddress->getTelephone() ?: null),
123-
'address' => array(
124-
'country' => ($country ?: 'ID'),
125-
'street_line_1' => ($billingAddress->getStreetLine(1) ?: null),
126-
'street_line_2' => ($billingAddress->getStreetLine(2) ?: null),
127-
'city' => ($billingAddress->getCity() ?: null),
128-
'state' => ($billingAddress->getRegion() ?: null),
129-
'postal_code' => ($billingAddress->getPostcode() ?: null)
130-
)
131-
);
132-
133-
$requestData['is_installment'] = "true";
134-
$requestData['billing_details'] = json_encode($billingDetails, JSON_FORCE_OBJECT);
135-
} else if ($method === 'cc_subscription') {
81+
if ($method === 'cc_subscription') {
13682
$requestData['payment_type'] = 'CREDIT_CARD_SUBSCRIPTION';
13783
$requestData['is_subscription'] = "true";
13884
$requestData['subscription_callback_url'] = $this->getDataHelper()->getXenditSubscriptionCallbackUrl(true);

Xendit/M2Invoice/Controller/Checkout/Notification.m22.php

+28
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,18 @@ private function checkOrder($order, $isEwallet, $callbackPayload, $invoice, $cal
225225
$payment->setTransactionId($transactionId);
226226
$payment->addTransaction(\Magento\Sales\Model\Order\Payment\Transaction::TYPE_CAPTURE, null, true);
227227

228+
if (!empty($invoice['credit_card_charge_id'])) {
229+
$payment->setAdditionalInformation('xendit_charge_id', $invoice['credit_card_charge_id']);
230+
231+
if ($invoice['payment_channel'] === 'CARD_INSTALLMENT') {
232+
$getCharge = $this->getChargeCC($invoice['credit_card_charge_id']);
233+
234+
$payment->setAdditionalInformation('xendit_installment', $getCharge['installment']);
235+
}
236+
237+
$payment->save();
238+
}
239+
228240
if ($isEwallet) {
229241
$payment->setAdditionalInformation('xendit_ewallet_id', $transactionId);
230242
$payment->save();
@@ -268,6 +280,22 @@ private function checkOrder($order, $isEwallet, $callbackPayload, $invoice, $cal
268280
return $result;
269281
}
270282

283+
private function getChargeCC($chargeId)
284+
{
285+
$requestUrl = $this->dataHelper->getCheckoutUrl() . "/payment/xendit/credit-card/charges/$chargeId";
286+
$requestMethod = \Zend\Http\Request::METHOD_GET;
287+
288+
try {
289+
$charge = $this->apiHelper->request($requestUrl, $requestMethod);
290+
} catch (\Magento\Framework\Exception\LocalizedException $e) {
291+
throw new LocalizedException(
292+
new Phrase($e->getMessage())
293+
);
294+
}
295+
296+
return $charge;
297+
}
298+
271299
private function getXenditInvoice($invoiceId)
272300
{
273301
$invoiceUrl = $this->dataHelper->getCheckoutUrl() . "/payment/xendit/invoice/$invoiceId";

Xendit/M2Invoice/Controller/Checkout/Notification.m23.php

+28
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,18 @@ private function checkOrder($order, $isEwallet, $callbackPayload, $invoice, $cal
236236
$payment->setTransactionId($transactionId);
237237
$payment->addTransaction(\Magento\Sales\Model\Order\Payment\Transaction::TYPE_CAPTURE, null, true);
238238

239+
if (!empty($invoice['credit_card_charge_id'])) {
240+
$payment->setAdditionalInformation('xendit_charge_id', $invoice['credit_card_charge_id']);
241+
242+
if ($invoice['payment_channel'] === 'CARD_INSTALLMENT') {
243+
$getCharge = $this->getChargeCC($invoice['credit_card_charge_id']);
244+
245+
$payment->setAdditionalInformation('xendit_installment', $getCharge['installment']);
246+
}
247+
248+
$payment->save();
249+
}
250+
239251
if ($isEwallet) {
240252
$payment->setAdditionalInformation('xendit_ewallet_id', $transactionId);
241253
$payment->save();
@@ -279,6 +291,22 @@ private function checkOrder($order, $isEwallet, $callbackPayload, $invoice, $cal
279291
return $result;
280292
}
281293

294+
private function getChargeCC($chargeId)
295+
{
296+
$requestUrl = $this->dataHelper->getCheckoutUrl() . "/payment/xendit/credit-card/charges/$chargeId";
297+
$requestMethod = \Zend\Http\Request::METHOD_GET;
298+
299+
try {
300+
$charge = $this->apiHelper->request($requestUrl, $requestMethod);
301+
} catch (\Magento\Framework\Exception\LocalizedException $e) {
302+
throw new LocalizedException(
303+
new Phrase($e->getMessage())
304+
);
305+
}
306+
307+
return $charge;
308+
}
309+
282310
private function getXenditInvoice($invoiceId)
283311
{
284312
$invoiceUrl = $this->dataHelper->getCheckoutUrl() . "/payment/xendit/invoice/$invoiceId";

Xendit/M2Invoice/Controller/Checkout/ProcessHosted.php

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ public function execute()
3838
}
3939
$payment->setAdditionalInformation('token_id', $hostedPayment['token_id']);
4040
$payment->setAdditionalInformation('xendit_installment', $hostedPayment['installment']);
41-
4241
return $this->processSuccessfulTransaction(
4342
$order,
4443
$payment,

Xendit/M2Invoice/Controller/Payment/OverviewPost.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ public function execute()
124124
}
125125

126126
$params = implode("-", $ids);
127-
$xenditCCMethods = array('cc', 'cchosted', 'cc_installment', 'cc_subscription');
128-
if (in_array($xenditPaymentMethod, $xenditCCMethods)) {
127+
if ($xenditPaymentMethod === 'cc_subscription') {
129128
$redirect = $baseUrl . '/xendit/checkout/ccmultishipping?order_ids=' . $params . '&preferred_method=' . $xenditPaymentMethod;
130129
} else {
131130
$redirect = $baseUrl . '/xendit/checkout/invoicemultishipping?order_ids=' . $params.'&preferred_method='.$xenditPaymentMethod;

Xendit/M2Invoice/Helper/ApiRequest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ private function getHeaders($isPublicRequest, $preferredMethod = null, $customHe
8585
'Content-Type' => 'application/json',
8686
'x-plugin-name' => 'MAGENTO2',
8787
'user-agent' => 'Magento 2 Module',
88-
'x-plugin-version' => '2.6.0'
88+
'x-plugin-version' => '2.7.0'
8989
];
9090

9191
if ($preferredMethod !== null) {

Xendit/M2Invoice/Helper/Data.php

+1-8
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,6 @@ public function getEnvironment()
150150
return $this->m2Invoice->getEnvironment();
151151
}
152152

153-
public function getCardPaymentType()
154-
{
155-
return $this->m2Invoice->getCardPaymentType();
156-
}
157-
158153
public function getAllowedMethod()
159154
{
160155
return $this->m2Invoice->getAllowedMethod();
@@ -262,9 +257,7 @@ public function xenditPaymentMethod( $payment ){
262257

263258
//method name => frontend routing
264259
$listPayment = [
265-
"cc" => "cc",
266-
"cchosted" => "cchosted",
267-
"cc_installment" => "cc_installment",
260+
"cc" => "credit_card",
268261
"cc_subscription" => "cc_subscription",
269262
"bcava" => "bca",
270263
"bniva" => "bni",

Xendit/M2Invoice/Model/Adminhtml/Source/CardPaymentType.php

-25
This file was deleted.

Xendit/M2Invoice/Model/Adminhtml/Source/ChosenMethod.php

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public function toOptionArray($isMultiselect = false)
2626
['value' => 'mandiriva', 'label' => __('Bank Transfer Mandiri')],
2727
['value' => 'permatava', 'label' => __('Bank Transfer Permata')],
2828
['value' => 'cc', 'label' => __('Credit Card')],
29-
['value' => 'cc_installment', 'label' => __('Credit Card Installment')],
3029
['value' => 'cc_subscription', 'label' => __('Credit Card Subscription')],
3130
['value' => 'dana', 'label' => __('DANA')],
3231
['value' => 'indomaret', 'label' => __('Indomaret')],

0 commit comments

Comments
 (0)