Skip to content

Commit

Permalink
Merge pull request #59 from xendit/TPI-2798/custom-externalId
Browse files Browse the repository at this point in the history
Use custom external ID
  • Loading branch information
IreneGohtami authored Oct 8, 2020
2 parents 045ee43 + 9197ecf commit ce2f330
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 16 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG

## 2.3.0 (2020-10-06)

Features:

- Enable custom external ID

## 2.2.2 (2020-10-01)

Bugfix:
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,15 @@ To activate this feature, you need to follow this additional steps:

## Supported Payment Method
- Credit and Debit Card
- Mandiri VA
- BNI VA
- BCA VA
- BNI VA
- BRI VA
- Mandiri VA
- Permata VA
- Alfamart
- OVO
- Credit Card Subscription
- Credit Card Installment

## Refund Support
Since v1.3.0, online refund (full and partial) is supported for payment through credit and debit card channel.
Expand Down
11 changes: 11 additions & 0 deletions Xendit/M2Invoice/Controller/Checkout/CCMultishipping.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function execute()

$transactionAmount = 0;
$tokenId = '';
$orderProcessed = false;
$orders = [];

if ($method === 'cc_subscription' && !$customerSession->isLoggedIn()) {
Expand All @@ -33,6 +34,12 @@ public function execute()
$order = $this->getOrderFactory()->create();
$order ->load($value);

$orderState = $order->getState();
if ($orderState === Order::STATE_PROCESSING && !$order->canInvoice()) {
$orderProcessed = true;
continue;
}

$order ->setState(Order::STATE_PENDING_PAYMENT)
->setStatus(Order::STATE_PENDING_PAYMENT)
->addStatusHistoryComment("Pending Xendit payment.");
Expand All @@ -52,6 +59,10 @@ public function execute()
$transactionAmount += (int)$order->getTotalDue();
}

if ($orderProcessed) {
return $this->_redirect('multishipping/checkout/success');
}

