【问题标题】:Square Payment API - Issue with smaller denomination of amountSquare Payment API - 金额较小的问题
【发布时间】:2019-04-16 03:06:53
【问题描述】:

我正在使用 Square Payment API,我在文档中找不到相同的任何内容,

假设我要收取 52.50 加元。

众所周知,它不允许小数(我使用的是 Node.js SDK v2)。

当我浏览文档时,它说金额必须是较小的面额。

我有自己的自定义表单,我想知道,当从支付表单(生成卡随机数)传递值时,我是否需要以较小面额传递金额,或仅在 API 端,或两者兼而有之。

我向用户询问金额,但面额不小,即(52.50 加元),我如何在 SDK 和前端传递金额。

【问题讨论】:

    标签: node.js square


    【解决方案1】:

    与美元 (USD) 一样,加元 (CAD) 的最小面额是美分。

    您的自定义/前端表单可以选择以美元显示金额,但 API 调用必须采用最小面额。

    正如您在下面的示例代码中所见,nonce 取自付款表单,收取的金额是硬编码的。如果您想从表单中提取收费金额,则需要对其进行清理,将其转换为美分(如果以美元为单位)并确保货币 ID 正确。

    示例代码

    来源:Payment processing example: Node JS

    router.post('/process-payment', function(req,res,next){
      var request_params = req.body;
    
      var idempotency_key = require('crypto').randomBytes(64).toString('hex');
    
      // Charge the customer's card
      var transactions_api = new squareConnect.TransactionsApi();
      var request_body = {
        card_nonce: request_params.nonce,
        amount_money: {
          amount: 100, // $1.00 charge
          currency: 'USD'
        },
        idempotency_key: idempotency_key
      };
      transactions_api.charge(config.squareLocationId, request_body).then(function(data) {
        console.log(util.inspect(data, false, null));
        res.render('process-payment', {
          'title': 'Payment Successful',
          'result': "Payment Successful (see console for transaction output)"
        });
      }, function(error) {
        console.log(util.inspect(error.status, false, null));
        res.render('process-payment', {
          'title': 'Payment Failure',
          'result': "Payment Failed (see console for error output)"
        });
      });
    
    });
    

    相关文档:

    【讨论】:

    • 我是否也需要在前端表单中以较小的面额传递金额?
    • 如上所述,表格是您设计的。你可以随心所欲。我个人不会将价格放入表格中,因为任何精明的人都可以随意将价格更改为免费或 0.01 美元。相反,我会在数据库中有一个产品列表,根据他们的购物车计算成本,将其展示给用户并收集他们的付款信息。然后在后端,向用户收取他们选择的产品的费用并处理他们的订单。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-13
    相关资源
    最近更新 更多