Coder Social home page Coder Social logo

midtrans / midtrans-magento2 Goto Github PK

View Code? Open in Web Editor NEW
2.0 8.0 7.0 565 KB

Official Midtrans Payment Module for Magento 2 | https://midtrans.com

License: MIT License

PHP 74.49% JavaScript 17.02% HTML 8.39% CSS 0.10%
magento2 payment-gateway magento2-module midtrans

midtrans-magento2's Introduction

Latest Stable Version Monthly Downloads Total Downloads License

Midtrans ❤️ Magento! Midtrans strive to make payments simple for both the merchant and customers. With Midtrans Magento extension/plugin, your Magento Store can easily start accepting payments via Midtrans.

Live Demo

Want to see Midtrans Magento payment plugins in action? We have some demo web-stores for Magento that you can use to try the payment journey directly, click the link below.

Requirements:

  • An online store with Magento infrastructure. This plugin tested with Magento v2.1.0, v2.2.0, v2.3.1, v2.4.1
  • PHP v5.6 or greater.
  • MySQL v5.7 or greater.
  • Midtrans plugin for Magento v2.x [ Github | Zip ]
  • This plugin supports Magento2 version 2.1.0 - 2.4.1 and higher.

How to install the plugins

Install Midtrans Snap plugins through Composer

Before you begin to install through the composer, you need Magento marketplace account and make sure that you have installed Composer. In your terminal, go to the Magento folder and run the following commands:

  1. Install the plugins: composer require midtrans/snap
  2. Enable the plugin: bin/magento module:enable Midtrans_Snap
  3. Execute upgrade script : bin/magento setup:upgrade
  4. Clean cache storage : bin/magento cache:clean
  5. Check the module status: bin/magento module:status Midtrans_Snap

Note: If you do have a previous version installed and upgrade the plugins to the latest version. After upgrade our plugins, You need to run bin/magento setup:upgrade --keep-generated, bin/magento setup:static-content:deploy and clean cache bin/magento cachce:clean.

Install Midtrans Snap plugins through Magento marketplace

You can install Midtrans Snap plugins through Magento Marketplace. Please, visit Midtrans on Magento Marketplace and follow step-by-step installation instructions from the Official Magento extension docs

Install Midtrans Snap plugins from GitHub project

With these steps, you can custom/modify our Magento plugins to handle the business model that you want

  1. Download and extract the plugin you have previously downloaded from GitHub and rename the folder as Snap.

  2. Make a directory structure like this:

  3. Locate the root Magento directory of your shop via FTP connection.

  4. Copy the app folders into the Magento root folder.

  5. Run this command on terminal

    bin/magento module:enable Midtrans_Snap

    bin/magento setup:upgrade

    bin/magento cache:clean

    bin/magento module:status Midtrans_Snap

Plugin Usage Instruction

Basic Plugins Configuration

Before you begin, make sure that you have successfully installed and enabled Midtrans Snap plugins. Configure the Midtrans plugin in your Magento admin panel:

  1. Log in to your Magento admin panel.
  2. In the left navigation bar, go to Stores(1) -> Configuration(2).
  3. In the menu, go to Sales(3) -> Payment Methods(4)

  1. In the Midtrans - Accept Online Payment section, click Basic Settings and fill out the following fields:
Field Description
Is Production Select whether you want to use a sandbox or production mode.
Merchant ID Unique id of your Midtrans account for which the payments will be processed.
Sandbox - ClientKey Used as an API key to be used for authorization sandbox environment on frontend API request/configuration. So it is safe to put in your HTML / client code publicly.
Sandbox - ServerKey Used as an API key to be used for authorization sandbox environment while calling Midtrans API from the backend. So keep it stored confidentially.
Production - ClientKey Used as an API key to be used for authorization production environment on frontend API request/configuration. So it is safe to put in your HTML / client code publicly.
Production - ServerKey Used as an API key to be used for authorization production environments while calling Midtrans API from the backend. So keep it stored confidentially
Enable Snap redirect Change to Snap redirect mode, the default value is No.

