Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const tempApp = actionssdk({ clientId: CLIENT_ID});
- tempApp.intent('actions.intent.TRANSACTION_DECISION', async (conv) => {
- console.log('Transaction decision complete');
- const arg = conv.arguments.get('TRANSACTION_DECISION_VALUE');
- console.log('arg.userDecision==========>>>>>>>>>>>>>>>', arg.userDecision);
- if (arg && arg.userDecision ==='ORDER_ACCEPTED') {
- const finalOrderId = arg.order.finalOrder.id;
- console.log('finalOrderId===============>>>>>>>>>>>>',finalOrderId);
- let stripeToken = JSON.parse(JSON.stringify(Base64.decode(arg.order.paymentInfo.googleProvidedPaymentInstrument.instrumentToken)));
- stripeToken = JSON.parse(stripeToken);
- console.log('arg.order.paymentInfo----------------->>>>>>>', stripeToken);
- // await conv.ask('Your transaction is being processed, please wait.');
- const platformSession = await PlatformSession.findOne({psid: conv.body.user.userId}).select('activeSessionId').lean().exec();
- const chatSession = await ChatSession.findOne({_id:platformSession.activeSessionId}).exec();
- const charge = await createCharge(stripeToken, chatSession);
- conv.channel = 'ga';
- conv.handshake = {
- query: {
- psid: conv.body.user.userId,
- ver: 1.1,
- brandName: BRAND_NAME,
- channel: 'ga',
- platformName: 'ga'
- },
- headers: {
- 'user-agent': '',
- origin: '',
- host: '',
- },
- };
- console.log('conv.data********************&&&&&&&&&&&&&***************', conv.data);
- if(charge && charge.id){
- chatSession.context_variables.authorizationStatusState = 'Accepted';
- chatSession.context_variables.chargeResponse = charge;
- chatSession.context_variables.googleToken = stripeToken;
- await chatSession.save();
- continue_last_workflow(conv, chatSession);
- conv.ask('Do you want an email confirmation for the booking?');
- }
- else{
- chatSession.context_variables.authorizationStatusState = 'Declined';
- chatSession.context_variables.googleToken = stripeToken;
- await chatSession.save();
- conv.data.orderBuilt = true;
- continue_last_workflow(conv, chatSession);
- conv.ask('Transaction Failed');
- }
- }
- else if (arg && arg.userDecision === 'DELIVERY_ADDRESS_UPDATED') {
- conv.ask(new DeliveryAddress({
- addressOptions: {
- reason: 'To know where to send the order',
- },
- }));
- } else {
- conv.close('Transaction failed.');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement