MCPcopy Index your code
hub / github.com/ampproject/amphtml / start

Method start

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

* Starts the payments completion flow. * @param {{ * productType: string, * oldSku: ?string, * paymentRecurrence: ?number, * }} response * @return {!Promise}

(response)

Source from the content-addressed store, hash-verified

5919 * @return {!Promise}
5920 */
5921 start(response) {
5922 this.sku_ = parseSkuFromPurchaseDataSafe(response.purchaseData);
5923 this.eventManager_.logSwgEvent(
5924 AnalyticsEvent.IMPRESSION_ACCOUNT_CHANGED,
5925 true,
5926 getEventParams$1(this.sku_ || '')
5927 );
5928 this.deps_.entitlementsManager().reset(true);
5929 // TODO(dianajing): future-proof isOneTime flag
5930 const args = {
5931 'publicationId': this.deps_.pageConfig().getPublicationId(),
5932 'productType': response['productType'],
5933 'isSubscriptionUpdate': !!response['oldSku'],
5934 'isOneTime': !!response['paymentRecurrence'],
5935 };
5936
5937 // TODO(dvoytenko, #400): cleanup once entitlements is launched everywhere.
5938 if (response.userData && response.entitlements) {
5939 args['idToken'] = response.userData.idToken;
5940 this.deps_
5941 .entitlementsManager()
5942 .pushNextEntitlements(response.entitlements.raw);
5943 // Persist swgUserToken in local storage
5944 if (response.swgUserToken) {
5945 this.deps_
5946 .storage()
5947 .set(Constants$1.USER_TOKEN, response.swgUserToken, true);
5948 }
5949 } else {
5950 args['loginHint'] = response.userData && response.userData.email;
5951 }
5952
5953 const /* {!Object<string, string>} */ urlParams = {};
5954 if (args.productType === ProductType.VIRTUAL_GIFT) {
5955 Object.assign(urlParams, {
5956 productType: args.productType,
5957 publicationId: args.publicationId,
5958 offerId: this.sku_,
5959 origin: parseUrl(this.win_.location.href).origin,
5960 isPaid: true,
5961 checkOrderStatus: true,
5962 });
5963 if (response.requestMetadata) {
5964 urlParams.canonicalUrl = response.requestMetadata.contentId;
5965 urlParams.isAnonymous = response.requestMetadata.anonymous;
5966 args['contentTitle'] = response.requestMetadata.contentTitle;
5967 }
5968
5969 // Add feArgs to be passed via activities.
5970 if (response.swgUserToken) {
5971 args.swgUserToken = response.swgUserToken;
5972 }
5973 const orderId = parseOrderIdFromPurchaseDataSafe(response.purchaseData);
5974 if (orderId) {
5975 args.orderId = orderId;
5976 }
5977 }
5978 if (this.clientConfigManager_.shouldForceLangInIframes()) {

Callers 2

configurePendingMethod · 0.95

Calls 15

getEventParams$1Function · 0.85
feUrlFunction · 0.85
feArgsFunction · 0.85
logSwgEventMethod · 0.80
entitlementsManagerMethod · 0.80
getPublicationIdMethod · 0.80
pageConfigMethod · 0.80
pushNextEntitlementsMethod · 0.80
storageMethod · 0.80
assignMethod · 0.80

Tested by

no test coverage detected