【问题标题】:Why I'm getting PayPal Android Native Checkout SDK - invalid client_id or redirect_uri为什么我收到 PayPal Android Native Checkout SDK - 无效的 client_id 或 redirect_uri
【发布时间】:2021-08-21 07:32:03
【问题描述】:

我在 Kotlin 中使用适用于 Android 的新 Native Checkout SDK,我一直在遵循文档中的每一步,但这种情况一直在发生,我不知道为什么。我也在尝试PayPal Android Native Checkout SDK - invalid client_id or redirect_uri, and CHECKOUT_ERROR,但它对我不起作用。

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'
}

打造腰带

// 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 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>

布局

<?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>

活动

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

    }

}

【问题讨论】:

    标签: android android-studio kotlin paypal paypal-sandbox


    【解决方案1】:

    确保您在 Paypal 开发者网站中添加了相同的返回 URL。并且返回的 Url 必须是“Your Application Id”+“://paypalpay”:

    【讨论】:

    • 是的,我确认,Paypal 网站中的返回 URL 和我的应用程序返回 URL 相同。但它没有用
    • 那我觉得你应该在paypal的github项目中报告一个bug
    【解决方案2】:

    我遇到了同样的问题。我设法通过在沙盒网站的 returnURL 中写入“com.example.appname://paypalpay”来解决它。试试看!

    【讨论】:

      【解决方案3】:

      我也遇到了同样的问题...要解决上面提到的问题,您必须转到 PayPal 仪表板,在您创建应用程序的沙盒设置中,可以选择输入返回 URL。

      添加后保存。

      快乐编码

      【讨论】:

        【解决方案4】:
        1. Paypal sandbox 中打开我的应用程序和凭据
        2. 选择您的应用
        3. 启用以下选项(请参阅附图以获得更好的想法)

        我。接受付款 > 原生结账 SDK、保险柜、计费协议。

        二。使用 PayPal 登录 > 全名、电子邮件、PayPal 帐户 ID、隐私政策 URL、用户协议 URL 4. 保存。现在,Sandbox 将开始工作。

        注意:(见附件截图)

        在上线之前,您的应用需要经过审核才能批准共享客户数据。默认情况下启用全名,但所有其他范围都需要通过应用审核流程获得 PayPal 的批准。应用审核过程通常需要 7-10 天,因此请在上线前留出足够的时间进行审核。


        【讨论】:

          猜你喜欢
          • 2021-05-28
          • 2022-09-17
          • 2021-09-07
          • 2018-05-06
          • 2021-03-02
          • 2021-05-31
          • 2022-01-10
          • 2021-07-04
          • 2014-05-29
          相关资源
          最近更新 更多