init
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?xml version="1.0"?>
|
||||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
|
||||
<body>
|
||||
<referenceBlock name="checkout.root">
|
||||
<arguments>
|
||||
<argument name="jsLayout" xsi:type="array">
|
||||
<item name="components" xsi:type="array">
|
||||
<item name="checkout" xsi:type="array">
|
||||
<item name="children" xsi:type="array">
|
||||
<item name="steps" xsi:type="array">
|
||||
<item name="children" xsi:type="array">
|
||||
<item name="billing-step" xsi:type="array">
|
||||
<item name="children" xsi:type="array">
|
||||
<item name="payment" xsi:type="array">
|
||||
<item name="children" xsi:type="array">
|
||||
<item name="renders" xsi:type="array">
|
||||
<item name="children" xsi:type="array">
|
||||
<item name="esun_oceanpayment" xsi:type="array">
|
||||
<item name="component" xsi:type="string">Esun_Oceanpayment/js/view/payment/qianhai</item>
|
||||
<item name="methods" xsi:type="array">
|
||||
<item name="esun_oceanpayment" xsi:type="array">
|
||||
<item name="isBillingAddressRequired" xsi:type="boolean">true</item>
|
||||
</item>
|
||||
<item name="esun_oceanpayment_onepage" xsi:type="array">
|
||||
<item name="isBillingAddressRequired" xsi:type="boolean">true</item>
|
||||
</item>
|
||||
</item>
|
||||
</item>
|
||||
</item>
|
||||
</item>
|
||||
</item>
|
||||
</item>
|
||||
</item>
|
||||
</item>
|
||||
</item>
|
||||
</item>
|
||||
</item>
|
||||
</item>
|
||||
</item>
|
||||
</argument>
|
||||
</arguments>
|
||||
</referenceBlock>
|
||||
</body>
|
||||
</page>
|
||||
@@ -0,0 +1,10 @@
|
||||
var config = {
|
||||
paths: {
|
||||
oceanpaymentSdk: 'https://secure.oceanpayment.com/pages/js/oceanpayment'
|
||||
},
|
||||
shim: {
|
||||
oceanpaymentSdk: {
|
||||
exports: 'Oceanpayment'
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,8 @@
|
||||
#oceanpayment-element {
|
||||
min-height: 180px;
|
||||
|
||||
iframe {
|
||||
border: 0;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
+175
@@ -0,0 +1,175 @@
|
||||
define([
|
||||
'jquery',
|
||||
'ko',
|
||||
'Magento_Checkout/js/view/payment/default',
|
||||
'mage/translate',
|
||||
'oceanpaymentSdk'
|
||||
], function ($, ko, Component, $t, Oceanpayment) {
|
||||
'use strict';
|
||||
|
||||
return Component.extend({
|
||||
defaults: {
|
||||
template: 'Esun_Oceanpayment/payment/onepage'
|
||||
},
|
||||
|
||||
redirectAfterPlaceOrder: false,
|
||||
orderPlaced: ko.observable(false),
|
||||
processing: ko.observable(false),
|
||||
sdkInitialized: false,
|
||||
|
||||
initialize: function () {
|
||||
this._super();
|
||||
window.oceanpaymentCallBack = this.handleOceanpaymentResult.bind(this);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
initOceanpayment: function () {
|
||||
var methodConfig = window.checkoutConfig.payment.esun_oceanpayment_onepage;
|
||||
|
||||
if (this.sdkInitialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
Oceanpayment.init(Boolean(methodConfig.sandbox), '', methodConfig.language || '');
|
||||
this.sdkInitialized = true;
|
||||
} catch (error) {
|
||||
this.showError($t('Unable to load the secure Oceanpayment card form.'));
|
||||
}
|
||||
},
|
||||
|
||||
validate: function () {
|
||||
if (!this.sdkInitialized) {
|
||||
this.showError($t('The secure payment form is still loading. Please try again.'));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
afterPlaceOrder: function () {
|
||||
this.orderPlaced(true);
|
||||
this.submitPayment();
|
||||
},
|
||||
|
||||
retryPayment: function () {
|
||||
this.submitPayment();
|
||||
},
|
||||
|
||||
submitPayment: function () {
|
||||
var self = this,
|
||||
methodConfig = window.checkoutConfig.payment.esun_oceanpayment_onepage;
|
||||
|
||||
if (this.processing()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.processing(true);
|
||||
$.ajax({
|
||||
url: methodConfig.prepareUrl,
|
||||
type: 'GET',
|
||||
dataType: 'json',
|
||||
cache: false
|
||||
}).done(function (response) {
|
||||
if (!response.success || !response.payload) {
|
||||
self.processing(false);
|
||||
self.showError(response.message || $t('Payment initialization failed.'));
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
Oceanpayment.checkout(response.payload);
|
||||
} catch (error) {
|
||||
self.processing(false);
|
||||
self.showError($t('Payment initialization failed. Please try again.'));
|
||||
}
|
||||
}).fail(function (xhr) {
|
||||
var response = xhr.responseJSON || {};
|
||||
|
||||
self.processing(false);
|
||||
self.showError(response.message || $t('Payment initialization failed. Please try again.'));
|
||||
});
|
||||
},
|
||||
|
||||
handleOceanpaymentResult: function (data) {
|
||||
var xml = typeof data === 'string' ? data : '',
|
||||
documentNode,
|
||||
parserError,
|
||||
payUrl;
|
||||
|
||||
this.processing(false);
|
||||
if (xml === '') {
|
||||
this.showError((data && (data.message || data.error)) || $t('Oceanpayment returned an invalid response.'));
|
||||
return;
|
||||
}
|
||||
|
||||
documentNode = (new window.DOMParser()).parseFromString(xml, 'application/xml');
|
||||
parserError = documentNode.getElementsByTagName('parsererror');
|
||||
if (parserError.length) {
|
||||
this.showError($t('Oceanpayment returned an invalid response.'));
|
||||
return;
|
||||
}
|
||||
|
||||
payUrl = this.getXmlValue(documentNode, 'pay_url');
|
||||
if (payUrl !== '') {
|
||||
if (!this.isAllowedPaymentUrl(payUrl)) {
|
||||
this.showError($t('Oceanpayment returned an invalid redirect URL.'));
|
||||
return;
|
||||
}
|
||||
window.location.assign(payUrl);
|
||||
return;
|
||||
}
|
||||
|
||||
this.verifyResult(xml);
|
||||
},
|
||||
|
||||
verifyResult: function (xml) {
|
||||
var self = this,
|
||||
methodConfig = window.checkoutConfig.payment.esun_oceanpayment_onepage;
|
||||
|
||||
this.processing(true);
|
||||
$.ajax({
|
||||
url: methodConfig.resultUrl,
|
||||
type: 'POST',
|
||||
data: xml,
|
||||
processData: false,
|
||||
contentType: 'text/plain; charset=UTF-8',
|
||||
dataType: 'json'
|
||||
}).done(function (response) {
|
||||
if (response.success) {
|
||||
window.location.replace(methodConfig.successUrl);
|
||||
return;
|
||||
}
|
||||
|
||||
self.processing(false);
|
||||
self.showError(response.message || $t('Payment was not completed. Please try again.'));
|
||||
}).fail(function (xhr) {
|
||||
var response = xhr.responseJSON || {};
|
||||
|
||||
self.processing(false);
|
||||
self.showError(response.message || $t('The payment result could not be verified.'));
|
||||
});
|
||||
},
|
||||
|
||||
getXmlValue: function (documentNode, name) {
|
||||
var nodes = documentNode.getElementsByTagName(name);
|
||||
|
||||
return nodes.length ? String(nodes[0].textContent || '').trim() : '';
|
||||
},
|
||||
|
||||
isAllowedPaymentUrl: function (url) {
|
||||
var anchor = document.createElement('a'),
|
||||
hostname;
|
||||
|
||||
anchor.href = url;
|
||||
hostname = String(anchor.hostname || '').toLowerCase();
|
||||
|
||||
return anchor.protocol === 'https:' && /(^|\.)oceanpayment\.com$/.test(hostname);
|
||||
},
|
||||
|
||||
showError: function (message) {
|
||||
this.messageContainer.addErrorMessage({message: String(message)});
|
||||
}
|
||||
});
|
||||
});
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
define([
|
||||
'Magento_Checkout/js/view/payment/default'
|
||||
], function (Component) {
|
||||
'use strict';
|
||||
|
||||
return Component.extend({
|
||||
defaults: {
|
||||
template: 'Esun_Oceanpayment/payment/qianhai'
|
||||
},
|
||||
|
||||
redirectAfterPlaceOrder: false,
|
||||
|
||||
afterPlaceOrder: function () {
|
||||
window.location.replace(
|
||||
window.checkoutConfig.payment.esun_oceanpayment.redirectUrl
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,17 @@
|
||||
define([
|
||||
'uiComponent',
|
||||
'Magento_Checkout/js/model/payment/renderer-list'
|
||||
], function (Component, rendererList) {
|
||||
'use strict';
|
||||
|
||||
rendererList.push({
|
||||
type: 'esun_oceanpayment',
|
||||
component: 'Esun_Oceanpayment/js/view/payment/method-renderer/qianhai-method'
|
||||
});
|
||||
rendererList.push({
|
||||
type: 'esun_oceanpayment_onepage',
|
||||
component: 'Esun_Oceanpayment/js/view/payment/method-renderer/onepage-method'
|
||||
});
|
||||
|
||||
return Component.extend({});
|
||||
});
|
||||
@@ -0,0 +1,41 @@
|
||||
<div class="payment-method" data-bind="css: {'_active': (getCode() === isChecked())}">
|
||||
<div class="payment-method-title field choice">
|
||||
<input type="radio"
|
||||
name="payment[method]"
|
||||
class="radio"
|
||||
data-bind="attr: {'id': getCode()}, value: getCode(), checked: isChecked, click: selectPaymentMethod, visible: isRadioButtonVisible()">
|
||||
<label class="label" data-bind="attr: {'for': getCode()}">
|
||||
<span data-bind="text: getTitle()"></span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="payment-method-content">
|
||||
<!-- ko foreach: getRegion('messages') -->
|
||||
<!-- ko template: getTemplate() --><!-- /ko -->
|
||||
<!-- /ko -->
|
||||
<div class="payment-method-billing-address">
|
||||
<!-- ko foreach: $parent.getRegion(getBillingAddressFormName()) -->
|
||||
<!-- ko template: getTemplate() --><!-- /ko -->
|
||||
<!--/ko-->
|
||||
</div>
|
||||
<div id="oceanpayment-element" data-bind="afterRender: initOceanpayment"></div>
|
||||
<p data-bind="i18n: 'Card details are securely collected by Oceanpayment.'"></p>
|
||||
<div class="actions-toolbar">
|
||||
<div class="primary">
|
||||
<!-- ko ifnot: orderPlaced -->
|
||||
<button class="action primary checkout"
|
||||
type="submit"
|
||||
data-bind="click: placeOrder, attr: {title: $t('Place Order')}, enable: (getCode() === isChecked()) && !processing() && isPlaceOrderActionAllowed(), css: {disabled: processing() || !isPlaceOrderActionAllowed()}">
|
||||
<span data-bind="i18n: 'Place Order and Pay'"></span>
|
||||
</button>
|
||||
<!-- /ko -->
|
||||
<!-- ko if: orderPlaced -->
|
||||
<button class="action primary checkout"
|
||||
type="button"
|
||||
data-bind="click: retryPayment, enable: !processing(), css: {disabled: processing()}">
|
||||
<span data-bind="i18n: 'Pay Now'"></span>
|
||||
</button>
|
||||
<!-- /ko -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,31 @@
|
||||
<div class="payment-method" data-bind="css: {'_active': (getCode() === isChecked())}">
|
||||
<div class="payment-method-title field choice">
|
||||
<input type="radio"
|
||||
name="payment[method]"
|
||||
class="radio"
|
||||
data-bind="attr: {'id': getCode()}, value: getCode(), checked: isChecked, click: selectPaymentMethod, visible: isRadioButtonVisible()">
|
||||
<label class="label" data-bind="attr: {'for': getCode()}">
|
||||
<span data-bind="text: getTitle()"></span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="payment-method-content">
|
||||
<!-- ko foreach: getRegion('messages') -->
|
||||
<!-- ko template: getTemplate() --><!-- /ko -->
|
||||
<!-- /ko -->
|
||||
<div class="payment-method-billing-address">
|
||||
<!-- ko foreach: $parent.getRegion(getBillingAddressFormName()) -->
|
||||
<!-- ko template: getTemplate() --><!-- /ko -->
|
||||
<!--/ko-->
|
||||
</div>
|
||||
<p data-bind="i18n: 'You will be redirected to Oceanpayment to complete your payment.'"></p>
|
||||
<div class="actions-toolbar">
|
||||
<div class="primary">
|
||||
<button class="action primary checkout"
|
||||
type="submit"
|
||||
data-bind="click: placeOrder, attr: {title: $t('Place Order')}, enable: (getCode() === isChecked()), css: {disabled: !isPlaceOrderActionAllowed()}">
|
||||
<span data-bind="i18n: 'Place Order'"></span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user