我正在尝试使用braintree-rails gem 向订阅添加折扣对象,但它未应用.我猜我的代码一定是错的,但我找不到一个有效的例子.
discount = BraintreeRails::Discount.find(params[:subscription_promo])
subscription = @plan.subscriptions.build permitted_params[:subscription]
subscription.discounts << discount
# ...
subscription.save
Run Code Online (Sandbox Code Playgroud)
当我转储时discount,它被正确加载.订阅创建得很好,但是全价.折扣不存在.如何在订阅中添加折扣?
更新:我尝试修改直接查询,但这没有帮助.
@subscription.raw_object.discounts = {add:[{inherited_from_id: discount.id}]}
Run Code Online (Sandbox Code Playgroud)
更新2:我还根据上述代码的请求运行了针对API的直接Braintree请求,并且它有效.在设置和保存之间发生了一些错误.
更新3:通过提取BraintreeRails::Subscription对象的属性,使用Braintree::Subscription调用API,并使用BraintreeRails::Subscription.find将其加载回对象,可以实现变通方法.但这绝对不是最佳选择,因为它不是很干净,需要额外的API调用.
ruby-on-rails subscription braintree recurring-billing braintree-rails
我正在使用在 Braintree 控制面板中配置的 Drop-in UI 来自动验证付款方式是否合法。
因此,在我的应用程序中,我在单击表单提交按钮时禁用它,如果用户付款方式不合法,它会说存在错误并且不提交表单。我的问题是如何捕获此错误,以便我可以启用提交按钮。
仅当输入字段中不存在所有字段时才会引发 onError 事件。那么验证错误怎么办,我该如何捕获它呢?
现在我的 JavaScript 看起来像这样:
braintree.setup("#{@braintree_token}", 'dropin', {
container: 'dropin',
onReady: function () {
},
onError: function() {
console.log("error");
$('#submit-payment').removeClass('disabled');
}
});
$("form").submit(function (e) {
$('#submit-payment').addClass('disabled');
setTimeout(function() { $('#submit-payment').removeClass('disabled'); }, 2000);
return;
});
Run Code Online (Sandbox Code Playgroud)
我的解决方案现在并不理想,因为它只是禁用按钮 2 秒钟。所以请给我推荐一些东西。
PS 需要明确的是,我想用 Javascript 捕获这种错误:

PSS 我还发现它回调了以下信息:
/**/callback_jsond435f0d591e44176bf94ec137859dd3c({"error":{"message":"Credit card verification failed"},"fieldErrors":[{"field":"creditCard","fieldErrors":[{"field":"cvv","code":"81736","message":"CVV verification failed"}]}],"status":422})
Run Code Online (Sandbox Code Playgroud)
大家好,我正在尝试与Braintree进行交易,并且正在使用Heroku Rails服务器。我无法获取client_token,当我尝试进行交易时,找不到404。我正在使用GitHub上存储库中的演示应用程序。这是演示应用程序中的相关代码。
import com.braintreepayments.demo.models.ClientToken;
import com.braintreepayments.demo.models.Transaction;
import retrofit.Callback;
import retrofit.http.Field;
import retrofit.http.FormUrlEncoded;
import retrofit.http.GET;
import retrofit.http.POST;
import retrofit.http.Query;
public interface ApiClient {
@GET("/client_token")
void getClientToken(@Query("customer_id") String customerId, @Query("merchant_account_id") String merchantAccountId, Callback<ClientToken> callback);
@FormUrlEncoded
@POST("/nonce/transaction")
void createTransaction(@Field("nonce") String nonce, Callback<Transaction> callback);
@FormUrlEncoded
@POST("/nonce/transaction")
//@POST("/checkout")
void createTransaction(@Field("nonce") String nonce, @Field("merchant_account_id") String merchantAccountId, Callback<Transaction> callback);
@FormUrlEncoded
@POST("/nonce/transaction")
void createTransaction(@Field("nonce") String nonce, @Field("merchant_account_id") String merchantAccountId, @Field("three_d_secure_required") boolean requireThreeDSecure, Callback<Transaction> callback);
}
Run Code Online (Sandbox Code Playgroud)
并在交易活动中
private void sendNonceToServer(PaymentMethodNonce nonce) {
Callback<Transaction> callback = new Callback<Transaction>() {
@Override …Run Code Online (Sandbox Code Playgroud)