Note: Access Keys are unique for every merchant. Server Key is secret, please always keep Server Key confidential.

Log options

The plugins will store log file in directory /var/log/midtrans. The default value is on for request, notification and error log. Except Throw Exception, is off by default.

Config Plugins Payment Integration

In the Midtrans Magento plugins we have 4 option to use Snap model payment method, with the following description:

  1. Snap payment integration

    This is the default Snap for Midtrans Magento plugins, Snap payment will be auto-enabled when installing the Midtrans plugins. Midtrans will show the available payment method on the Snap payment screen.

  2. Specific Payment integration | Optional

    Enabling this will display additional payment options to customer, for specific payment that are specified in the "Allowed Payment Method" field, Midtrans Snap will show only the listed payment method on the Snap screen.

  3. Online Installment payment integration | Optional

    Enabling this will display additional payment options to customer, for online installment payment where the Card Issuer and Acquiring Bank is the same entity (e.g: BNI Card and BNI Acquiring bank).

  4. Offline Installment payment integration | Optional

    Enabling this will display additional payment options to customer, for offline Installment where the Card Issuer and Acquiring Bank don't have to be same entity (e.g: BNI Card and Mandiri Acquiring Bank)

Note: You can use different Midtrans Account for every Snap model payment method, should configure the access-key in Optional section “Use different Midtrans account”. If the optional access-key is empty, the plugins will automatically use access key on Basic Settings.