if ($method === 'cc') {
$requestData = array(
'token_id' => $tokenId,
Expand Down
15 changes: 13 additions & 2 deletions Xendit/M2Invoice/Controller/Checkout/InvoiceMultishipping.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,19 @@ public function execute()
$orderIds = explode("-", $rawOrderIds);

$transactionAmount = 0;

$orders = [];
$orderProcessed = false;
$orders = [];

foreach ($orderIds as $key => $value) {
$order = $this->getOrderFactory()->create();
$order->load($value);

$orderState = $order->getState();
if ($orderState === Order::STATE_PROCESSING && !$order->canInvoice()) {
$orderProcessed = true;
continue;
}

$order->setState(Order::STATE_PENDING_PAYMENT)
->setStatus(Order::STATE_PENDING_PAYMENT)
->addStatusHistoryComment("Pending Xendit payment.");
Expand All @@ -34,6 +41,10 @@ public function execute()
$billingEmail = $order->getCustomerEmail();
}

if ($orderProcessed) {
return $this->_redirect('multishipping/checkout/success');
}

$preferredMethod = $this->getRequest()->getParam('preferred_method');
$requestData = [
'success_redirect_url' => $this->getDataHelper()->getSuccessUrl(true),
Expand Down
5 changes: 2 additions & 3 deletions Xendit/M2Invoice/Controller/Checkout/Notification.m22.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,8 @@ public function handleEwalletCallback($callbackPayload) {
$failureCode = $callbackPayload['failure_code'];
}

$extIdPrefix = $this->dataHelper->getExternalIdPrefix();
// Trimmed external ID from prefix is Magento's order ID
$orderId = ltrim($callbackPayload['external_id'], $extIdPrefix);
$temp = explode('-', $callbackPayload['external_id']);
$orderId = end($temp);
$order = $this->getOrderById($orderId);

return $this->checkOrder($order, true, $callbackPayload, null, $orderId);
Expand Down
5 changes: 2 additions & 3 deletions Xendit/M2Invoice/Controller/Checkout/Notification.m23.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,8 @@ public function handleEwalletCallback($callbackPayload) {
$failureCode = $callbackPayload['failure_code'];
}

$extIdPrefix = $this->dataHelper->getExternalIdPrefix();
// Trimmed external ID from prefix is Magento's order ID
$orderId = ltrim($callbackPayload['external_id'], $extIdPrefix);
$temp = explode('-', $callbackPayload['external_id']);
$orderId = end($temp);
$order = $this->getOrderById($orderId);

return $this->checkOrder($order, true, $callbackPayload, null, $orderId);
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.2.2'
'x-plugin-version' => '2.3.0'
];

if ($preferredMethod !== null) {
Expand Down
7 changes: 5 additions & 2 deletions Xendit/M2Invoice/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,12 @@ public function getExternalId($orderId, $duplicate = false)

public function getExternalIdPrefix()
{
$storeName = substr(preg_replace("/[^a-z0-9]/mi", "", $this->getStoreManager()->getStore()->getName()), 0, 20);
return $this->m2Invoice->getConfigData('external_id_prefix') . "-" . $this->getStoreName();
}

return "magento-xendit-$storeName";
public function getStoreName()
{
return substr(preg_replace("/[^a-z0-9]/mi", "", $this->getStoreManager()->getStore()->getName()), 0, 20);
}

public function getApiKey()
Expand Down
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.2.2",
"version": "2.3.0",
"license": [
"GPL-3.0"
],
Expand Down
21 changes: 20 additions & 1 deletion Xendit/M2Invoice/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,17 @@
shouldEnableSpecificMethod();
specificSelection.prop('size', 6);
var externalIdPrefix = jQuery("input[id*='m2invoice_external_id_prefix']");
jQuery(externalIdPrefix).attr("placeholder", "magento-xendit");
jQuery(externalIdPrefix).attr("maxlength", 50);
var defaultText = "Format: {Prefix}-{Store Name}-{Order ID}<br>Example: <b>"+externalIdPrefix.val()+"-mystore-245</b>";
externalIdPrefix.siblings('.note').children()[0].innerHTML = defaultText;
externalIdPrefix.change(function () {
var newText = "Format: {Prefix}-{Store Name}-{Order ID}<br>Example: <b>"+externalIdPrefix.val()+"-mystore-245</b>";
externalIdPrefix.siblings('.note').children()[0].innerHTML = newText;
});
jQuery("textarea[id*='m2invoice_card_installment_description']").attr("placeholder", "Bayar pesanan dengan cicilan kartu kredit anda melalui Xendit.\nBank yang tersedia: BCA, BRI");
if ( !jQuery("textarea[id*='m2invoice_card_installment_description']").val() ) {
Expand Down Expand Up @@ -176,7 +187,15 @@
<source_model>Xendit\M2Invoice\Model\Adminhtml\Source\ChosenMethod</source_model>
<can_be_empty>1</can_be_empty>
</field>
<field id="send_invoice_email" translate="label" type="select" sortOrder="67" showInDefault="1" showInWebsite="1" showInStore="0">
<field id="external_id_prefix" translate="label" type="text" sortOrder="67" showInDefault="1" showInWebsite="1" showInStore="0">
<label>External ID Prefix</label>
<comment>
<![CDATA[Format: {Prefix}-{Store Name}-{Order ID}<br>
Example: <b>magento-xendit-mystore-245</b>]]>
</comment>
<validate>required-entry</validate>
</field>
<field id="send_invoice_email" translate="label" type="select" sortOrder="68" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Send Email Notification</label>
<comment>
Send Xendit payment email notification to end customer when they checkout using bank transfer or retail outlet
Expand Down
1 change: 1 addition & 0 deletions Xendit/M2Invoice/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<validation_key backend_model="Magento\Config\Model\Config\Backend\Encrypted" />
<card_payment_type>form</card_payment_type>
<allowed_method>all</allowed_method>
<external_id_prefix>magento-xendit</external_id_prefix>
<send_invoice_email>1</send_invoice_email>
</m2invoice>
<alfamart>
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.2.2" active="true"></module>
<module name="Xendit_M2Invoice" setup_version="2.3.0" active="true"></module>
</config>

0 comments on commit ce2f330

Please sign in to comment.