Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Stripe app crashes on adding new payment source

Desired payment flow

Am trying to achieve the above checkout flow using stripe SDK in android using this documentation https://stripe.com/docs/mobile/android/customer-information. I have created a backend call that returns the ephemeral key like this

{
    "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"
}

In my app, am initializing my CustomerSession and starting the PaymentMethodsActivity like this

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);
                            }
                        }));

Then i have this onActivityResult method

  @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.
        }
    }

It opens the PaymentMethodsActivity fine and on adding a new payment method, when i try to submit the app crashes with the following stack trace. anything i might have missed?

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)
like image 971
muoki_D Avatar asked Aug 27 '18 11:08

muoki_D


2 Answers

It's complaining that you've not initialized the PaymentConfiguration object with a publishable key.

PaymentConfiguration.init(<<YOUR PUBLISHABLE KEY HERE>>);
like image 153
korben Avatar answered Oct 06 '22 00:10

korben


It should be like this

PaymentConfiguration.init(applcationContext, "publishableKey");
like image 28
Divyesh Tarsariya Avatar answered Oct 06 '22 00:10

Divyesh Tarsariya