paypal / android-checkout-sdk

Apache License 2.0
77 stars 38 forks source link

The new PaymentButtonContainer button is invisible in the android studio preview #164

Open rafiul587 opened 2 years ago

rafiul587 commented 2 years ago

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)

mahmoud-turki commented 2 years ago

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

rafiul587 commented 2 years ago

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()
    }
}`
mahmoud-turki commented 2 years ago

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):

Additional context Add any other context about the problem here.