hansemannn / titanium-apple-pay

💰 Support for iOS Apple Pay in Titanium

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Apple Pay dialog stucks at "Processing"

yuranevmer opened this issue · comments

Hello.
I got strange behaviour - Apple Pay dialog sometimes stucks at "Processing".
Logs shows that didAuthorizePayment event was not triggered:

[DEBUG] Ti.ApplePay: No payment provider selected, using own gateway.
[DEBUG] Ti.ApplePay: didSelectPayment

Checked on both - simulator and real device.
Merchant ID was properly setted.
Also checked with module's example/app.js.

Did you faced same issues?

Here is my example code.

function doClick(e) {
	const ApplePay = require('ti.applepay');
	ApplePay.setupPaymentGateway({});
	//Summary items
	let data = {
		value: 100,
		value_price: 100,
	};
	const company = 'ООО "Ливайн Торг"';
	const items = [{
		title: `a96`,
		price: 100
	}];
	const summaryItems = items.map(item => ApplePay.createSummaryItem({
		itemType: ApplePay.PAYMENT_SUMMARY_ITEM_TYPE_FINAL,
		title: item.title,
		price: item.price
	}));
	const totalPrice = items.reduce((sum, el) => sum + el.price, 0);

	// The native Apple Pay API receives the total as a summary item that
	// usually holds the company name and total price of the order.
	const summary = ApplePay.createSummaryItem({
		itemType: ApplePay.PAYMENT_SUMMARY_ITEM_TYPE_FINAL,
		title: company,
		price: totalPrice
	});

	summaryItems.push(summary);

	const paymentRequest = ApplePay.createPaymentRequest({
		merchantIdentifier: 'merchant.ua.com.avias.app',
		merchantCapabilities: ApplePay.MERCHANT_CAPABILITY_3DS,
		countryCode: 'UA',
		currencyCode: 'UAH',
		supportedNetworks: [ApplePay.PAYMENT_NETWORK_VISA, ApplePay.PAYMENT_NETWORK_MASTERCARD],
		summaryItems: summaryItems,
		applicationData: {
			userId: 24
		}
	});

	let paymentResult;
	const paymentDialog = ApplePay.createPaymentDialog({ paymentRequest });
	paymentDialog.addEventListener('didSelectPayment', didSelectPayment);
	paymentDialog.addEventListener('willAuthorizePayment', willAuthorizePayment);
	paymentDialog.addEventListener('didAuthorizePayment', didAuthorizePayment);
	

	paymentDialog.addEventListener('close', willClose);
	paymentDialog.show();

	function didSelectPayment(e) {
		Ti.API.debug("didSelectPayment");
		e.handler.complete(paymentRequest.summaryItems);
	}

	function willAuthorizePayment(e) {
		Ti.API.debug("willAuthorizePayment");
	}

	function didAuthorizePayment(e) {
		Ti.API.debug("didAuthorizePayment");
		// paymentResult = e.payment;
		e.handler.complete(ApplePay.PAYMENT_AUTHORIZATION_STATUS_SUCCESS);
		//send to server
	}

	function willClose(e) {
		Ti.API.debug("willClose");
		// handle cancelled payment
		if (!paymentResult) {
			// cb({cancelled: true});
		}
	}
}