MCPcopy Create free account
hub / github.com/ampproject/amphtml / validatePayResponse

Function validatePayResponse

third_party/subscriptions-project/swg.js:6084–6129  ·  view source on GitHub ↗

* @param {!./deps.DepsDef} deps * @param {!Promise<!Object>} payPromise * @param {function():!Promise} completeHandler * @return {!Promise<!SubscribeResponse>}

(deps, payPromise, completeHandler)

Source from the content-addressed store, hash-verified

6082 * @return {!Promise<!SubscribeResponse>}
6083 */
6084function validatePayResponse(deps, payPromise, completeHandler) {
6085 const wasRedirect = !PayCompleteFlow.waitingForPayClient_;
6086 PayCompleteFlow.waitingForPayClient_ = false;
6087 return payPromise.then((data) => {
6088 // 1) We log against a random TX ID which is how we track a specific user
6089 // anonymously.
6090 // 2) If there was a redirect to gPay, we may have lost our stored TX ID.
6091 // 3) Pay service is supposed to give us the TX ID it logged against.
6092 let eventType = AnalyticsEvent.UNKNOWN;
6093 let eventParams = undefined;
6094 if (typeof data !== 'object' || !data['googleTransactionId']) {
6095 // If gPay doesn't give us a TX ID it means that something may
6096 // be wrong. If we previously logged then we are at least continuing to
6097 // log against the same TX ID. If we didn't previously log then we have
6098 // lost all connection to the events that preceded the payment event and
6099 // we at least want to know why that data was lost.
6100 eventParams = new EventParams();
6101 eventParams.setHadLogged(!wasRedirect);
6102 eventType = AnalyticsEvent.EVENT_GPAY_NO_TX_ID;
6103 } else {
6104 const oldTxId = deps.analytics().getTransactionId();
6105 const newTxId = data['googleTransactionId'];
6106
6107 if (wasRedirect) {
6108 // This is the expected case for full redirects. It may be happening
6109 // unexpectedly at other times too though and we want to be aware of
6110 // it if it does.
6111 deps.analytics().setTransactionId(newTxId);
6112 eventType = AnalyticsEvent.EVENT_GPAY_CANNOT_CONFIRM_TX_ID;
6113 } else {
6114 if (oldTxId === newTxId) {
6115 // This is the expected case for non-redirect pay events
6116 eventType = AnalyticsEvent.EVENT_CONFIRM_TX_ID;
6117 } else {
6118 // This is an unexpected case: gPay rejected our TX ID and created
6119 // its own. Log the gPay TX ID but keep our logging consistent.
6120 eventParams = new EventParams();
6121 eventParams.setGpayTransactionId(newTxId);
6122 eventType = AnalyticsEvent.EVENT_CHANGED_TX_ID;
6123 }
6124 }
6125 }
6126 deps.eventManager().logSwgEvent(eventType, true, eventParams);
6127 return parseSubscriptionResponse(deps, data, completeHandler);
6128 });
6129}
6130
6131/**
6132 * @param {!./deps.DepsDef} deps

Callers 1

configurePendingMethod · 0.85

Calls 9

setHadLoggedMethod · 0.80
analyticsMethod · 0.80
setGpayTransactionIdMethod · 0.80
logSwgEventMethod · 0.80
eventManagerMethod · 0.80
thenMethod · 0.45
getTransactionIdMethod · 0.45
setTransactionIdMethod · 0.45

Tested by

no test coverage detected