Skip to content

Commit

Permalink
Added Apple Pay
Browse files Browse the repository at this point in the history
  • Loading branch information
michielgerritsen committed May 8, 2019
1 parent 11b239f commit 329a2d3
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 4 deletions.
1 change: 1 addition & 0 deletions Helper/General.php
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ public function getAllActiveMethods($storeId)
'mollie_methods_klarnasliceit',
'mollie_methods_giftcard',
'mollie_methods_przelewy24',
'mollie_methods_applepay',
];

foreach ($methodCodes as $methodCode) {
Expand Down
25 changes: 25 additions & 0 deletions Model/Methods/ApplePay.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* Copyright © 2018 Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Mollie\Payment\Model\Methods;

class ApplePay extends \Mollie\Payment\Model\Mollie
{

/**
* Payment method code
*
* @var string
*/
protected $_code = 'mollie_methods_applepay';

/**
* Info instructions block path
*
* @var string
*/
protected $_infoBlockType = 'Mollie\Payment\Block\Info\Base';
}
9 changes: 6 additions & 3 deletions Model/MollieConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class MollieConfigProvider implements ConfigProviderInterface
'mollie_methods_klarnasliceit',
'mollie_methods_giftcard',
'mollie_methods_przelewy24',
'mollie_methods_applepay',
];
/**
* @var array
Expand Down Expand Up @@ -207,9 +208,11 @@ public function getActiveMethods($mollieApi)
try {
$quote = $this->checkoutSession->getQuote();
$amount = $this->mollieHelper->getOrderAmountByQuote($quote);
$params = ["amount[value]" => $amount['value'],
"amount[currency]" => $amount['currency'],
"resource" => "orders"
$params = [
'amount[value]' => $amount['value'],
'amount[currency]' => $amount['currency'],
'resource' => 'orders',
'includeWallets' => 'applepay',
];
$apiMethods = $mollieApi->methods->all($params);

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ Mollie requires no minimum costs, no fixed contracts, no hidden costs. At Mollie

- Klarna

- Giftcards
- Giftcards

- Apple Pay

## Configuration, FAQ and Troubleshooting ##
If you experience problems with the extension installation, setup or whenever you need more information about how to setup the Mollie Payment extension in Magento 2.x, please see our [WIKI Page](https://github.com/mollie/magento2/wiki) or send an e-mail to [info@mollie.com](mailto:info@mollie.com) with an exact description of the problem.
Expand Down
1 change: 1 addition & 0 deletions etc/adminhtml/methods.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
<include path="Mollie_Payment::methods/paymentlink.xml"/>
<include path="Mollie_Payment::methods/giftcard.xml"/>
<include path="Mollie_Payment::methods/przelewy24.xml"/>
<include path="Mollie_Payment::methods/applepay.xml"/>
</include>
92 changes: 92 additions & 0 deletions etc/adminhtml/methods/applepay.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8"?>
<include xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_include.xsd">
<group id="mollie_methods_applepay" translate="label" type="text" sortOrder="22" showInDefault="1"
showInWebsite="1" showInStore="1">
<label>Apple Pay</label>
<field id="active" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1"
showInStore="1">
<label>Enabled</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<config_path>payment/mollie_methods_applepay/active</config_path>
<comment><![CDATA[<strong>Please note: This payment method is only visible when the users device has Apple Pay enabled.</strong>]]></comment>
</field>
<field id="title" translate="label" type="text" sortOrder="2" showInDefault="1" showInWebsite="1"
showInStore="1">
<label>Title</label>
<config_path>payment/mollie_methods_applepay/title</config_path>
<depends>
<field id="active">1</field>
</depends>
</field>
<field id="method" translate="label" type="select" sortOrder="3" showInDefault="1" showInWebsite="1"
showInStore="1">
<label>Method</label>
<source_model>Mollie\Payment\Model\Adminhtml\Source\Method</source_model>
<config_path>payment/mollie_methods_applepay/method</config_path>
<depends>
<field id="active">1</field>
</depends>
<comment><![CDATA[<strong>Payment API</strong><br>Use the Payment API Platform for the transactions.<br><br>
<strong>Order API</strong><br>Use the new Order API Platform and get additional insights in the orders.
Read <a href="https://docs.mollie.com/orders/why-use-orders" target="_blank" >more.</a>]]></comment>
</field>
<field id="payment_description" translate="label" type="text" sortOrder="4" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Description</label>
<config_path>payment/mollie_methods_applepay/payment_description</config_path>
<comment><![CDATA[The description to be used for this transaction. These variables are available:<br><br>
<strong>{ordernumber}</strong>: The order number for this transaction<br>
<strong>{storename}</strong>: The name of the store<br><br>
(Note: This only works when the method is set to Payments API)
]]></comment>
<depends>
<field id="method">payment</field>
<field id="active">1</field>
</depends>
</field>
<field id="allowspecific" translate="label" type="allowspecific" sortOrder="96" showInDefault="1"
showInWebsite="1" showInStore="1">
<label>Payment from Applicable Countries</label>
<source_model>Magento\Payment\Model\Config\Source\Allspecificcountries</source_model>
<config_path>payment/mollie_methods_applepay/allowspecific</config_path>
<depends>
<field id="active">1</field>
</depends>
</field>
<field id="specificcountry" translate="label" type="multiselect" sortOrder="97" showInDefault="1"
showInWebsite="1" showInStore="1">
<label>Payment from Specific Countries</label>
<source_model>Magento\Directory\Model\Config\Source\Country</source_model>
<can_be_empty>1</can_be_empty>
<config_path>payment/mollie_methods_applepay/specificcountry</config_path>
<depends>
<field id="active">1</field>
</depends>
</field>
<field id="min_order_total" translate="label" type="text" sortOrder="98" showInDefault="1" showInWebsite="1"
showInStore="1">
<label>Minimum Order Total</label>
<config_path>payment/mollie_methods_applepay/min_order_total</config_path>
<depends>
<field id="active">1</field>
</depends>
</field>
<field id="max_order_total" translate="label" type="text" sortOrder="99" showInDefault="1" showInWebsite="1"
showInStore="1">
<label>Maximum Order Total</label>
<config_path>payment/mollie_methods_applepay/max_order_total</config_path>
<depends>
<field id="active">1</field>
</depends>
</field>
<field id="sort_order" translate="label" type="text" sortOrder="100" showInDefault="1" showInWebsite="1"
showInStore="1">
<label>Sort Order</label>
<frontend_class>validate-number</frontend_class>
<config_path>payment/mollie_methods_applepay/sort_order</config_path>
<depends>
<field id="active">1</field>
</depends>
</field>
</group>
</include>
9 changes: 9 additions & 0 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,15 @@
<allowspecific>0</allowspecific>
<instructions/>
</mollie_methods_przelewy24>
<mollie_methods_applepay>
<active>0</active>
<model>Mollie\Payment\Model\Methods\ApplePay</model>
<title>Apple Pay</title>
<payment_description>{ordernumber}</payment_description>
<payment_action>order</payment_action>
<allowspecific>0</allowspecific>
<instructions/>
</mollie_methods_applepay>
</payment>
</default>
</config>
3 changes: 3 additions & 0 deletions etc/payment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,8 @@
<method name="mollie_methods_przelewy24">
<allow_multiple_address>0</allow_multiple_address>
</method>
<method name="mollie_methods_applepay">
<allow_multiple_address>0</allow_multiple_address>
</method>
</methods>
</payment>
3 changes: 3 additions & 0 deletions view/frontend/layout/checkout_index_index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@
<item name="mollie_methods_przelewy24" xsi:type="array">
<item name="isBillingAddressRequired" xsi:type="boolean">true</item>
</item>
<item name="mollie_methods_applepay" xsi:type="array">
<item name="isBillingAddressRequired" xsi:type="boolean">true</item>
</item>
</item>
</item>
</item>
Expand Down
11 changes: 11 additions & 0 deletions view/frontend/web/js/view/payment/method-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ define(
{type: 'mollie_methods_giftcard', component: giftcardComponent},
{type: 'mollie_methods_przelewy24', component: defaultComponent}
];

/**
* Only add Apple Pay if the current client supports Apple Pay.
*/
if (window.ApplePaySession && window.ApplePaySession.canMakePayments()) {
methods.push({
type: 'mollie_methods_applepay',
component: defaultComponent
});
}

$.each(methods, function (k, method) {
if (window.checkoutConfig.payment.isActive[method['type']]) {
rendererList.push(method);
Expand Down

0 comments on commit 329a2d3

Please sign in to comment.