Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. const tempApp = actionssdk({ clientId: CLIENT_ID});
  2.  
  3. tempApp.intent('actions.intent.TRANSACTION_DECISION', async (conv) => {
  4. console.log('Transaction decision complete');
  5. const arg = conv.arguments.get('TRANSACTION_DECISION_VALUE');
  6. console.log('arg.userDecision==========>>>>>>>>>>>>>>>', arg.userDecision);
  7. if (arg && arg.userDecision ==='ORDER_ACCEPTED') {
  8. const finalOrderId = arg.order.finalOrder.id;
  9. console.log('finalOrderId===============>>>>>>>>>>>>',finalOrderId);
  10. let stripeToken = JSON.parse(JSON.stringify(Base64.decode(arg.order.paymentInfo.googleProvidedPaymentInstrument.instrumentToken)));
  11. stripeToken = JSON.parse(stripeToken);
  12.  
  13. console.log('arg.order.paymentInfo----------------->>>>>>>', stripeToken);
  14.  
  15. // await conv.ask('Your transaction is being processed, please wait.');
  16.  
  17. const platformSession = await PlatformSession.findOne({psid: conv.body.user.userId}).select('activeSessionId').lean().exec();
  18. const chatSession = await ChatSession.findOne({_id:platformSession.activeSessionId}).exec();
  19.  
  20. const charge = await createCharge(stripeToken, chatSession);
  21.  
  22. conv.channel = 'ga';
  23. conv.handshake = {
  24. query: {
  25. psid: conv.body.user.userId,
  26. ver: 1.1,
  27. brandName: BRAND_NAME,
  28. channel: 'ga',
  29. platformName: 'ga'
  30. },
  31. headers: {
  32. 'user-agent': '',
  33. origin: '',
  34. host: '',
  35. },
  36. };
  37.  
  38. console.log('conv.data********************&&&&&&&&&&&&&***************', conv.data);
  39. if(charge && charge.id){
  40. chatSession.context_variables.authorizationStatusState = 'Accepted';
  41. chatSession.context_variables.chargeResponse = charge;
  42. chatSession.context_variables.googleToken = stripeToken;
  43. await chatSession.save();
  44. continue_last_workflow(conv, chatSession);
  45. conv.ask('Do you want an email confirmation for the booking?');
  46. }
  47. else{
  48. chatSession.context_variables.authorizationStatusState = 'Declined';
  49. chatSession.context_variables.googleToken = stripeToken;
  50. await chatSession.save();
  51. conv.data.orderBuilt = true;
  52. continue_last_workflow(conv, chatSession);
  53. conv.ask('Transaction Failed');
  54. }
  55. }
  56. else if (arg && arg.userDecision === 'DELIVERY_ADDRESS_UPDATED') {
  57. conv.ask(new DeliveryAddress({
  58. addressOptions: {
  59. reason: 'To know where to send the order',
  60. },
  61. }));
  62. } else {
  63. conv.close('Transaction failed.');
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement