Braintree Gateway:使用客户ID如何使用Paymethodrequest或TransactionRequ



我正在使用Braintree Sping示例:https://github.com/braintree/braintree/braintree_spring_example。

控制器类具有一种向新信用卡/客户收取特定金额的方法。控制器从帖子数据中获取该金额。

我想使用拱形信用卡,而不是使用新卡/客户。

似乎是通过创建一个新的PaymentMethodRequest,如下所示:https://developers.braintreepayments.com/reference/request/request/payment-method/create/create/java

但是,当我查看API时,我看不到如何设置用于使用Paymethodrequest收费的金额。与TransactionRequest类不同,PaymentMethodRequest不允许设定金额。

所以,给定一个客户,我如何向拱顶卡收取一次性费用?

感谢您的帮助。

这是处理帖子信息的方法


    public String postForm(@RequestParam("amount") String amount, @RequestParam("payment_method_nonce") String nonce, Model model, final RedirectAttributes redirectAttributes) {
 // ... validate the amount ... 
        TransactionRequest request = new TransactionRequest()
            .amount(decimalAmount)
            .paymentMethodNonce(nonce)
            .options()
                .submitForSettlement(true)
                .done();
        Result<Transaction> result = gateway.transaction().sale(request);
    // ... process result....
    }

似乎我应该能够做

PaymentMethodRequest request = new PaymentMethodRequest()
  .amount(decimalAmount) // this isn't actually allowed by the class
  .customerId(customer.getId())
  .token("the_token")
  .paymentMethodNonce(nonceFromTheClient);

但是paymentmethodrequest没有该功能。

事实证明我正在做错方法。

实现我的目标,我没有更改PostForm((。相反,我更改了Checkout((。我在代码中添加了CustomerID和ClientTokenRequest行。在这里,我对客户ID进行了硬编码。这只是用于演示的目的。

   @RequestMapping(value = "/checkouts", method = RequestMethod.GET)
    public String checkout(Model model) {
        // Two new lines for the new way  - retrieve customer specific token from the vault
          String customerId = "555555555"; // Hard coded just to make it work.
        ClientTokenRequest clientTokenRequest = new ClientTokenRequest() .customerId(customerId);
        // One modified line for the new way - gets vaulted payment methods: now use clientTokenRequest to generate clientToken
        String clientToken = gateway.clientToken().generate(clientTokenRequest);
        // old way - one time charge with all new data. generate() takes no arguments
        /* String clientToken = gateway.clientToken().generate(); */
        model.addAttribute("clientToken", clientToken);
        return "checkouts/new";
    }

相关内容

最新更新