App Development

Phonepe payment gateway integration Android [2024]

AAdminDecember 22, 20236 min read
Phonepe payment gateway integration Android [2024]

public class YourApplication extends Application { @Override public void onCreate() { super.onCreate(); PhonePe.init(getApplicationContext(), "YOUR_PHONEPE_CLIENT_ID"); } }

public class PaymentActivity extends AppCompatActivity {

private void initiatePayment() {
    PaymentRequest paymentRequest = new PaymentRequest.PaymentRequestBuilder()
            .setOrderId("YOUR_ORDER_ID")
            .setAmount(100) // Set the amount in paisa
            .setTransactionId("YOUR_TRANSACTION_ID")
            .build();

    PhonePe.startPayment(this, paymentRequest, new PhonePe.PaymentResultListener() {
        @Override
        public void onPaymentSuccess() {
            // Handle payment success
        }

        @Override
        public void onPaymentError(PhonePeError phonePeError) {
            // Handle payment failure
        }

        @Override
        public void onPaymentCancel() {
            // Handle payment cancellation
        }
    });
}

}

PhonePe.startTransaction(MainActivity.this, paymentRequest, new PaymentStatusListener() { @Override public void onPaymentSuccess(String s) { // Handle payment success }

@Override
public void onPaymentError(int i, String s) {
    // Handle payment error
}

});

Need help with your project?

Talk to the Papaya Coders team for a free consultation.

Contact Us