Skip to content

Commit b90fcb2

Browse files
Merge pull request #54 from xendit/feature/subscription
Feature/subscription
2 parents 31604b1 + 0f01f6e commit b90fcb2

39 files changed

+1208
-34
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,6 @@ fabric.properties
8787

8888
*.zip
8989

90-
telepresence.log
90+
telepresence.log
91+
92+
.DS_Store

CHANGELOG.md

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

3+
## 2.2.0 (2020-09-15)
4+
5+
Features:
6+
7+
- Add Credit Card Subscription payment method
8+
39
## 2.1.0 (2020-09-04)
410

511
Features:

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ To activate this feature, you need to follow this additional steps:
5050
- Done! The cron should already scheduling and running in the background.
5151

5252
## Supported Payment Method
53-
Currently this plugins support collecting payment through Xendit from these payment channels:
5453
- Credit and Debit Card
5554
- Mandiri VA
5655
- BNI VA
@@ -65,6 +64,9 @@ Since v1.3.0, online refund (full and partial) is supported for payment through
6564
## Multishipping Support
6665
Since v2.0.0, multishipping checkout is supported for all payment methods.
6766

67+
## Installment & Subscription
68+
Since v2.2.0, merchant can setup installment & subscription payment methods via credit card.
69+
6870
## Unit Testing
6971
To run unit test, run this command from you `MAGENTO_DIR`:
7072

Xendit/M2Invoice/Block/CustomView.php

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
namespace Xendit\M2Invoice\Block;
3+
4+
use Magento\Framework\Registry;
5+
use Magento\Framework\View\Element\Template;
6+
use Magento\Framework\View\Element\Template\Context;
7+
use Xendit\M2Invoice\Helper\Data;
8+
9+
class CustomView extends Template
10+
{
11+
private $dataHelper;
12+
13+
public function __construct(
14+
Context $context,
15+
Registry $registry,
16+
Data $dataHelper,
17+
array $data = []
18+
) {
19+
$this->registry = $registry;
20+
$this->dataHelper = $dataHelper;
21+
22+
parent::__construct($context, $data);
23+
}
24+
25+
/**
26+
* Retrieve current order model instance
27+
*
28+
* @return \Magento\Sales\Model\Order
29+
*/
30+
public function getOrder()
31+
{
32+
return $this->registry->registry('current_order');
33+
}
34+
35+
public function getPaymentMethod()
36+
{
37+
return $this->getOrder()->getPayment()->getMethodInstance()->getCode();
38+
}
39+
40+
public function getSubscriptionConfig()
41+
{
42+
$data = array();
43+
$data['card_subscription_interval'] = $this->dataHelper->getSubscriptionInterval();
44+
$data['card_subscription_interval_count'] = $this->dataHelper->getSubscriptionIntervalCount();
45+
46+
return $data;
47+
}
48+
49+
public function getInstallmentData()
50+
{
51+
return $this->getOrder()->getPayment()->getAdditionalInformation('xendit_installment');
52+
}
53+
}

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

+2-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ class CCCallback extends ProcessHosted
1111
public function execute()
1212
{
1313
try {
14-
$post = $this->getRequest()->getContent();
15-
$callbackToken = $this->getRequest()->getHeader('X-CALLBACK-TOKEN');
16-
$decodedPost = json_decode($post, true);
17-
1814
$orderIds = explode('-', $this->getRequest()->getParam('order_ids'));
1915

2016
$shouldRedirect = false;
@@ -52,6 +48,8 @@ public function execute()
5248
$order->setGrandTotal($order->getGrandTotal() + $order->getDiscountAmount());
5349
$order->save();
5450
}
51+
$payment->setAdditionalInformation('token_id', $hostedPayment['token_id']);
52+
$payment->setAdditionalInformation('xendit_installment', $hostedPayment['installment']);
5553

5654
$this->processSuccessfulTransaction(
5755
$order,

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

+2-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ class CCCallback extends ProcessHosted implements CsrfAwareActionInterface
1515
public function execute()
1616
{
1717
try {
18-
$post = $this->getRequest()->getContent();
19-
$callbackToken = $this->getRequest()->getHeader('X-CALLBACK-TOKEN');
20-
$decodedPost = json_decode($post, true);
21-
2218
$orderIds = explode('-', $this->getRequest()->getParam('order_ids'));
2319

2420
$shouldRedirect = false;
@@ -55,6 +51,8 @@ public function execute()
5551
$order->setGrandTotal($order->getGrandTotal() + $order->getDiscountAmount());
5652
$order->save();
5753
}
54+
$payment->setAdditionalInformation('token_id', $hostedPayment['token_id']);
55+
$payment->setAdditionalInformation('xendit_installment', $hostedPayment['installment']);
5856

5957
$this->processSuccessfulTransaction(
6058
$order,

Xendit/M2Invoice/Controller/Checkout/CCMultishipping.php

+24-5
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55
use Magento\Framework\Controller\ResultFactory;
66
use Magento\Sales\Model\Order;
77
use Xendit\M2Invoice\Enum\LogDNALevel;
8+
use Magento\Framework\UrlInterface;
89

910
class CCMultishipping extends AbstractAction
1011
{
1112
public function execute()
1213
{
14+
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
15+
$customerSession = $objectManager->get('Magento\Customer\Model\Session');
16+
1317
try {
1418
$rawOrderIds = $this->getRequest()->getParam('order_ids');
1519
$method = $this->getRequest()->getParam('preferred_method');
@@ -19,6 +23,12 @@ public function execute()
1923
$tokenId = '';
2024
$orders = [];
2125

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+
2232
foreach ($orderIds as $key => $value) {
2333
$order = $this->getOrderFactory()->create();
2434
$order ->load($value);
@@ -76,7 +86,7 @@ public function execute()
7686
return $this->processFailedPayment($orderIds, $charge['failure_reason']);
7787
}
7888
}
79-
else if ($method === 'cchosted' || $method === 'cc_installment') {
89+
else if ($method === 'cchosted' || $method === 'cc_installment' || $method === 'cc_subscription') {
8090
$requestData = array(
8191
'order_number' => $rawOrderIds,
8292
'amount' => $transactionAmount,
@@ -88,10 +98,10 @@ public function execute()
8898
'platform_callback_url' => $this->_url->getUrl('xendit/checkout/cccallback') . '?order_ids=' . $rawOrderIds
8999
);
90100

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();
94103

104+
if ($method === 'cc_installment') {
95105
$firstName = $billingAddress->getFirstname() ?: $shippingAddress->getFirstname();
96106
$country = $billingAddress->getCountryId() ?: $shippingAddress->getCountryId();
97107
$billingDetails = array(
@@ -111,6 +121,15 @@ public function execute()
111121

112122
$requestData['is_installment'] = "true";
113123
$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);
114133
}
115134

116135
$hostedPayment = $this->requestHostedPayment($requestData);
@@ -126,7 +145,7 @@ public function execute()
126145
$this->addCCHostedData($orders, $hostedPayment);
127146

128147
// 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";
130149
$resultRedirect = $this->getRedirectFactory()->create();
131150
$resultRedirect->setUrl($redirect);
132151

Xendit/M2Invoice/Controller/Checkout/ProcessHosted.php

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public function execute()
3636
$order->setGrandTotal($order->getGrandTotal() + $order->getDiscountAmount());
3737
$order->save();
3838
}
39+
$payment->setAdditionalInformation('token_id', $hostedPayment['token_id']);
40+
$payment->setAdditionalInformation('xendit_installment', $hostedPayment['installment']);
3941

4042
return $this->processSuccessfulTransaction(
4143
$order,

0 commit comments

Comments
 (0)