本文介绍了为什么我收到 PayPal Android Native Checkout SDK - 无效的 client_id 或 redirect_uri的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 Kotlin 中使用了适用于 Android 的新 Native Checkout SDK,并且我一直在遵循文档中的每一步,但这种情况不断发生,我不知道为什么.我也在尝试
build.girdle :
插件{id 'com.android.application'id 'kotlin-android'id 'kotlin-android-extensions'}安卓 {编译SDK版本30buildToolsVersion "30.0.2";默认配置{applicationIdcom.example.paypalkotlin"minSdk 版本 23目标SDK版本30版本代码 1版本名称1.0"testInstrumentationRunnerandroidx.test.runner.AndroidJUnitRunner"}构建类型{释放 {minifyEnabled falseproguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'}}编译选项{sourceCompatibility JavaVersion.VERSION_1_8targetCompatibility JavaVersion.VERSION_1_8}科特林选项{jvmTarget = '1.8'}}依赖{实现org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version";实现 'androidx.core:core-ktx:1.2.0'实现 'androidx.appcompat:appcompat:1.3.0'实现 'com.google.android.material:material:1.3.0'实现 'androidx.constraintlayout:constraintlayout:2.0.4'实现('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'}
打造腰围
//顶级构建文件,您可以在其中添加所有子项目/模块通用的配置选项.构建脚本{ext.kotlin_version = "1.3.72";存储库{谷歌()jcenter()}依赖{类路径com.android.tools.build:gradle:4.1.3";classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version";//注意:不要将您的应用程序依赖项放在这里;他们属于//在单独的模块 build.gradle 文件中}}所有项目{存储库{谷歌()jcenter()MavenCentral()//需要此私有存储库来解决 Cardinal SDK 传递依赖项.行家{网址https://cardinalcommerceprod.jfrog.io/artifactory/android"证书 {//请务必添加这些非敏感凭据,以便从私有存储库中检索依赖项.用户名paypal_sgerritz"密码AKCp8jQ8tAahqpT5JjZ4FRP2mW7GMoFZ674kGqHmupTesKeAY2G8NcmPKLuTxTGkKjDLRzDUQ"}}}}任务清理(类型:删除){删除 rootProject.buildDir}
清单
<uses-permission android:name="android.permission.INTERNET"/><申请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"><意图过滤器><action android:name="android.intent.action.MAIN";/><category android:name="android.intent.category.LAUNCHER";/></意图过滤器></活动></应用程序></清单>
布局
<androidx.constraintlayout.widget.ConstraintLayout <com.paypal.checkout.paymentbutton.PayPalButtonandroid:id="@+id/payPalButton";android:layout_width=100dp"android:layout_height="wrap_content";app:layout_constraintBottom_toBottomOf=父级"app:layout_constraintLeft_toLeftOf=父"app:layout_constraintRight_toRightOf=父"app:layout_constraintTop_toTopOf=父"/></androidx.constraintlayout.widget.ConstraintLayout>
活动
package com.example.paypalkotlin导入 androidx.appcompat.app.AppCompatActivity导入 android.os.Bundle导入 android.util.Log导入 com.paypal.checkout.PayPalCheckout导入 com.paypal.checkout.approve.OnApprove导入 com.paypal.checkout.config.CheckoutConfig导入 com.paypal.checkout.config.Environment导入 com.paypal.checkout.config.SettingsConfig导入 com.paypal.checkout.createorder.CreateOrder导入 com.paypal.checkout.createorder.CurrencyCode导入 com.paypal.checkout.createorder.OrderIntent导入 com.paypal.checkout.createorder.UserAction导入 com.paypal.checkout.order.Amount导入 com.paypal.checkout.order.AppContext导入 com.paypal.checkout.order.Order导入 com.paypal.checkout.order.PurchaseUnit导入 kotlinx.android.synthetic.main.activity_main.*类 MainActivity : AppCompatActivity() {val YOUR_CLIENT_ID = AVxCKg9vnFKxNXLU5LLylEOnGCnsG8UiN300FlmY37zI4oKdrpyiuR_zutUn77rKSVxC377x0jM_uCPk";覆盖 fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.activity_main)val 配置 = CheckoutConfig(应用程序 = 应用程序,clientId = YOUR_CLIENT_ID,环境 = Environment.SANDBOX,returnUrl = "${BuildConfig.APPLICATION_ID}://paypalpay",货币代码 = 货币代码.USD,userAction = UserAction.PAY_NOW,设置配置 = 设置配置(日志记录启用 = 真))PayPalCheckout.setConfig(config)payPalButton.setup(createOrder = CreateOrder { createOrderActions ->val 订单 = 订单(意图 = OrderIntent.CAPTURE,appContext = AppContext(userAction = UserAction.PAY_NOW),购买单位列表 = listOf(采购单位(金额 = 金额(货币代码 = 货币代码.USD,值 = 10.00"))))createOrderActions.create(order)},onApprove = OnApprove { 批准 ->批准.orderActions.capture { captureOrderResult ->Log.i("CaptureOrder", "CaptureOrderResult: $captureOrderResult")}})}}
解决方案
- 打开我的应用程序
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.
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
layout
<?
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") } } ) } }
解决方案- Open My Apps & Credentials in Paypal sandbox
- Select your App
- Enable the below options (See attached images for a better idea)
Note: (See attached screenshot)
这篇关于为什么我收到 PayPal Android Native Checkout SDK - 无效的 client_id 或 redirect_uri的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!