android-checkout-sdk icon indicating copy to clipboard operation
android-checkout-sdk copied to clipboard

The new PaymentButtonContainer button is invisible in the android studio preview

Open rafiul587 opened this issue 2 years ago • 3 comments

I tried to copy and use the PaymentButtonContainer from the official document like the one below. But it doesn't show anything in the android studio preview. I got the error message from the android studio preview. Version: Android Studio Dolphin | 2021.3.1

<com.paypal.checkout.paymentbutton.PaymentButtonContainer
    android:id="@+id/payment_button_container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:paypal_button_color="silver"
    app:paypal_button_label="pay"
    app:paypal_button_shape="rectangle"
    app:paypal_button_size="large"
    app:paypal_button_enabled="true" />

Error from the android studio preview window

The following classes could not be instantiated: - com.paypal.checkout.paymentbutton.PaymentButtonContainer (Open Class, Show Exception, Clear Cache) Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE. If this is an unexpected error you can also try to build the project, then manually refresh the layout. Exception Details java.lang.IllegalStateException: Required value was null.   at com.paypal.pyplcheckout.di.SdkComponent$Companion.getInstance(SdkComponent.kt:129)   at com.paypal.checkout.paymentbutton.PaymentButtonContainer.(PaymentButtonContainer.kt:174)   at com.paypal.checkout.paymentbutton.PaymentButtonContainer.(PaymentButtonContainer.kt:63)   at com.paypal.checkout.paymentbutton.PaymentButtonContainer.(PaymentButtonContainer.kt:-1)   at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(NativeConstructorAccessorImpl.java:-2)   at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)   at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

rafiul587 avatar Oct 27 '22 07:10 rafiul587

You need to initialize the checkout config 1st in your application class.

mahmoud-turki avatar Oct 27 '22 11:10 mahmoud-turki

It's already there. Can hilt cause the problem somehow?

`@HiltAndroidApp class MyApplication : Application() {

override fun onCreate() {
    super.onCreate()

    val config = CheckoutConfig(
        application = this,
        clientId = "Client id here",
        environment = Environment.SANDBOX,
        currencyCode = CurrencyCode.USD,
        userAction = UserAction.PAY_NOW,
        settingsConfig = SettingsConfig(
            loggingEnabled = true,
        )

    )

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        PayPalCheckout.setConfig(config)
    } else {
        Toast.makeText(this, "Checkout SDK only available for API 23+", Toast.LENGTH_SHORT).show()
    }
}`

rafiul587 avatar Oct 27 '22 15:10 rafiul587

It shouldn't be. Could you please fill out the following information so it's easier for me to reproduce the issue and figure out what went wrong on the client side?

Before you create a new issue, please search for similar issues. It's possible somebody has encountered this bug already. PLEASE REMOVE THIS LINE TO ACKNOWLEDGE THAT AN ISSUE DOESN'T ALREADY EXIST FOR THIS BUG

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Smartphone (please complete the following information):

  • Android Version: [e.g. API 30]
  • Device: [e.g. Emulator or One Plus 9]
  • Browser [e.g. chrome, safari] <- only applicable for app switches or fallback situations
  • SDK Version [e.g. 0.1.0]
  • Package name of your app [e.g. com.example.my_app]
  • Client ID

Additional context Add any other context about the problem here.

mahmoud-turki avatar Oct 27 '22 17:10 mahmoud-turki