簡體   English   中英

Braintree網關:如何使用customerId如何通過PaymentMethodRequest或TransactionRequest向一次性信用卡收取一次性費用?

[英]Braintree Gateway: Using a customerId how can I charge a vaulted credit card a one-time fee using PaymentMethodRequest or TransactionRequest?

我正在使用在這里找到的Braintree Sping示例: https : //github.com/braintree/braintree_spring_example

控制器類具有一種向新信用卡/客戶收取特定金額的方法。 控制器從POST數據中獲取該金額。

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

似乎做到這一點的方法是通過創建一個新的PaymentMethodRequest,如下所示: https : //developers.braintreepayments.com/reference/request/payment-method/create/java

但是,當我查看API時,看不到如何設置通過PaymentMethodRequest收費的金額。 與TransactionRequest類不同,PaymentMethodRequest不允許設置金額。

因此,給定一個customerid,我如何一次性收取拱形卡費用?

謝謝您的幫助。

這是處理帖子信息的方法


    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行。 在這里,我對customerId進行了硬編碼。 這只是出於演示目的。

   @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";
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM