Skip to content

Commit 30261d3

Browse files
author
Sundus Abdullah
authored
Support Apple Pay Web Registration
* Update Moyasar form * Remove AP section from admin panel * Add AP web reg * Change AP label * Update Moyasar form 1.5.6 * Remove ApplePay folder * Remove validateApplePayMerchant method
1 parent 07705d2 commit 30261d3

File tree

8 files changed

+12
-225
lines changed

8 files changed

+12
-225
lines changed

Moyasar/Mysr/Controller/ApplePay/Validate.php

Lines changed: 0 additions & 106 deletions
This file was deleted.

Moyasar/Mysr/Helper/MoyasarHelper.php

Lines changed: 2 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -367,91 +367,17 @@ public function fetchMoyasarPayment($paymentId)
367367
return @json_decode($this->_curl->getBody(), true);
368368
}
369369

370-
public function getMerchantCertificatePath()
371-
{
372-
return $this->getFilePath('payment/moyasar_apple_pay/validate_merchant_cert');
373-
}
374-
375-
public function getMerchantCertificateKeyPath()
376-
{
377-
return $this->getFilePath('payment/moyasar_apple_pay/validate_merchant_pk');
378-
}
379-
380-
protected function getFilePath($key)
381-
{
382-
$varDir = $this->directoryList->getPath(DirectoryList::VAR_DIR);
383-
$moyasarUploadDir = 'moyasar/applepay/certificates';
384-
$path = $this->scopeConfig->getValue($key, ScopeInterface::SCOPE_STORE);
385-
386-
return "$varDir/$moyasarUploadDir/$path";
387-
}
388-
389-
public function getMerchantCertificateKeyPassword()
390-
{
391-
$password = $this->scopeConfig->getValue('payment/moyasar_apple_pay/validate_merchant_pk_password', ScopeInterface::SCOPE_STORE);
392-
393-
if (!is_string($password)) {
394-
return '';
395-
}
396-
397-
return $password;
398-
}
399-
400-
public function getMerchantApplePayIdentifier()
401-
{
402-
return $this->scopeConfig->getValue('payment/moyasar_apple_pay/merchant_id', ScopeInterface::SCOPE_STORE);
403-
}
404-
405370
protected function getCurrentStoreName()
406371
{
407372
return $this->storeManager->getStore()->getName();
408373
}
409-
410-
protected function getInitiativeContext()
374+
375+
public function getInitiativeContext()
411376
{
412377
$baseUrl = $this->storeManager->getStore()->getBaseUrl();
413378
if (preg_match('/^.+:\/\/([A-Za-z0-9\-\.]+)\/?.*$/', $baseUrl, $matches) !== 1) {
414-
return $this->getMerchantApplePayIdentifier();
415379
}
416380

417381
return $matches[1];
418382
}
419-
420-
public function validateApplePayMerchant($validationUrl)
421-
{
422-
if (!$validationUrl) {
423-
return null;
424-
}
425-
426-
$body = [
427-
'merchantIdentifier' => $this->getMerchantApplePayIdentifier(),
428-
'displayName' => $this->getCurrentStoreName(),
429-
'initiative' => 'web',
430-
'initiativeContext' => $this->getInitiativeContext()
431-
];
432-
433-
$this->_curl->setOptions([
434-
CURLOPT_SSL_VERIFYPEER => true,
435-
CURLOPT_SSLCERT => $this->getMerchantCertificatePath(),
436-
CURLOPT_SSLKEY => $this->getMerchantCertificateKeyPath(),
437-
CURLOPT_SSLKEYPASSWD => $this->getMerchantCertificateKeyPassword(),
438-
CURLOPT_RETURNTRANSFER => true
439-
]);
440-
441-
try {
442-
$this->_curl->post($validationUrl, json_encode($body));
443-
} catch (Exception $e) {
444-
$this->_logger->warning('Could not validate merchant with Apple, error: ' . $e->getMessage());
445-
return null;
446-
}
447-
448-
if ($this->_curl->getStatus() > 299) {
449-
$this->_logger->warning('Error while trying to validate merchant ' . $this->_curl->getStatus(), [
450-
'response' => @json_decode($this->_curl->getBody(), true)
451-
]);
452-
return null;
453-
}
454-
455-
return @json_decode($this->_curl->getBody());
456-
}
457383
}

