繁体   English   中英

在Android中需要创建Paypal按钮吗?

[英]What needs to create paypal button in android?

我知道关于贝宝按钮的讨论很多,但我不明白需要什么。。假设这是我的B7REJHRY9RGWL宝ID B7REJHRY9RGWL ...我现在该怎么办? 是否有一段代码可以创建按钮? 我的目标是创建一个免费的捐赠按钮,并将其插入我的Donate.java活动中。 谢谢

请考虑阅读以下内容: https : //developer.paypal.com/webapps/developer/docs/classic/mobile/ht_mpl-itemPayment-Android/我认为这里有所有说明:)

自从贝宝(Paypal)收购Braintrain之后,贝宝(Paypal)贬值了其贝宝(PayPal)移动SDK,因此先前答案中的链接不再起作用。

自2019年3月起,贝宝(PayPal)支持名为Paypal Checkout SDK的移动应用程序的轻量级客户端集成。

首先,您需要设置SDK

如果尚未完成,Android应用程序需要指定它接受互联网权限。 如果您还想向钱包添加触觉反馈以获取选择通知,请在应用程序的AndroidManifest.xml的顶部还包含振动许可。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="checkout.paypal.com.myapplication">
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.VIBRATE"/>

为了使PayPal进行身份验证并在应用中被记住,我们依赖于OpenID的AppAuth实现。 请将此活动添加到AndroidManifest.xml中,以确保使用App Links(将在下面列出的网址)切换回应用程序,该网址应与生成的App Links网址匹配。

请记住,应用链接需要在PayPal开发人员门户中注册为返回URL。

<activity android:name="net.openid.appauth.RedirectUriReceiverActivity">
    <intent-filter android:autoVerify="true">
        <action android:name="android.intent.action.VIEW" />

        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />

        <data
            android:scheme="https"
            android:host="example.com"
            android:path="/buyingstuff"/>
    </intent-filter>
</activity>

如果无法为特定用户加载本机体验,PayPal将退回到Chrome自定义标签(或默认浏览器),以确保实现转换。 为确保用户从PayPal Web体验中将其返回到应用程序,采用了自定义方案。 请使用您为应用选择的自定义方案注册活动。 房东应该留下paypalxo

<activity android:name="com.paypal.pyplcheckout.PYPLCheckoutReceiver"
  android:launchMode="singleTask"
  >
  <intent-filter android:autoVerify="true">

      <data
          android:scheme="testapp"
          android:host="paypalxo" />

      <action android:name="android.intent.action.VIEW" />

      <category android:name="android.intent.category.DEFAULT" />
      <category android:name="android.intent.category.BROWSABLE" />

  </intent-filter>
</activity>

完整的AndroidManifest.xml应该类似于以下内容。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="checkout.paypal.com.myapplication">
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.VIBRATE"/>

    <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/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="net.openid.appauth.RedirectUriReceiverActivity">
            <intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data
                    android:scheme="https"
                    android:host="example.com"
                    android:path="/buyingstuff"/>
            </intent-filter>
        </activity>

        <activity android:name="com.paypal.pyplcheckout.PYPLCheckoutReceiver"
          android:launchMode="singleTask"
          >
          <intent-filter android:autoVerify="true">

              <data
                  android:scheme="testapp"
                  android:host="paypalxo" />

              <action android:name="android.intent.action.VIEW" />

              <category android:name="android.intent.category.DEFAULT" />
              <category android:name="android.intent.category.BROWSABLE" />

          </intent-filter>
        </activity>
    </application>
</manifest>

然后,您需要将存储库添加到构建文件中。 使用Gradle,它看起来像:

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://github.com/syrjs/maven/raw/master"}
        maven { url "https://github.com/paypal/paypalcheckout-android/raw/nativeSDK"}
    }
}

将依赖项添加到应用程序级别build.gradle。

dependencies {
    implementation 'com.paypal.pyplcheckout:nativexo:3.4.5'
}

下一步是调用SDK。 PayPal可以观看应用程序中的WebView,并提供本地支付体验来代替网站,或者可以通过调用简单函数直接调用。 您可以使用以下步骤将其手动集成到应用程序中。