INFO:

  • The built-in BCA Klikpay landing page for now will only use server key from basic settings of Snap payment integration.
  • Multishipping only support on version Midtrans Magento Plugins v2.5.3 or greater and not support in offline installment payment
  • In case you need to customize configuration these field are configurable, and described as follows:

    Field Description
    Enable Payment snap section enable
    Title The title for the payment method in the checkout page
    Custom Expiry This field will allow you to set a custom duration on how long the transaction is available to be paid.
    Allowed Payment Method Customize allowed payment method, separate payment method code with a comma. e.g: bank_transfer,credit_card. Leave it default if you are not sure.
    Acquiring Bank You can specify which Acquiring Bank they prefer to use for a specific transaction. The transaction fund will be routed to that specific acquiring bank. Leave it blank if you are not sure!
    BIN Number It is a feature that allows the merchant to accept only Credit Cards within a specific set of BIN numbers. Separate BIN number with comma Example: 4,5,4811,bni,mandiri. Leave it blank if you are not sure!
    Installment Terms An arrangement for payment by installments.
    3D Secure You must enable 3D Secure for secure card transactions. Please contact us if you wish to disable this feature in the Production environment.
    Save Card This will allow your customer to save their card on the payment popup, for faster payment flow on the following purchase.

    Midtrans  MAP Configuration

    1. Login to your Midtrans  Account, select your environment (sandbox/production), go to menu settings -> configuration

      • Payment Notification URL:

      https://[your-site-url]/snap/payment/notification

      • Finish Redirect URL:

      https://[your-site-url]/snap/index/finish

      • Unfinish Redirect URL:

      https://[your-site-url]/snap/index/finish

      • Error Redirect URL:

      https://[your-site-url]/snap/index/finish

    2. Go to menu settings > Snap Preference > System Settings

    • Insert https://[your-site-url]/snap/index/finish link as Finish/Unfinish/Error Redirect URL.

    How to online refund transaction

    Click to expand info

    You can request refunds either from the Midtrans Dashboard or from the Magento admin. After a refund is issued, it cannot be cancelled or undone. Before you trigger this request, make sure that the refund amount and any other details are correct.

    If you make refund from the Midtrans Dashboard, Refund notification is sent to Magento, set transaction state to CLOSED and for now is not created the credit memo.

    Request refund from Magento Admin:

    1. Log in to your Magento admin panel.

    2. In the menu, go to Sales > Orders. This opens the order overview page.

    3. Click on the order you want to refund.

    4. In the Order list View left-hand navigation sidebar, click Invoices tab.

    5. In the invoice list page, selected the order. click the view button on invoice you need to request online refund.

    6. Click Credit Memo on the top-right corner of the page.

    7. In the New Memo for Invoice page, scroll down to the Refund Totals section.

    8. In this section, you can request online Refund or Refund Offline.

      • Refund: This option will request refund Online to Midtrans, Midtrans automatically send refund notification and changes order status to Closed from notification.
      • Refund Offline: An offline refund does not trigger request refund to midtrans it’s only refund in Magento side. You need to take action and carry out the refund manually from Midtrans dashboard.After a refund operation, the order status changes to Closed. This order status change is controlled by the Magento system.

      The status change may not mean that the refund has carried out successfully on Midtrans side. When the transaction status in Midtrans dashboard changes to REFUND, then the refund went through successfully

    Configuring Custom Payment Fee

    In case you need it, payment fee can optionally be added by using additional (3rd party) extension: Mageprince Magento2 PaymentFee extension. It allows adding extra charges for specific payment methods and displays them on the cart page, checkout page, invoice, and credit memo.

    All the fee calculation will be handled by that extension. Midtrans extension will then take the produced PaymentFee value (from Magento order object), and parse it into additional item object for Midtrans API param.

    Example on how to use the PaymentFee Extension

    Click to expand info

    You can try the demo extension here

    Installation & Configuration Instructions

    You can install from Magento Marketplace or follow the manual installation step.

    How to configure the extension

    1. Go to menu Stores -> Configuration -> MagePrince -> Payment Fee
    2. Set Enable field to Yes
    3. Go to Payment Fee Settings section, choose PriceType, Fill in Minimum and Maximum order amount.
    4. Click Add Fee button, then choose Midtrans Payment method on Payment Method Fee and Fill in Fee Amount
    5. Click Save Config

    This is just an example configuration that works at the time of this writing, the extension may change in the future. For further & most up to date details of Mageprince PaymentFee extension configuration, you can check the official extension documentation.

    Get help

    midtrans-magento2's People

    Contributors

    aalexanderkevin avatar xaxxis avatar

    Stargazers

     avatar  avatar

    Watchers

     avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

    midtrans-magento2's Issues

    Checkout total double amount

    I am using this extension on Magento 2.4 and it is working perfectly for simple products, but on configurable products, it shows the double price as of actual cart total.

    Notice: Trying to get property 'status_code' of non-object

    Hallo, coba install modul midtrans di m2, tepatnya 2.3.2
    Transaksi jalan normal, tapi tidak bisa terima balikan notifikasi pembayaran,

    {"0":"Notice: Trying to get property 'status_code' of non-object in \/var\/www\/html\/lib\/internal\/midtrans-php\/Midtrans\/ApiRequestor.php on line 102","1":"<pre>#1 Midtrans\\ApiRequestor::remoteCall('https:\/\/api.sand...', 'SB-Mid-server-4P...', false, false) called at [lib\/internal\/midtrans-php\/Midtrans\/ApiRequestor.php:22]\n#2 Midtrans\\ApiRequestor::get('https:\/\/api.sand...', 'SB-Mid-server-4P...', false) called at [lib\/internal\/midtrans-php\/Midtrans\/Transaction.php:23]\n#3 Midtrans\\Transaction::status(NULL) called at [lib\/internal\/midtrans-php\/Midtrans\/Notification.php:26]\n#4 Midtrans\\Notification->__construct('php:\/\/input') called at [vendor\/magento\/framework\/ObjectManager\/Factory\/AbstractFactory.php:116]\n#5 Magento\\Framework\\ObjectManager\\Factory\\AbstractFactory->createObject('Midtrans\\Notific...', array('php:\/\/input')) called at [vendor\/magento\/framework\/ObjectManager\/Factory\/Compiled.php:108]\n#6 Magento\\Framework\\ObjectManager\\Factory\\Compiled->create('Midtrans\\Notific...') called at [vendor\/magento\/framework\/ObjectManager\/ObjectManager.php:70]\n#7 Magento\\Framework\\ObjectManager\\ObjectManager->get('Midtrans\\Notific...') called at [app\/code\/Midtrans\/Snap\/Controller\/Payment\/Notification.php:56]\n#8 Midtrans\\Snap\\Controller\\Payment\\Notification->execute() called at [vendor\/magento\/framework\/App\/Action\/Action.php:108]\n#9 Magento\\Framework\\App\\Action\\Action->dispatch(&Magento\\Framework\\App\\Request\\Http#000000000e8954c5000000005911c361#) called at [vendor\/magento\/framework\/Interception\/Interceptor.php:58]\n#10 Midtrans\\Snap\\Controller\\Payment\\Notification\\Interceptor->___callParent('dispatch', array(&Magento\\Framework\\App\\Request\\Http#000000000e8954c5000000005911c361#)) called at [vendor\/magento\/framework\/Interception\/Interceptor.php:138]\n#11 Midtrans\\Snap\\Controller\\Payment\\Notification\\Interceptor->Magento\\Framework\\Interception\\{closure}(&Magento\\Framework\\App\\Request\\Http#000000000e8954c5000000005911c361#) called at [vendor\/magento\/framework\/Interception\/Interceptor.php:153]\n#12 Midtrans\\Snap\\Controller\\Payment\\Notification\\Interceptor->___callPlugins('dispatch', array(&Magento\\Framework\\App\\Request\\Http#000000000e8954c5000000005911c361#), array(array('designLoader', 'customerNotifica...', 'catalog_app_acti...', 'tax-app-action-d...', 'weee-app-action-...', 'storeCheck', 'contextPlugin', 'customer-app-act...'))) called at [generated\/code\/Midtrans\/Snap\/Controller\/Payment\/Notification\/Interceptor.php:26]\n#13 Midtrans\\Snap\\Controller\\Payment\\Notification\\Interceptor->dispatch(&Magento\\Framework\\App\\Request\\Http#000000000e8954c5000000005911c361#) called at [vendor\/magento\/framework\/App\/FrontController.php:159]\n#14 Magento\\Framework\\App\\FrontController->processRequest(&Magento\\Framework\\App\\Request\\Http#000000000e8954c5000000005911c361#, &Midtrans\\Snap\\Controller\\Payment\\Notification\\Interceptor#000000000e895535000000005911c361#) called at [vendor\/magento\/framework\/App\/FrontController.php:99]\n#15 Magento\\Framework\\App\\FrontController->dispatch(&Magento\\Framework\\App\\Request\\Http#000000000e8954c5000000005911c361#) called at [vendor\/magento\/framework\/Interception\/Interceptor.php:58]\n#16 Magento\\Framework\\App\\FrontController\\Interceptor->___callParent('dispatch', array(&Magento\\Framework\\App\\Request\\Http#000000000e8954c5000000005911c361#)) called at [vendor\/magento\/framework\/Interception\/Interceptor.php:138]\n#17 Magento\\Framework\\App\\FrontController\\Interceptor->Magento\\Framework\\Interception\\{closure}(&Magento\\Framework\\App\\Request\\Http#000000000e8954c5000000005911c361#) called at [vendor\/magento\/module-store\/App\/FrontController\/Plugin\/RequestPreprocessor.php:94]\n#18 Magento\\Store\\App\\FrontController\\Plugin\\RequestPreprocessor->aroundDispatch(&Magento\\Framework\\App\\FrontController\\Interceptor#000000000e895796000000005911c361#, &Closure#000000000e895672000000005911c361#, &Magento\\Framework\\App\\Request\\Http#000000000e8954c5000000005911c361#) called at [vendor\/magento\/framework\/Interception\/Interceptor.php:135]\n#19 Magento\\Framework\\App\\FrontController\\Interceptor->Magento\\Framework\\Interception\\{closure}(&Magento\\Framework\\App\\Request\\Http#000000000e8954c5000000005911c361#) called at [vendor\/magento\/module-page-cache\/Model\/App\/FrontController\/BuiltinPlugin.php:69]\n#20 Magento\\PageCache\\Model\\App\\FrontController\\BuiltinPlugin->aroundDispatch(&Magento\\Framework\\App\\FrontController\\Interceptor#000000000e895796000000005911c361#, &Closure#000000000e895672000000005911c361#, &Magento\\Framework\\App\\Request\\Http#000000000e8954c5000000005911c361#) called at [vendor\/magento\/framework\/Interception\/Interceptor.php:135]\n#21 Magento\\Framework\\App\\FrontController\\Interceptor->Magento\\Framework\\Interception\\{closure}(&Magento\\Framework\\App\\Request\\Http#000000000e8954c5000000005911c361#) called at [vendor\/magento\/framework\/Interception\/Interceptor.php:153]\n#22 Magento\\Framework\\App\\FrontController\\Interceptor->___callPlugins('dispatch', array(&Magento\\Framework\\App\\Request\\Http#000000000e8954c5000000005911c361#), NULL) called at [generated\/code\/Magento\/Framework\/App\/FrontController\/Interceptor.php:26]\n#23 Magento\\Framework\\App\\FrontController\\Interceptor->dispatch(&Magento\\Framework\\App\\Request\\Http#000000000e8954c5000000005911c361#) called at [vendor\/magento\/framework\/App\/Http.php:137]\n#24 Magento\\Framework\\App\\Http->launch() called at [vendor\/magento\/framework\/App\/Bootstrap.php:261]\n#25 Magento\\Framework\\App\\Bootstrap->run(&Magento\\Framework\\App\\Http\\Interceptor#000000000e89543b000000005911c361#) called at [index.php:39]\n<\/pre>","url":"\/snap\/payment\/notification","script_name":"\/index.php"}

    coba hit ulang via postman juga sama,,
    bisa tolong dibantu, trims,,

    Support Multishipping

    Halo, saya ingin mengkonfirmasi, apakah plugin Midtrans untuk Magento ini sudah support untuk Multishipping?

    Karna saya coba tidak muncul di multishipping untuk payment Midtrans.

    @Xaxxis
    Terima kasih.

    Save Credit Card

    Selamat Sore, mau tanya. kalo save credit card number di plugin midtrans untuk magento sudah bisa dipakai kah?

    Expired not working

    Halo, saya coba set expired di config, namun di payload tidak terkirim. Saya lihat di AbstractAction seperti ini:

    ` if (!empty($customExpiry)) {
    $customExpiry = explode(" ", $customExpiry);
    $expiry_unit = $customExpiry[1];
    $expiry_duration = (int)$customExpiry[0];

            $payloads['expiry'] = [
                'unit' => $expiry_unit,
                'duration' => (int)$expiry_duration
            ];
        }`
    

    $customExpiry tidak merujuk ke variable apa pun, apakah mungkin maksudnya merujuk ke config?

    Can not place an order

    Preconditions and environment

    • Magento 2.4.4 or 2.4.3 and Midtrans 2.7.0
    • Enable Snap Redirect

    Steps to reproduce

    • Open web, add a product to Cart
    • Go to checkout, payment page
    • Click to Place Order

    Expected result

    • Go to payment page

    Actual result

    • Can not go to payment page

    Other

    Midtrans error log: The entity that was requested doesn't exist. Verify the entity and try again

    Hint maybe:

    • getOrderByIncrementId in Midtrans/Snap/Model/Order/OrderRepository.php.

    • $this->magentoOrderRepository->get($realOrderId). Function get is default Magento with parameter is entity_id of order but in class Midtrans/Snap/Controller/Payment/Redirect.php (Line 16) call it with parameter is increment id.

    Tag new version

    Current 2.3.0 is require:
    "php": "~5.5.0|~5.6.0",

    but magento 2.3.x require php 7.
    Please tag new version for current code in master
    cc: @Xaxxis

    Custom Snap

    Halo.. saya ingin menanyakan fitur. apakah bisa dengan snap ini menambahkan biaya layanan dengan perhitungan sesuai credit card yang digunakan dan installment term yg dipilih oleh customer? jika bisa bagaimana caranya. jika tidak bisa workaround nya seperti apa ya.

    Bad Request

    per tanggal 15 Oktober 2020, untuk versi yang terbaru, saya mendapatkan response "Bad Request" ketika request token SNAP API, namun tidak terjadi pada versi 2.2.0.

    `[2020-10-15 06:30:15] MidtransLogger.ERROR: Midtrans Error (400):

    400 Bad request


    Your browser sent an invalid request.

    | Request url: https://app.midtrans.com/snap/v1/transactions {"is_exception":false} [] `

    Saya lihat perbedaannya ada pada header yang dikirim, jadi saya coba samakan dengan versi di 2.2.0.

    $curl_options = array( CURLOPT_URL => $url, CURLOPT_HTTPHEADER => array( 'Content-Type: application/json', 'Accept: application/json', 'user-agent : Magento 2 Module', 'x-plugin-name : midtrans-magento2', 'Authorization: Basic ' . base64_encode($server_key . ':') ), CURLOPT_RETURNTRANSFER => 1, // CURLOPT_CAINFO => dirname(__FILE__) . "/../data/cacert.pem" );

    menjadi

    $curl_options = array( CURLOPT_URL => $url, CURLOPT_HTTPHEADER => array( 'Content-Type: application/json', 'Accept: application/json', 'Authorization: Basic ' . base64_encode($server_key . ':') ), CURLOPT_RETURNTRANSFER => 1, // CURLOPT_CAINFO => dirname(__FILE__) . "/../data/cacert.pem" );

    pada file SnapApiRequestor.php dan ApiRequestor.php

    Payment captured but invoice not generated

    Preconditions and environment

    • Magento 2.4.3 and Midtrans 2.6.5

    Steps to reproduce

    • Open web, add a product to Cart
    • Go to checkout, payment page
    • Input incorrect data: 4411 1111 1111 1118 , 10/25, CVV: 111
    • Input correct data again: 4411 1111 1111 1118 , 10/25, CVV: 123

    Expected result

    • Order status change to processing and invoice generated.

    Actual result

    • Order status is processing and invoice is not generated.

    Hint maybe:
    When Input data is incorrect, order received Deny notification from midtrands, and order status change to Payment Review. After customer input correct data again, order received Capture notification from midtrands. However, the invoice is not generated because the order did not pass canInvoice function because the current status is Payment Review.

    Recommend Projects

    • React photo React

      A declarative, efficient, and flexible JavaScript library for building user interfaces.

    • Vue.js photo Vue.js

      🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

    • Typescript photo Typescript

      TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

    • TensorFlow photo TensorFlow

      An Open Source Machine Learning Framework for Everyone

    • Django photo Django

      The Web framework for perfectionists with deadlines.

    • D3 photo D3

      Bring data to life with SVG, Canvas and HTML. 📊📈🎉

    Recommend Topics

    • javascript

      JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

    • web

      Some thing interesting about web. New door for the world.

    • server

      A server is a program made to process requests and deliver data to clients.

    • Machine learning

      Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

    • Game

      Some thing interesting about game, make everyone happy.

    Recommend Org

    • Facebook photo Facebook

      We are working to build community through open source technology. NB: members must have two-factor auth.

    • Microsoft photo Microsoft

      Open source projects and samples from Microsoft.

    • Google photo Google

      Google ❤️ Open Source for everyone.

    • D3 photo D3

      Data-Driven Documents codes.