Why I'm getting PayPal Android Native Checkout SDK - invalid client_id or redirect_uri

Viewed 1431

I'm using the new Native Checkout SDK for Android with Kotlin and I've been following every step in the documentation but this keeps happening and I don't know why. I'm trying also PayPal Android Native Checkout SDK - invalid client_id or redirect_uri, and CHECKOUT_ERROR but but it didn't work for me.

enter image description here

build.girdle :

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-android-extensions'
}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.2"

    defaultConfig {
        applicationId "com.example.paypalkotlin"
        minSdkVersion 23
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}

dependencies {

    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.2.0'
    implementation 'androidx.appcompat:appcompat:1.3.0'
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation('com.paypal.checkout:android-sdk:0.2.0')
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

build girdle

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext.kotlin_version = "1.3.72"
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.1.3"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
        // This private repository is required to resolve the Cardinal SDK transitive dependency.
        maven {
            url  "https://cardinalcommerceprod.jfrog.io/artifactory/android"
            credentials {
                // Be sure to add these non-sensitive credentials in order to retrieve dependencies from the private repository.
              
                username "paypal_sgerritz"
                password "AKCp8jQ8tAahqpT5JjZ4FRP2mW7GMoFZ674kGqHmupTesKeAY2G8NcmPKLuTxTGkKjDLRzDUQ"
            }
        }

    }
}


task clean(type: Delete) {
    delete rootProject.buildDir
}

Manifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.paypalkotlin">
    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.PaypalKotlin">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

layout

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <com.paypal.checkout.paymentbutton.PayPalButton
        android:id="@+id/payPalButton"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

Activity

package com.example.paypalkotlin

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log

import com.paypal.checkout.PayPalCheckout
import com.paypal.checkout.approve.OnApprove
import com.paypal.checkout.config.CheckoutConfig
import com.paypal.checkout.config.Environment
import com.paypal.checkout.config.SettingsConfig
import com.paypal.checkout.createorder.CreateOrder
import com.paypal.checkout.createorder.CurrencyCode
import com.paypal.checkout.createorder.OrderIntent
import com.paypal.checkout.createorder.UserAction
import com.paypal.checkout.order.Amount
import com.paypal.checkout.order.AppContext
import com.paypal.checkout.order.Order
import com.paypal.checkout.order.PurchaseUnit
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

    val YOUR_CLIENT_ID = "AVxCKg9vnFKxNXLU5LLylEOnGCnsG8UiN300FlmY37zI4oKdrpyiuR_zutUn77rKSVxC377x0jM_uCPk";
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val config = CheckoutConfig(
                application = application,
                clientId = YOUR_CLIENT_ID,
                environment = Environment.SANDBOX,
                returnUrl = "${BuildConfig.APPLICATION_ID}://paypalpay",
                currencyCode = CurrencyCode.USD,
                userAction = UserAction.PAY_NOW,
                settingsConfig = SettingsConfig(
                        loggingEnabled = true
                )
        )

        PayPalCheckout.setConfig(config)
        payPalButton.setup(
                createOrder = CreateOrder { createOrderActions ->
                    val order = Order(
                            intent = OrderIntent.CAPTURE,
                            appContext = AppContext(
                                    userAction = UserAction.PAY_NOW
                            ),
                            purchaseUnitList = listOf(
                                    PurchaseUnit(
                                            amount = Amount(
                                                    currencyCode = CurrencyCode.USD,
                                                    value = "10.00"
                                            )
                                    )
                            )
                    )
                    createOrderActions.create(order)
                },

                onApprove = OnApprove { approval ->
                    approval.orderActions.capture { captureOrderResult ->
                        Log.i("CaptureOrder", "CaptureOrderResult: $captureOrderResult")
                    }
                }
        )

    }

}

4 Answers

Make sure you have added Same Return Url in the Paypal Developer Website. and The return Url must be "Your Application Id" + "://paypalpay":

I had the same problem. I managed to solve it by writing "com.example.appname://paypalpay" in the returnURL from the Sandbox Website. Try it!

I too faced the same issue...to fix it as mentioned above you have to go to PayPal Dashboard and in the sandbox settings where you have created the application, there will have the option to enter the return URL.

after adding it and save.

Happy coding

  1. Open My Apps & Credentials in Paypal sandbox
  2. Select your App
  3. Enable the below options (See attached images for a better idea)

i. Accept Payments > Native Checkout SDK, Vault, Billing agreements.

ii. Login with PayPal > Full name, Email, PayPal account ID, Privacy Policy URL, User agreement URL 4. Save it. now, Sandbox will start working.

Note: (See attached screenshot)

Before going Live, your app will need to be reviewed in order to approve sharing customer data. Full name is enabled by default, but all other scopes will require PayPal's approval through the app review process. The app review process typically takes 7-10 days, so please account for enough time to review before going Live.


#1#2

Related