Moyasar/Mysr/Model/PaymentConfigProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ public function getConfig()
6767
'payment_url' => $this->moyasarHelper->buildMoyasarUrl('payments'),
6868
'country' => $this->scopeConfig->getValue('general/country/default'),
6969
'store_name' => $this->storeManager->getStore()->getName(),
70-
'methods' => $this->moyasarHelper->methodEnabled()
70+
'methods' => $this->moyasarHelper->methodEnabled(),
71+
'domain_name' => $this->moyasarHelper->getInitiativeContext()
7172
]
7273
];
7374
}

Moyasar/Mysr/etc/adminhtml/system.xml

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -56,35 +56,6 @@
5656
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
5757
</field>
5858
</group>
59-
60-
61-
<!-- Apple Pay -->
62-
<group id="moyasar_apple_pay" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="3" translate="label">
63-
<label>Apple Pay Configuration</label>
64-
65-
<field id="merchant_id" translate="label" type="text" sortOrder="30" showInDefault="1"
66-
showInWebsite="1" showInStore="0">
67-
<label>Apple Pay Merchant ID</label>
68-
<comment>Used for initiating Apple Pay Sessions</comment>
69-
</field>
70-
<field id="validate_merchant_cert" translate="label" type="Magento\Framework\Data\Form\Element\File" sortOrder="39" showInDefault="1" showInWebsite="0" >
71-
<label>Validation Certificate</label>
72-
<backend_model>Moyasar\Mysr\Model\Config\ApplePayCertificateFile</backend_model>
73-
<upload_dir config="system" scope_info="1">moyasar/applepay/certificates</upload_dir>
74-
<comment>Used for initiating Apple Pay Sessions</comment>
75-
</field>
76-
<field id="validate_merchant_pk" translate="label" type="Magento\Framework\Data\Form\Element\File" sortOrder="40" showInDefault="1" showInWebsite="0" >
77-
<label>Certificate Private Key</label>
78-
<backend_model>Moyasar\Mysr\Model\Config\ApplePayCertificateFile</backend_model>
79-
<upload_dir config="system" scope_info="1">moyasar/applepay/certificates</upload_dir>
80-
<comment>Used for initiating Apple Pay Sessions</comment>
81-
</field>
82-
<field id="validate_merchant_pk_password" translate="label" type="text" sortOrder="30" showInDefault="1"
83-
showInWebsite="1" showInStore="0">
84-
<label>Private Key Password</label>
85-
<comment>Used for initiating Apple Pay Sessions, Only set if there is a password for your private key</comment>
86-
</field>
87-
</group>
8859
</section>
8960
</system>
9061
</config>

Moyasar/Mysr/etc/config.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@
1818
<stc_pay>0</stc_pay>
1919
<apple_pay>0</apple_pay>
2020
</moyasar_online_payment>
21-
22-
<moyasar_apple_pay>
23-
<active>0</active>
24-
<model>Moyasar\Mysr\Model\Payment\MoyasarApplePay</model>
25-
<order_status>pending_payment</order_status>
26-
<title>Apple Pay</title>
27-
<sort_order>0</sort_order>
28-
</moyasar_apple_pay>
2921
</payment>
3022
</default>
3123
</config>

Moyasar/Mysr/view/frontend/web/css/moyasar.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Moyasar/Mysr/view/frontend/web/js/model/moyasar.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Moyasar/Mysr/view/frontend/web/js/view/payment/method-renderer/moyasar_online_payment_method.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ define(
5656
on_completed: this.onCompleted.bind(this),
5757
on_failure: this.onFailure.bind(this),
5858
apple_pay: {
59-
label: this.getStoreName(),
60-
validate_merchant_url: this.getValidationUrl(),
59+
label: this.getDomain(),
60+
validate_merchant_url: 'https://api.moyasar.com/v1/applepay/initiate',
6161
country: this.getCountry()
6262
},
6363
});
@@ -88,6 +88,9 @@ define(
8888
getApiKey: function () {
8989
return window.checkoutConfig.moyasar_online_payment.api_key;
9090
},
91+
getDomain: function () {
92+
return window.checkoutConfig.moyasar_online_payment.domain_name;
93+
},
9194
getAmount: function () {
9295
return parseFloat(quote.totals()['base_grand_total']).toFixed(2);
9396
},

0 commit comments

Comments
 (0)