我正在尝试在我的GWT应用程序中使用Braintree。
目前我正在加载表单,并在用户点击确定按钮时从我的服务器获取客户端令牌。
这就是我设置braintree的方式:
private static native void setup(String domId, String serverToken) /*-{
braintree.setup(
serverToken,
"custom",
{
id: domId
});
}-*/;
这是我认为的工作:
private final static String CREDIT_CARD_FORM_ID = "credit-card-form";
@Inject
PaymentMethodInfoView(Binder uiBinder) {
this.initWidget(uiBinder.createAndBindUi(this));
this.formCreditCard.getElement().setId(CREDIT_CARD_FORM_ID);
}
@Override
public void setupBraintree(String serverToken) {
BraintreeClient.setupForm(CREDIT_CARD_FORM_ID, serverToken);
}
在用户输入信用卡数据并点击正常后,此处setupBraintree()
被称为。正如您所看到的,我在视图的构造函数中设置了id
属性。
仍然,由于某种原因,我得到了:
Uncaught Error: Unable to find form with id: "credit-card-form"
知道问题是什么吗?
这是我目前的Braintree客户端包装器。我确保在我的Web应用程序引导程序中调用静态函数load()
。
public class BraintreeClient {
private final static Logger LOGGER = Logger.getLogger(BraintreeClient.class.getName());
private final static String BRAINTREE_JS_URL = "https://js.braintreegateway.com/js/braintree-2.27.0.min.js";
private static JavaScriptObject braintreeJs;
public static void load(OnSuccessCallback<Void> success, OnFailureCallback failure) {
if(braintreeJs == null) {
LOGGER.fine("Loading " + BRAINTREE_JS_URL);
braintreeJs = ScriptInjector.fromUrl(BRAINTREE_JS_URL).setCallback(
new Callback<Void, Exception>() {
@Override
public void onFailure(Exception caught) {
failure.onFailure(caught);
braintreeJs = null;
}
@Override
public void onSuccess(Void result) {
success.onSuccess(result);
}
}).inject();
}
}
public static void setupForm(String domId, String serverToken) {
if(braintreeJs == null) {
throw new RuntimeException("Braintree has not been loaded. Did you call BraintreeClient.load()?");
}
LOGGER.fine("Setting up form " + domId);
setup(domId, serverToken);
}
private static native void setup(String domId, String serverToken) /*-{
braintree.setup(
serverToken,
"custom",
{
id: domId
});
}-*/;
}
答案 0 :(得分:0)
这只是一个猜测,但正在改变
private static native void setup(String domId, String serverToken) /*-{
braintree.setup(
serverToken,
"custom",
{
id: domId
});
}-*/;
到
private static native void setup(String domId, String serverToken) /*-{
braintree.setup(
serverToken,
"custom",
{
container: domId
});
}-*/;
似乎就是这里的伎俩,尽管我在documentation中看到了一个像我一样使用id
的例子。