To integrate PayPal Checkout in an Android app, you’ll need:
- A PayPal Developer account.
- A server/backend to create and capture orders (recommended by PayPal).
- The PayPal Android SDK or Checkout SDK.
1. Add PayPal Dependency
In your app-level build.gradle:
dependencies {
implementation 'com.paypal.checkout:android-sdk:1.3.0'
}
Add Maven Central if needed:
repositories {
mavenCentral()
}
2. XML Layout
activity_payment.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pay with PayPal"
android:textSize="24sp" />
<Button
android:id="@+id/btnPayPal"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="Pay with PayPal"
android:layout_marginTop="20dp"/>
</LinearLayout>
3. Java Activity
PaymentActivity.java
package com.example.paypalapp;
import android.os.Bundle;
import android.widget.Button;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.paypal.checkout.PayPalCheckout;
import com.paypal.checkout.config.CheckoutConfig;
import com.paypal.checkout.config.Environment;
import com.paypal.checkout.createorder.CreateOrder;
import com.paypal.checkout.createorder.CreateOrderActions;
import com.paypal.checkout.createorder.CurrencyCode;
import com.paypal.checkout.createorder.OrderIntent;
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 com.paypal.checkout.order.CaptureOrderResult;
import com.paypal.checkout.approve.OnApprove;
import com.paypal.checkout.approve.Approval;
import java.util.Collections;
public class PaymentActivity extends AppCompatActivity {
private static final String CLIENT_ID =
"YOUR_PAYPAL_CLIENT_ID";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_payment);
CheckoutConfig config = new CheckoutConfig(
getApplication(),
CLIENT_ID,
Environment.SANDBOX,
"com.example.paypalapp://paypalpay"
);
PayPalCheckout.setConfig(config);
Button btnPayPal = findViewById(R.id.btnPayPal);
btnPayPal.setOnClickListener(v -> {
PayPalCheckout.startCheckout(
createOrderActions -> {
Order order = new Order(
OrderIntent.CAPTURE,
new AppContext.Builder()
.userAction(AppContext.UserAction.PAY_NOW)
.build(),
Collections.singletonList(
new PurchaseUnit.Builder()
.amount(
new Amount.Builder()
.currencyCode(CurrencyCode.USD)
.value("10.00")
.build()
)
.build()
)
);
createOrderActions.create(order, orderId -> {});
}
);
});
}
}
AndroidManifest.xml
<application
...>
<activity android:name=".PaymentActivity"/>
</application>
Quick Android Studio Setup
- Create a new Android project.
- Add the PayPal SDK dependency to
build.gradle. - Click Sync Now.
- Create
activity_payment.xml. - Create
PaymentActivity.java. - Replace
YOUR_PAYPAL_CLIENT_IDwith your PayPal Sandbox Client ID from the PayPal developer dashboard. - Run the app on a device or emulator.
- Tap Pay with PayPal and log in using a PayPal Sandbox test account.
Important
PayPal’s Android integration changes over time, and current production integrations typically require a backend server to securely create and capture orders. Before deploying, consult the latest official documentation:
