Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Calls the LINE Pay API and "reserves" a payment transaction
- * It wil also redirect to the LINE Pay screen
- * */
- async Reserve(userProfile)
- {
- console.log("");
- console.log("linepaymodule.Reserve");
- /*
- * These are the URLs that need to be put into a webview
- * These will be the URLs the app will redirect to when the user
- * either confirms or cancels the payment at the LINE Pay service
- * */
- let queryString = this.PrepareQueryString(userProfile);
- //Change to LIFF URL here
- //confirmURL = 'line://app/1595088973-yBZmjZ6M' + "?" + queryString;
- let confirmURL = process.env.BASE_URL + "/linepay_service/confirm";
- let cancelURL = process.env.BASE_URL + "/linepay_service/cancel";
- confirmURL = confirmURL + "?" + queryString;
- cancelURL = cancelURL + "?" + queryString;
- let sqlvariables = [
- userProfile.botID,
- userProfile.userID,
- userProfile.language
- ];
- try
- {
- /*
- * Get the cart contents from the database
- * It should be a specialized JSON, as LINE Pay has a specific JSON style to follow
- * */
- let returnedValue = await dbModule.useDBFunction(dbModule.SQLStrings.view_cart, sqlvariables);
- console.log(JSON.stringify(returnedValue));
- //For debugging purposes, this will be the JSON returned for now
- let jsonReturned = {
- "amount" : 100,
- "currency" : "USD",
- "orderId" : "MKSI_S_20180904_1000001",
- "packages" : [
- {
- "id" : "1",
- "amount": 100,
- "products" : [
- {
- "name" : "Pen Brown",
- "quantity" : 2,
- "price" : 50
- }
- ]
- }
- ],
- "redirectUrls" : {
- "confirmUrl" : confirmURL,
- "cancelUrl" : cancelURL
- }
- };
- jsonReturned.redirectUrls.confirmUrl = confirmURL;
- jsonReturned.redirectUrls.confirmUrl = cancelURL;
- //To skip CaptureAPI
- jsonReturned.options.payment.capture = true;
- let apiResponse = await sendClassObj.LinePay_Reserve(jsonReturned);
- console.log("API Response: ", apiResponse);
- //Save Transaction ID into database
- let jsonObject = await dbModule.useDBFunction(dbModule.SQLStrings.view_cart, sqlvariables);
- //Display the cards with the API Response content
- // let apiResponse = {
- // webURL: body.info.paymentUrl.web,
- // appURL: body.info.paymentUrl.app,
- // transactionID: body.info.transactionId,
- // paymentAccessToken: body.info.paymentAccessToken
- // };
- let urlObject = {
- buildurl: apiResponse.webURL
- };
- jsonObject.urlObject = urlObject;
- //let messageType = this._FixMessageType(jsonObject);
- //displayModule.displayBuilder(userProfile, jsonObject, messageType);
- //FOR DEBUGGING
- //Maybe get this JSON from the database? For better customization?
- let json = {
- "type": "bubble",
- "styles": {
- "body": {
- "backgroundColor": "#FFFFFF"
- },
- "footer": {
- "backgroundColor": "#FFFFFF",
- "separator": true,
- "separatorColor": "#000000"
- }
- },
- "body": {
- "type": "box",
- "layout": "vertical",
- "contents": [
- {
- "type": "text",
- "text": "Payment",
- "weight": "bold",
- "color": "#000000",
- "wrap": true,
- "size": "md"
- },
- {
- "type": "text",
- "text": "Please press the button to complete proceed.",
- "color": "#000000",
- "wrap": true,
- "size": "sm"
- },
- {
- "type": "spacer",
- "size": "xl"
- }
- ]
- },
- "footer": {
- "type": "box",
- "layout": "vertical",
- "spacing": "sm",
- "contents": [
- {
- "type": "button",
- "style": "primary",
- "action": {
- "type": "uri",
- "label": "LINE Pay",
- "uri": apiResponse.webURL
- }
- }
- ]
- }
- };
- displayModule.sendRawJSON(userProfile, json);
- }
- catch (err)
- {
- console.log("");
- console.log("linepaymodule.Reserve ERROR!");
- console.log(err);
- this.DisplayErrorMessage(userProfile, "linepaymodule.Reserve", err);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement