i know thare are many discussion about paypal buttons but i don't understand what needs.. Assuming that this is my paypal ID B7REJHRY9RGWL
... What have i to do now with this? Is there a piece of code to create the button? My goal is create a free donate button and insert it in my Donate.java
activity. Thanks
What needs to create paypal button in android?
2.6k views Asked by David_D AtThere are 2 answers
Since Paypal acquired Braintrain, Paypal has depreciated its PayPal Mobile SDKs, therefore the link from the previous answer doesn't work any more.
As of March 2019, PayPal supports a lightweight client-side integration for mobile apps called Paypal Checkout SDK.
First you need to set up for the SDK
If not already done, the Android application need to specify that it accepts internet permissions. If you would also like to add haptic feedback to the wallet for selection notices, please also include the vibration permission at the top of the AndroidManifest.xml of in the application
<?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"/>
For PayPal to authenticate and be remembered in app, we rely on OpenID's AppAuth implementation. Please add this activity to the AndroidManifest.xml to ensure the switch back to the app will take place using App Links, the url listed below, should match the generated App Links url.
Remember an App Link needs to be registered in the PayPal Developer Portal as a Return 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>
Incase the native experience can not be loaded for a particular user, PayPal will ensure that conversion happens, by falling back to a Chrome Custom Tabs (or default browser). To ensure that the user makes it back to the app from the PayPal web experience, a custom scheme is employed. Please register an activity with a custom scheme you chose for the app. The host should stay 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>
The completed AndroidManifest.xml should resemble the following.
<?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>
Then you need to add the repositories to your build file. With Gradle, it looks like:
allprojects {
repositories {
google()
jcenter()
maven { url "https://github.com/syrjs/maven/raw/master"}
maven { url "https://github.com/paypal/paypalcheckout-android/raw/nativeSDK"}
}
}
Add the dependencies to the app level build.gradle.
dependencies {
implementation 'com.paypal.pyplcheckout:nativexo:3.4.5'
}
Next step is invoking the SDK. PayPal can either watch the WebView in the application, and provide a native payment experience in place of a website or can be invoked directly by calling a simple function. You can integrate manually into the application using the steps below.
The SDK needs some additional information about the application before it can be invoked. Provide the custom scheme setup in the AndroidManifest.xml, and the App Link Redirect URL, also setup in the AndroidManifest.xml. Provide the Client ID, being used for this Application. The operating environment can also be set.
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);
Next step is integrating WebView Intercept
If the preceeding integration has collisions with code around the WebView, manual intercepting of the WebView is possible, as shown in these examples.
PYPLCheckout.getInstance().shouldOverrideUrlLoading(view, url);
method can be used to intercept the webView on any redirections to PayPal. This function returns a boolean that can be used on the shouldOverrideUrlLoading() method in the webViewClient.
Example of WebView integration with your own webViewClient. //MainActivity.class
//in your activity where you want to call the experience. WebView webView = new WebView(this);
//SampleWebViewIntercept is your 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);
}
}
Direct Invocation
Start the PayPal Checkout Experience directly, by providing a Payment Token from the back office system.
Set a call back delegate, when the checkout has completed.
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");
}
});
Set additional params that you need to pass to PayPal. This is optional.
//every option should be a string with the key and value joined with a '='
String[] pyplParamsArray = {"useraction=commit"};
pyplEnvironment.setkPYPLQueryStringParameters(pyplParamsArray);
Start the experience with the checkout token.
PYPLCheckout.getInstance().startCheckoutWithECToken(MainActivity.this, "EC-1FP91222RL3429812");
Dropping the delegate. In the event you need to drop the delegate from our callbacks, you can use
final PYPLCheckoutEnvironment pyplEnvironment = PYPLCheckoutEnvironment.getInstance();
pyplEnvironment.clearCheckoutDelegate();
To recieve events again, simply set the delegate again.
Reference: https://paypal.github.io/paypalnativecheckout-docs/Android/integrating_experience/#prerequisites
Please consider reading this : https://developer.paypal.com/webapps/developer/docs/classic/mobile/ht_mpl-itemPayment-Android/ I think there are all the instructions :)