在调用之前,SDK需要有关该应用程序的一些其他信息。 在AndroidManifest.xml中提供自定义方案设置,并在AndroidManifest.xml中提供应用程序链接重定向URL。 提供用于此应用程序的客户端ID。 也可以设置操作环境。

final PYPLCheckoutEnvironment pyplEnvironment = PYPLCheckoutEnvironment.getInstance();

pyplEnvironment.setkPYPLEnvironment(Environment.SANDBOX);

pyplEnvironment.setkPYPLUrlScheme("foobarstore");

//set the redurect uri, that has the assetLinks.json.
pyplEnvironment.setkPYPLRedirectURL("https://paypalmerchant.herokuapp.com/thankyou");

//set the client ID for the merchant
pyplEnvironment.setClientId("AX93NErgg-F0VeBQ6pNLwa2VKQdw3BnKDvBnasIe_pKoprQyz6NiSf6XS7I1Qtro-VD4GP-AJdjT0Uz4");

//set the user context. 'this' should be the activity from which the experience is being called.
pyplEnvironment.setkPYPLUserContext(this);

下一步是集成WebView拦截

如果先前的集成与WebView周围的代码发生冲突,则可以手动拦截WebView,如这些示例所示。

PYPLCheckout.getInstance().shouldOverrideUrlLoading(view, url); 方法可用于拦截任何重定向到PayPal的webView。 此函数返回一个布尔值,该布尔值可用于webViewClient中的shouldOverrideUrlLoading()方法。

WebView与您自己的webViewClient集成的示例。 //MainActivity.class

//在您想调用体验的活动中。 WebView webView =新的WebView(this);

// SampleWebViewIntercept是您的webViewClient。 webView.setWebViewClient(new SampleWebViewIntercept());

//SampleWebViewIntercept.class

public class SampleWebViewIntercept extends WebViewClient {

 //include this for integrating with Checkout.js
  @Override
  public void onPageFinished(WebView view, String url) {

      super.onPageFinished(view, url);

      //this will load a script to handle the Checkout.js integration
      PYPLCheckout.getInstance().loadScript(view);

  }

  @Override
  public boolean shouldOverrideUrlLoading(WebView view, final String url) {

      return PYPLCheckout.getInstance().shouldOverrideUrlLoading(view, url);

  }

}

直接调用

通过从后台系统提供付款令牌,直接启动PayPal Checkout体验。

结帐完成后,设置回叫代表。

pyplEnvironment.setkCheckoutDelegate(new PYPLCheckoutDelegate() {

      @Override
      public void completeCheckout(HashMap<String,String> returnParams) {

        //return params will contain all the required information for the merchant to finish the transaction
          Log.i("CheckoutFinishedWith>>", returnParams.toString());

        //here is a sample of what return params consists
        /**
        {
          from_cart=true, returnUrl=https://sampleurl.com/checkouts/?from_cart=true&key=Key&token=EC-token&PayerID=payerID&opType=payment,
          token=EC-token,
          key=Key,
          PayerID=payerID,
          opType=payment
        }
        **/

      }

      // in addition to the checkoutComplete delegate you can also provide a canceled delegate that is called when the user exits CCT amidst checkout
      @Override
       public void checkoutCanceled() {

          Log.i("Checkout Canceled>>", "Checkout Canceled");

        }



  });

设置您需要传递给PayPal的其他参数。 这是可选的。

//every option should be a string with the key and value joined with a '='
String[] pyplParamsArray = {"useraction=commit"};

pyplEnvironment.setkPYPLQueryStringParameters(pyplParamsArray);

从结帐令牌开始体验。

PYPLCheckout.getInstance().startCheckoutWithECToken(MainActivity.this, "EC-1FP91222RL3429812");

删除代表。 如果您需要从我们的回调中删除委托,则可以使用

final PYPLCheckoutEnvironment pyplEnvironment = PYPLCheckoutEnvironment.getInstance();
pyplEnvironment.clearCheckoutDelegate();

要再次接收事件,只需再次设置委托即可。

参考: https : //paypal.github.io/paypalnativecheckout-docs/Android/integrating_experience/#prerequisites

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM