我如何摆脱Firebase CLI中的错误“解析错误意外令牌”

时间:2019-05-13 20:31:26

标签: node.js

我正在尝试将具有Paybase的简单结帐与Firebase云功能集成在一起。

一旦用户使用贝宝(Paypal)按钮进行付款,交易/订单ID将存储在Firestore中,则云功能应侦听该文档的添加,获取该订单ID,然后通过贝宝(Paypal)运行它以获取交易的价值。 / p>

当我尝试部署该功能时,每次都会抛出此错误。 错误39:31 error Parsing error: Unexpected token payPalClient

代码

const functions = require('firebase-functions');
const paypal = require('paypal-rest-sdk');

const checkoutNodeJssdk = require('@paypal/checkout-server-sdk');

const payPalClient = require('../Common/payPalClient');

exports.readOrder = functions.firestore
    .document('user/{userId}/order/{orderId}')
    .onCreate((snap, context) => {
            const newValue = snap.data();

            const orderNo = newValue.orderID;
            console.log(orderNo);
            // perform desired operations ...

            // 2a. Get the order ID from firestore. The below id is 
             hardcoded however

            const orderID = "5T126226733479148";

            // 3. Call PayPal to get the transaction details
            let request = new checkoutNodeJssdk.orders.OrdersGetRequest(orderID);

            let order;
            try {

       //this below line is the one 
       //that throws the error

                order = await payPalClient.client().execute(request); 
            } catch (err) {

                // 4. Handle any errors from the call
                console.error(err);
                return response.send(500);
            }

            // 5. Validate the transaction details are as expected
            if (order.result.purchase_units[0].amount.value !== '220.00') {
                return response.send(400);
            }

            // 6. Save the transaction in your database
            // await database.saveTransaction(orderID);

            // 7. Return a successful response to the client
            return response.send(200);
        }
    });

我认为的错误是因为模块未正确导入,但这实际上是他们在文档中拥有的确切方式。 同样,每个模块和SDK都已正确安装在functions目录中。 任何帮助都会真的有帮助

0 个答案:

没有答案