Skip to content

Commit

Permalink
Merge pull request #15 from omarxp/support-drupal-9-and-enhancement
Browse files Browse the repository at this point in the history
Support Drupal 9 and Enhancement
  • Loading branch information
omarxp committed Aug 26, 2021
2 parents ed5e78a + 3d4e4b4 commit eb9b1a7
Show file tree
Hide file tree
Showing 56 changed files with 1,491 additions and 7,386 deletions.
40 changes: 31 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,51 @@
Midtrans Drupal 8 Commerce Payment Gateway Module
Midtrans Drupal 8/9 Commerce Payment Gateway Module
=======================================================

Midtrans :heart: Drupal 8!
Midtrans :heart: Drupal 8/9!
Let your Drupal Commerce 2 store integrated with Midtrans payment gateway.

### Description
This is the official Midtrans extension for the Drupal Commerce 2 E-commerce platform.

### Version
8.x-2.00
(for Drupal v 8.x)
2.0.0
(for Drupal v8.x and Drupal v9.x)

### Requirements
The following plugin is tested under following environment:

* PHP v5.6.x or greater
* MySQL version 5.0 or greater
* Drupal v8.x
* Drupal v8.x or greater
* [Drupal Commerce 8.x-2.xx ](http://www.drupal.org/project/commerce)

#### Installation Process
#### Composer Installation
If you are using [Composer](https://getcomposer.org), you can install via composer CLI:

```
composer require midtrans/midtrans-drupal8
```

**or**

add this require line to your `composer.json` file:

```json
{
"require": {
"midtrans/midtrans-drupal8": "2.0.0"
}
}
```

and run `composer update` on your terminal.

#### Manual Instalation
The manual installation method involves downloading our feature-rich plugin and uploading it to your webserver via your favourite FTP application.

1. Download the plugin file to your computer and unzip it, rename folder to ``commerce_midtrans``.
2. Using an FTP program, or your hosting control panel, upload the unzipped plugin folder to your Drupal modules installation's ``[Drupal folder]/modules/contrib/`` directory.
2. Using an FTP program, or your hosting control panel, upload the unzipped plugin folder to your Drupal modules installation's ``[Drupal folder]/modules/contrib/`` directory.


#### Plugin Configuration
1. Open drupal admin page, open menu **Extend**.
Expand All @@ -44,7 +66,7 @@ The manual installation method involves downloading our feature-rich plugin and
#### Advanced Usage
<details>
<summary>Note on Customer Phone Number</summary>

##### Note on Customer Phone Number
Unfortunately Drupal Commerce by default doesn't have `phone number` as customer data <sup>\[1\]</sup>, so there will be no `phone` data passed to Midtrans side.

Expand All @@ -66,7 +88,7 @@ But you will need to figure out on your own, how to programmatically retrieve cu
You can also add more custom Snap API payload to add more data related to the transaction. Learn more on the API payload [on Snap API docs](http://snap-docs.midtrans.com)

> <sup>\[1\]</sup> At this time of writing, based on `[DrupalCommerceFolder]/modules/contrib/address/src/Plugin/Field/FieldType/AddressItem.php`, the class doesn't have any phone attribute by default.
>
>
> And no explanation of it on the [Drupal Commerce PG module development guide](https://docs.drupalcommerce.org/commerce2/developer-guide/payments/create-payment-gateway/on-site-gateways/stored-payment-methods)
</details>
Expand Down
9 changes: 9 additions & 0 deletions commerce_midtrans.commerce_log_templates.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
commerce_midtrans_notification:
category: commerce_order
label: 'Notification'
template: '<p><strong>Midtrans Notification:</strong><br />
Drupal Order ID: {{ order_id }}<br>
Midtrans Transaction ID: {{ transaction_id }}<br>
Transaction Status: {{ transaction_status }}<br>
Payment Type: {{ payment_type }}<br>
</p>'
5 changes: 3 additions & 2 deletions commerce_midtrans.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ package: Commerce (contrib)
dependencies:
- commerce:commerce_payment
# Information
version: '8.x-2.10'
version: '2.0.0'
core: '8.x'
core_version_requirement: ^8 || ^9
project: 'commerce_midtrans'
datestamp: 1543190400
datestamp: 1543190400
19 changes: 19 additions & 0 deletions commerce_midtrans.libraries.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
adminmodule:
version: VERSION
js:
js/midtrans.admin.js: {}
dependencies:
- core/jquery
- core/jquery.once
- core/drupal
- core/drupalSettings

checkout:
version: VERSION
js:
js/midtrans.checkout.js: {}
dependencies:
- core/jquery
- core/jquery.once
- core/drupal
- core/drupalSettings
11 changes: 11 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "midtrans/midtrans-drupal8",
"description": "The official Midtrans extension for the Drupal Commerce 2",
"homepage": "https://midtrans.com",
"version": "2.0.0",
"type": "drupal-module",
"license":"MIT",
"require": {
"midtrans/midtrans-php": "^2.4"
}
}
78 changes: 60 additions & 18 deletions config/schema/commerce_midtrans.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ commerce_payment.commerce_payment_gateway.plugin.midtrans:
mapping:
merchant_id:
type: string
label: 'Merchant Id'
label: 'Merchant ID'
server_key:
type: string
label: 'Server key'
label: 'Server Key'
client_key:
type: string
label: 'Client key'
label: 'Client Key'
enable_3ds:
type: boolean
label: 'Enable 3DS'
Expand All @@ -25,19 +25,28 @@ commerce_payment.commerce_payment_gateway.plugin.midtrans:
custom_field:
type: string
label: 'Custom Field'
enable_override_notification:
type: boolean
label: 'Enable Override Notification'
enable_log_for_http_notification:
type: boolean
Label: 'Enable Notification Log'
enable_log_for_exception:
type: boolean
Label: 'Enable Throw Exception'

commerce_payment.commerce_payment_gateway.plugin.midtrans_installment:
type: commerce_payment_gateway_configuration
mapping:
merchant_id:
type: string
label: 'Merchant Id'
label: 'Merchant ID'
server_key:
type: string
label: 'Server key'
label: 'Server Key'
client_key:
type: string
label: 'Client key'
label: 'Client Key'
enable_3ds:
type: boolean
label: 'Enable 3DS'
Expand All @@ -53,19 +62,28 @@ commerce_payment.commerce_payment_gateway.plugin.midtrans_installment:
custom_field:
type: string
label: 'Custom Field'
enable_override_notification:
type: boolean
label: 'Enable Override Notification'
enable_log_for_http_notification:
type: boolean
Label: 'Enable Notification Log'
enable_log_for_exception:
type: boolean
Label: 'Enable Throw Exception'

commerce_payment.commerce_payment_gateway.plugin.midtrans_installmentoff:
type: commerce_payment_gateway_configuration
mapping:
merchant_id:
type: string
label: 'Merchant Id'
label: 'Merchant ID'
server_key:
type: string
label: 'Server key'
label: 'Server Key'
client_key:
type: string
label: 'Client key'
label: 'Client Key'
enable_3ds:
type: boolean
label: 'Enable 3DS'
Expand All @@ -75,28 +93,43 @@ commerce_payment.commerce_payment_gateway.plugin.midtrans_installmentoff:
enable_savecard:
type: boolean
label: 'Enable Save Card'
installment_term:
type: string
label: 'Installment Terms'
acquiring_bank:
type: string
label: 'Acquiring Bank'
min_amount:
type: string
label: 'Minimal Amount'
bin_number:
type: string
label: 'CC Bins'
label: 'CC Bins'
custom_field:
type: string
label: 'Custom Field'

enable_override_notification:
type: boolean
label: 'Enable Override Notification'
enable_log_for_http_notification:
type: boolean
Label: 'Enable Notification Log'
enable_log_for_exception:
type: boolean
Label: 'Enable Throw Exception'

commerce_payment.commerce_payment_gateway.plugin.midtrans_promo:
type: commerce_payment_gateway_configuration
mapping:
merchant_id:
type: string
label: 'Merchant Id'
label: 'Merchant ID'
server_key:
type: string
label: 'Server key'
label: 'Server Key'
client_key:
type: string
label: 'Client key'
label: 'Client Key'
enable_3ds:
type: boolean
label: 'Enable 3DS'
Expand All @@ -108,7 +141,7 @@ commerce_payment.commerce_payment_gateway.plugin.midtrans_promo:
label: 'Enable Save Card'
method_enabled:
type: string
label: 'Enable Payment'
label: 'Enable Payment'
min_amount:
type: string
label: 'Minimal Amount'
Expand All @@ -123,10 +156,19 @@ commerce_payment.commerce_payment_gateway.plugin.midtrans_promo:
label: 'Discount Amount'
max_discount:
type: number
label: 'Maximun Discount'
label: 'Maximun Discount'
custom_expiry:
type: string
label: 'Custom Expiry'
label: 'Custom Expiry'
custom_field:
type: string
label: 'Custom Field'
label: 'Custom Field'
enable_override_notification:
type: boolean
label: 'Enable Override Notification'
enable_log_for_http_notification:
type: boolean
Label: 'Enable Notification Log'
enable_log_for_exception:
type: boolean
Label: 'Enable Throw Exception'
42 changes: 42 additions & 0 deletions js/midtrans.admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// This file for dynamically put sandbox/production text label on API keys field, according to selected API env mode.
// For each of Midtrans Modules (fullpayment, installment, promo etc)

(function ($, Drupal, drupalSettings) {
'use strict';

Drupal.behaviors.initMidtransModule = {
attach: function (context) {
var midtransSettings = drupalSettings.commerce_midtrans;
var midtransModule = $(context).find(midtransSettings.id);
if (midtransModule.length > 0) {
updateEnvMode(midtransSettings.module);
}
}
};

function updateEnvMode(moduleName) {
var selectorName = moduleName.replace('_', '-');
var mode = $("input[type='radio'][name='configuration[" +moduleName+ "][mode]']:checked").val();
updateTextLabel(selectorName, mode);

$("input[type='radio'][name='configuration[" +moduleName+ "][mode]']").on('change', function() {
updateTextLabel(selectorName, this.value);
});
}

function updateTextLabel(selectorName, mode) {
var hrefs = document.querySelectorAll('.config_info');
var textLabel = capitalizeLabel(mode);
var subdomain = (mode == 'sandbox') ? 'dashboard.sandbox' : 'dashboard';
document.querySelector('label[for^="edit-configuration-' +selectorName+ '-server-key"]').innerText = "Server Key " +textLabel;
document.querySelector('label[for^="edit-configuration-' +selectorName+ '-client-key"]').innerText = "Client Key " +textLabel;
hrefs.forEach(function(e){
e.href = 'https://' +subdomain+ '.midtrans.com/settings/config_info'
});
}

function capitalizeLabel(string) {
return string[0].toUpperCase() + string.slice(1);
}

})(jQuery, Drupal, drupalSettings);
Loading

0 comments on commit eb9b1a7

Please sign in to comment.