Skip to content

Commit

Permalink
Merge pull request #61 from xendit/TPI-2020/dana
Browse files Browse the repository at this point in the history
Add DANA payment method
  • Loading branch information
candrasaputra authored Nov 5, 2020
2 parents ce2f330 + 4397042 commit f4b8367
Show file tree
Hide file tree
Showing 33 changed files with 363 additions and 50 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# CHANGELOG

## 2.4.0 (2020-11-02)

Features:

- Add DANA payment method
- Add Indomaret payment method

## 2.3.0 (2020-10-06)

Features:
Expand Down
3 changes: 2 additions & 1 deletion Xendit/M2Invoice/Controller/Checkout/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ private function getApiRequestData($order)
'preferred_method' => $preferredMethod,
'should_send_email' => $this->getDataHelper()->getSendInvoiceEmail() ? "true" : "false",
'platform_callback_url' => $this->getXenditCallbackUrl(),
'client_type' => 'INTEGRATION'
'client_type' => 'INTEGRATION',
'payment_methods' => json_encode([strtoupper($preferredMethod)])
];

return $requestData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public function execute()
'preferred_method' => $preferredMethod,
'should_send_email' => $this->getDataHelper()->getSendInvoiceEmail() ? "true" : "false",
'platform_callback_url' => $this->getXenditCallbackUrl(),
'client_type' => 'INTEGRATION'
'client_type' => 'INTEGRATION',
'payment_methods' => json_encode([strtoupper($preferredMethod)])
];

