Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CashApp Pay #968

Merged
merged 2 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,8 @@ function getAmazonpayConfig() {
};
}

function getApplePayConfig() {
// Used for Apple Pay and Cash App
function getPaymentFromComponentDefaultConfig() {
return {
showPayButton: true,
onSubmit: (state, component) => {
Expand Down Expand Up @@ -367,10 +368,11 @@ function setCheckoutConfiguration() {
paypal: getPaypalConfig(),
amazonpay: getAmazonpayConfig(),
giftcard: getGiftCardConfig(),
applepay: getApplePayConfig(),
applepay: getPaymentFromComponentDefaultConfig(),
klarna: getKlarnaConfig(),
klarna_account: getKlarnaConfig(),
klarna_paynow: getKlarnaConfig(),
cashapp: getPaymentFromComponentDefaultConfig(),
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const store = require('../../../../store');
const constants = require('../constants');

function assignPaymentMethodValue() {
const adyenPaymentMethod = document.querySelector('#adyenPaymentMethodName');
Expand Down Expand Up @@ -39,7 +40,7 @@ function paymentFromComponent(data, component = {}) {
setOrderFormData(response);
if (response.fullResponse?.action) {
component.handleAction(response.fullResponse.action);
} else if (response.isApplePay) {
} else if (response.skipSummaryPage) {
document.querySelector('#result').value = JSON.stringify(response);
document.querySelector('#showConfirmationForm').submit();
} else if (response.paymentError || response.error) {
Expand Down Expand Up @@ -72,13 +73,7 @@ function displaySelectedMethod(type) {
: type;
resetPaymentMethod();

const disabledSubmitButtonMethods = [
'paypal',
'paywithgoogle',
'googlepay',
'amazonpay',
'applepay',
];
const disabledSubmitButtonMethods = constants.DISABLED_SUBMIT_BUTTON_METHODS;
if (window.klarnaWidgetEnabled) {
disabledSubmitButtonMethods.push('klarna');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ module.exports = {
ACTIONTYPE: {
QRCODE: 'qrCode',
},
DISABLED_SUBMIT_BUTTON_METHODS: [
'paypal',
'paywithgoogle',
'googlepay',
'amazonpay',
'applepay',
'cashapp',
],
APPLE_DOMAIN_URL:
'/.well-known/apple-developer-merchantid-domain-association',
};
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Payment from Component should authorize express payment 1`] = `
exports[`Payment from Component should authorize express payment with skipping summary page 1`] = `
[
[
{
"isApplePay": true,
"orderNo": "mocked_orderNo",
"orderToken": "mocked_orderToken",
"resultCode": "Authorised",
"skipSummaryPage": true,
},
],
]
Expand All @@ -27,10 +27,10 @@ exports[`Payment from Component should return json response 1`] = `
[
[
{
"isApplePay": true,
"orderNo": "mocked_orderNo",
"orderToken": "mocked_orderToken",
"resultCode": "Authorised",
"skipSummaryPage": false,
},
],
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ describe('Payment from Component', () => {
paymentFromComponent(req, res, jest.fn());
expect(res.json.mock.calls).toMatchSnapshot();
});
it('should authorize express payment', () => {
it('should authorize express payment with skipping summary page', () => {
req.form.data.paymentMethod.type = 'applepay';
req.form.data.paymentMethod.paymentType = 'express';
req.form.data = JSON.stringify(req.form.data);
paymentFromComponent(req, res, jest.fn());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@ function handleExpressPayment(reqDataObj, currentBasket) {
}
}

function canSkipSummaryPage(reqDataObj) {
if (
constants.CAN_SKIP_SUMMARY_PAGE.indexOf(reqDataObj.paymentMethod?.type) >= 0
) {
return true;
}

return false;
}

/**
* Make a payment from inside a component, skipping the summary page. (paypal, QRcodes, MBWay)
*/
Expand Down Expand Up @@ -213,9 +223,8 @@ function paymentFromComponent(req, res, next) {
handleRefusedResultCode(result, reqDataObj, order);
}

if (AdyenHelper.isApplePay(reqDataObj.paymentMethod?.type)) {
result.isApplePay = true;
}
// Check if summary page can be skipped in case payment is already authorized
result.skipSummaryPage = canSkipSummaryPage(reqDataObj);

result.orderNo = order.orderNo;
result.orderToken = order.orderToken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ function handlePayment(stateData, order, options) {
if (
result &&
(JSON.stringify(result).indexOf('amazonpay') > -1 ||
JSON.stringify(result).indexOf('applepay') > -1)
JSON.stringify(result).indexOf('applepay') > -1 ||
JSON.stringify(result).indexOf('cashapp') > -1)
) {
finalResult = JSON.parse(result);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ module.exports = {
AMAZONPAY: 'amazonpay',
},

CAN_SKIP_SUMMARY_PAGE: ['applepay','cashapp',],

PLATFORMS: {
SFRA: 'SFRA',
SG: 'SG'
Expand Down Expand Up @@ -96,7 +98,7 @@ module.exports = {
CHECKOUT_ENVIRONMENT_LIVE_IN: 'live-in',

CHECKOUT_COMPONENT_VERSION: {
SFRA: '5.40.0',
SFRA: '5.44.0',
SG: '5.28.0'
},
VERSION: '23.2.1',
Expand Down
Loading