我试图使用此文档https://stripe.com/docs/mobile/android/customer-information在android中使用条带SDK实现上述结帐流程。我已经创建了一个后端调用,它会像这样返回短暂的密钥
{
"id": "ephkey_EPHEMERAL_KEY_HERE",
"object": "ephemeral_key",
"associated_objects": [
{
"id": "cus_CUSTOMER_ID_HERE",
"type": "customer"
}
],
"created": 1535352558,
"expires": 1535356158,
"livemode": true,
"secret": "ek_live_SECRET_HERE"
}
在我的应用程序中,我正在初始化我的CustomerSession并启动PaymentMethodsActivity
CustomerSession.initCustomerSession(
new MyEphemeralKeyProvider(
new MyEphemeralKeyProvider.ProgressListener() {
@Override
public void onStringResponse(String string) {
if (string.startsWith("Error: ")) {
new android.support.v7.app.AlertDialog.Builder(SelectCardActivity.this).setMessage(string).show();
}
Intent payIntent = PaymentMethodsActivity.newIntent(SelectCardActivity.this);
startActivityForResult(payIntent, REQUEST_CODE_SELECT_SOURCE);
}
}));
然后我有这个onActivityResult方法
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE_SELECT_SOURCE && resultCode == RESULT_OK) {
String selectedSource = data.getStringExtra(PaymentMethodsActivity.EXTRA_SELECTED_PAYMENT);
Source source = Source.fromString(selectedSource);
// This is the customer-selected source.
// Note: it isn't possible for a null or non-card source to be returned at this time.
}
}
当我尝试使用以下堆栈跟踪提交应用程序崩溃时,它会打开PaymentMethodsActivity并添加新的付款方式。我可能错过了什么?
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.stealthdroids.itransfer, PID: 22404
java.lang.IllegalStateException: Attempted to get instance of PaymentConfiguration without initialization.
at com.stripe.android.PaymentConfiguration.getInstance(PaymentConfiguration.java:29)
at com.stripe.android.view.AddSourceActivity.onActionSave(AddSourceActivity.java:133)
at com.stripe.android.view.StripeActivity.onOptionsItemSelected(StripeActivity.java:88)
at com.stripe.android.view.AddSourceActivity.onOptionsItemSelected(AddSourceActivity.java:33)
at android.app.Activity.onMenuItemSelected(Activity.java:2970)
at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:407)
at android.support.v7.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.java:195)
at android.support.v7.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:108)
at android.support.v7.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:108)
at android.support.v7.app.ToolbarActionBar$2.onMenuItemClick(ToolbarActionBar.java:63)
at android.support.v7.widget.Toolbar$1.onMenuItemClick(Toolbar.java:203)
at android.support.v7.widget.ActionMenuView$MenuBuilderCallback.onMenuItemSelected(ActionMenuView.java:780)
at android.support.v7.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:822)
at android.support.v7.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:171)
at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:973)
at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:963)
at android.support.v7.widget.ActionMenuView.invokeItem(ActionMenuView.java:624)
at android.support.v7.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:150)
at android.view.View.performClick(View.java:4848)
at android.view.View$PerformClick.run(View.java:20270)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5668)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:963)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:758)
它抱怨你没有用可发布的密钥初始化PaymentConfiguration
对象。
PaymentConfiguration.init(<<YOUR PUBLISHABLE KEY HERE>>);