$invoice = $this->createInvoice($requestData);
Expand Down
15 changes: 5 additions & 10 deletions Xendit/M2Invoice/Controller/Checkout/Notification.m22.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function handleInvoiceCallback($callbackPayload) {

$invoice = $this->getXenditInvoice($transactionId);

if( $isMultishipping ) {
if ($isMultishipping) {
foreach ($orderIds as $key => $value) {
$order = $this->orderFactory->create();
$order->load($value);
Expand Down Expand Up @@ -237,13 +237,12 @@ private function checkOrder($order, $isEwallet, $callbackPayload, $invoice, $cal
$this->getCheckoutHelper()->restoreQuote(); //restore cart
}

if ($isEwallet) {
$order ->setState($orderState)
->setStatus($orderState);
$order ->save();
$order ->addStatusHistoryComment("Xendit payment " . strtolower($paymentStatus) . ". Transaction ID: $transactionId")
->save();

if ($isEwallet) {
$payment = $order->getPayment();
$payment->setAdditionalInformation('xendit_ewallet_failure_code', $failureCode);
$payment->setAdditionalInformation('xendit_ewallet_failure_code', $callbackPayload['failure_code']);
$payment->save();
}

Expand Down Expand Up @@ -286,10 +285,6 @@ private function getEwalletStatus($ewalletType, $externalId)
);
}

if ($ewalletType == 'DANA') {
$response['status'] = $response['payment_status'];
}

$statusList = array("COMPLETED", "PAID", "SUCCESS_COMPLETED"); //OVO, DANA, LINKAJA
if (in_array($response['status'], $statusList)) {
return "COMPLETED";
Expand Down
15 changes: 5 additions & 10 deletions Xendit/M2Invoice/Controller/Checkout/Notification.m23.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function handleInvoiceCallback($callbackPayload) {

$invoice = $this->getXenditInvoice($transactionId);

if( $isMultishipping ) {
if ($isMultishipping) {
foreach ($orderIds as $key => $value) {
$order = $this->orderFactory->create();
$order->load($value);
Expand Down Expand Up @@ -248,13 +248,12 @@ private function checkOrder($order, $isEwallet, $callbackPayload, $invoice, $cal
$this->getCheckoutHelper()->restoreQuote(); //restore cart
}

$order ->addStatusHistoryComment("Xendit payment " . strtolower($paymentStatus) . ". Transaction ID: $transactionId")
->save();

if ($isEwallet) {
$order ->setState($orderState)
->setStatus($orderState);
$order ->save();

$payment = $order->getPayment();
$payment->setAdditionalInformation('xendit_ewallet_failure_code', $failureCode);
$payment->setAdditionalInformation('xendit_ewallet_failure_code', $callbackPayload['failure_code']);
$payment->save();
}

Expand Down Expand Up @@ -297,10 +296,6 @@ private function getEwalletStatus($ewalletType, $externalId)
);
}

if ($ewalletType == 'DANA') {
$response['status'] = $response['payment_status'];
}

$statusList = array("COMPLETED", "PAID", "SUCCESS_COMPLETED"); //OVO, DANA, LINKAJA
if (in_array($response['status'], $statusList)) {
return "COMPLETED";
Expand Down
4 changes: 0 additions & 4 deletions Xendit/M2Invoice/Controller/Checkout/Redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,6 @@ private function getEwalletStatus($ewalletType, $externalId)
);
}

if ($ewalletType == 'DANA') {
$response['status'] = $response['payment_status'];
}

$statusList = array("COMPLETED", "PAID", "SUCCESS_COMPLETED"); //OVO, DANA, LINKAJA
if (in_array($response['status'], $statusList)) {
return "COMPLETED";
Expand Down
2 changes: 1 addition & 1 deletion Xendit/M2Invoice/Helper/ApiRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private function getHeaders($isPublicRequest, $preferredMethod = null, $customHe
'Content-Type' => 'application/json',
'x-plugin-name' => 'MAGENTO2',
'user-agent' => 'Magento 2 Module',
'x-plugin-version' => '2.3.0'
'x-plugin-version' => '2.4.0'
];

if ($preferredMethod !== null) {
Expand Down
4 changes: 3 additions & 1 deletion Xendit/M2Invoice/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,9 @@ public function xenditPaymentMethod( $payment ){
"mandiriva" => "mandiri",
"permatava" => "permata",
"alfamart" => "alfamart",
"ovo" => "ovo"
"ovo" => "ovo",
"dana" => "dana",
"indomaret" => "indomaret"
];

$response = FALSE;
Expand Down
2 changes: 2 additions & 0 deletions Xendit/M2Invoice/Model/Adminhtml/Source/ChosenMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public function toOptionArray($isMultiselect = false)
['value' => 'cc', 'label' => __('Credit Card')],
['value' => 'cc_installment', 'label' => __('Credit Card Installment')],
['value' => 'cc_subscription', 'label' => __('Credit Card Subscription')],
['value' => 'dana', 'label' => __('DANA')],
['value' => 'indomaret', 'label' => __('Indomaret')],
['value' => 'ovo', 'label' => __('OVO')],
];

Expand Down
6 changes: 3 additions & 3 deletions Xendit/M2Invoice/Model/Payment/AbstractInvoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null)
return true;
}
//uncomment this block for local testing
/*if($this->methodCode == 'OVO'){
/*if($this->methodCode == 'OVO' || $this->methodCode == 'DANA'){
return true;
}*/

if ( !in_array( strtoupper($this->methodCode), $availableMethod ) ) {
if (!in_array(strtoupper($this->methodCode), $availableMethod)) {
return false;
}

Expand Down Expand Up @@ -156,7 +156,7 @@ private function getAvailableMethods()
throw $e;
}

if ( !isset($response['available_method']) ) {
if (!isset($response['available_method'])) {
return [];
}

Expand Down
16 changes: 16 additions & 0 deletions Xendit/M2Invoice/Model/Payment/DANA.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Xendit\M2Invoice\Model\Payment;

class DANA extends AbstractInvoice
{
/**
* Payment code
*
* @var string
*/
protected $_code = 'dana';
protected $_minAmount = 10000;
protected $_maxAmount = 10000000;
protected $methodCode = 'DANA';
}
16 changes: 16 additions & 0 deletions Xendit/M2Invoice/Model/Payment/Indomaret.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Xendit\M2Invoice\Model\Payment;

class Indomaret extends AbstractInvoice
{
/**
* Payment code
*
* @var string
*/
protected $_code = 'indomaret';
protected $_minAmount = 10000;
protected $_maxAmount = 2500000;
protected $methodCode = 'Indomaret';
}
2 changes: 1 addition & 1 deletion Xendit/M2Invoice/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "xendit/m2invoice",
"description": "Xendit Payment Gateway Module",
"type": "magento2-module",
"version": "2.3.0",
"version": "2.4.0",
"license": [
"GPL-3.0"
],
Expand Down
2 changes: 1 addition & 1 deletion Xendit/M2Invoice/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
function shouldDisplayAdditionalKYCWarningMethod() {
var currentValue = specificSelection.val();
if (currentValue.includes('ovo') || currentValue.includes('alfamart') || currentValue.includes('bcava')) {
if (currentValue.includes('ovo') || currentValue.includes('alfamart') || currentValue.includes('bcava') || currentValue.includes('dana')) {
displayAdditionalKYCWarning(true);
} else {
displayAdditionalKYCWarning(false);
Expand Down
22 changes: 21 additions & 1 deletion Xendit/M2Invoice/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,26 @@
<cctypes>VI,MC,AE,JCB</cctypes>
<sort_order>10</sort_order>
</cc_subscription>
<dana>
<active>1</active>
<payment_action>initialize</payment_action>
<model>Xendit\M2Invoice\Model\Payment\DANA</model>
<title>DANA</title>
<is_gateway>1</is_gateway>
<can_initialize>1</can_initialize>
<can_use_checkout>1</can_use_checkout>
<sort_order>11</sort_order>
</dana>
<indomaret>
<active>1</active>
<payment_action>initialize</payment_action>
<model>Xendit\M2Invoice\Model\Payment\Indomaret</model>
<title>Indomaret</title>
<is_gateway>1</is_gateway>
<can_initialize>1</can_initialize>
<can_use_checkout>1</can_use_checkout>
<sort_order>12</sort_order>
</indomaret>
<ovo>
<active>1</active>
<payment_action>authorize</payment_action>
Expand All @@ -127,7 +147,7 @@
<is_gateway>1</is_gateway>
<can_initialize>1</can_initialize>
<can_use_checkout>1</can_use_checkout>
<sort_order>11</sort_order>
<sort_order>13</sort_order>
</ovo>
</payment>
</default>
Expand Down
2 changes: 1 addition & 1 deletion Xendit/M2Invoice/etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Xendit_M2Invoice" setup_version="2.3.0" active="true"></module>
<module name="Xendit_M2Invoice" setup_version="2.4.0" active="true"></module>
</config>
6 changes: 6 additions & 0 deletions Xendit/M2Invoice/etc/payment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ https://github.com/magento/magento2/blob/2.2.0-rc2.1/app/code/Magento/Multishipp
<method name='cc_subscription'>
<allow_multiple_address>1</allow_multiple_address>
</method>
<method name='dana'>
<allow_multiple_address>1</allow_multiple_address>
</method>
<method name='indomaret'>
<allow_multiple_address>1</allow_multiple_address>
</method>
<method name='ovo'>
<allow_multiple_address>1</allow_multiple_address>
</method>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
<item name="mandiriva" xsi:type="string">Xendit_M2Invoice::multishipping/mandiriva.phtml</item>
<item name="permatava" xsi:type="string">Xendit_M2Invoice::multishipping/permatava.phtml</item>
<item name="ovo" xsi:type="string">Xendit_M2Invoice::multishipping/ovo.phtml</item>
<item name="dana" xsi:type="string">Xendit_M2Invoice::multishipping/dana.phtml</item>
<item name="indomaret" xsi:type="string">Xendit_M2Invoice::multishipping/indomaret.phtml</item>
</argument>
</arguments>
</referenceBlock>
Expand Down
29 changes: 29 additions & 0 deletions Xendit/M2Invoice/view/frontend/templates/multishipping/dana.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
?>
<script>
require([
'uiLayout',
'jquery'
], function (layout, $) {
$(function () {
var paymentMethodData = {
method: 'dana'
};
layout([
{
component: 'Xendit_M2Invoice/js/view/payment/method-renderer/multishipping/dana',
name: 'payment_method_dana',
method: paymentMethodData.method,
item: paymentMethodData
}
]);

$('body').trigger('contentUpdated');
})
})
</script>
<!-- ko template: getTemplate() --><!-- /ko -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
?>
<script>
require([
'uiLayout',
'jquery'
], function (layout, $) {
$(function () {
var paymentMethodData = {
method: 'indomaret'
};
layout([
{
component: 'Xendit_M2Invoice/js/view/payment/method-renderer/multishipping/indomaret',
name: 'payment_method_indomaret',
method: paymentMethodData.method,
item: paymentMethodData
}
]);

$('body').trigger('contentUpdated');
})
})
</script>
<!-- ko template: getTemplate() --><!-- /ko -->
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ define(
type: 'ovo',
component: 'Xendit_M2Invoice/js/view/payment/method-renderer/ovo'
},
{
type: 'dana',
component: 'Xendit_M2Invoice/js/view/payment/method-renderer/dana'
},
{
type: 'indomaret',
component: 'Xendit_M2Invoice/js/view/payment/method-renderer/indomaret'
},
{
type: 'cc',
component: 'Xendit_M2Invoice/js/view/payment/method-renderer/cc'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ define(
}

if (totals.grand_total < 10000) {
self.messageContainer.addErrorMessage({'message': 'Xendit doesn\'t support purchases less than Rp 11.000.'});
self.messageContainer.addErrorMessage({'message': 'Xendit doesn\'t support purchases less than Rp 10,000.'});
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ define(
}

if (totals.grand_total < 10000) {
self.messageContainer.addErrorMessage({'message': 'Xendit doesn\'t support purchases less than Rp 11.000.'});
self.messageContainer.addErrorMessage({'message': 'Xendit doesn\'t support purchases less than Rp 10,000.'});
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ define(
}

if (totals.grand_total < 10000) {
self.messageContainer.addErrorMessage({'message': 'Xendit doesn\'t support purchases less than Rp 11.000.'});
self.messageContainer.addErrorMessage({'message': 'Xendit doesn\'t support purchases less than Rp 10,000.'});
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ define(
}

if (totals.grand_total < 10000) {
self.messageContainer.addErrorMessage({'message': 'Xendit doesn\'t support purchases less than Rp 11.000.'});
self.messageContainer.addErrorMessage({'message': 'Xendit doesn\'t support purchases less than Rp 10,000.'});
return false;
}

Expand Down
Loading

0 comments on commit f4b8367

Please sign in to comment.