[英]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.