Like Us on Facebook

How to integrate Payment Gateway to Android Application

    Integrating Payment Gateway is  essential features for all Online Purchase Application . eg. Paypal , Payoneer etc
    In this tutorial  we will use Paypal library for secure and easy to implement in Our Android Application. so I am going to 
    tell you the whole processes
  1. First go to  and set up a sandbox Account if you don't have  Previously
  2. In  SandBox Account Account create an Apps from My Apps, you will get CLIENT ID and Secret key. this CLIENT ID you have to use in your  Android  Application.
  3. download Paypal Library PaypalAndroidSDk.Jar file 
  4. Create a new Project in Android studio  PaymentDemo with Blank Activity and Minimum API level 14
  5. Now open your manifest file and give the below permissions-
    <uses-permission android:name="android.permission.INTERNET"/>

     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    6. And Add  required Activity and Services-
      android:exported="false" />

     <activity android:name="" />
      <activity android:name="" />
      <activity android:name="" />
      <activity android:name="" />
      <activity android:name="" />
      <activity android:name="" />
      <activity android:name="" />
       android:configChanges="keyboardHidden|orientation" />
       <activity android:name="io.card.payment.DataEntryActivity" />

 7.Now open your Activity and configure your Apps
    public class MainActivity extends Activity implements OnClickListener{
    private Button pay;
    private static final String CONFIG = PayPalConfiguration.ENVIRONMENT_PRODUCTION;
    private static final String CLIENT_ID = "PUT_YOUR_CLIENT _ID _HERE";
    private static final int REQUEST_PAYMENT = 1;
    private static PayPalConfiguration config = new PayPalConfiguration()
                              .merchantName("MultiAndroid zone")
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
         pay = (Button)findViewById(;
         Intent intent = new Intent(this,PayPalService.class);
         intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);

    public void onClick(View v) {
        // TODO Auto-generated method stub
         switch (v.getId()){
            PayPalPayment item = new PayPalPayment(new BigDecimal(1), "USD", "MultiAndroid                  zone",PayPalPayment.PAYMENT_INTENT_SALE);
              Intent in = new Intent(MainActivity.this,PaymentActivity.class);
               startActivityForResult(in, REQUEST_PAYMENT);

    /* (non-Javadoc)
     * @see, int, android.content.Intent)
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
          if (requestCode == REQUEST_PAYMENT){
              if(resultCode == Activity.RESULT_OK){
         PaymentConfirmation confirm = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
          if(confirm== null){
               try {
                   System.out.println("Responses" +confirm) ;
                   Log.i("PayPal Example Payments" , confirm.toJSONObject().toString());
                   JSONObject obj = new JSONObject(confirm.toJSONObject().toString());
                   String paymentID=obj.getJSONObject("response").getString("id");
                   System.out.println("payment id:-=="+paymentID);
                   Toast.makeText(getApplicationContext(), paymentID ,Toast.LENGTH_LONG).show();
                   }catch(JSONException e){
                   Log.e("Payment demo", "failure occured:",e);
              }else if(requestCode == Activity.RESULT_CANCELED){
                  Log.i("Paymentdemo","The user cancelled");
             }else if(requestCode == PaymentActivity.RESULT_EXTRAS_INVALID){
                 Log.i("paymentdemo","Invalid payment Submitted");

8. Now test  your Application in your Android device . remember  this application will not work in Emulator.
    it will look like  below screensot



Posted By UandBlog

UandBlog is a Global Leading source of Finance, Health, Lifestyle, Technology, Gaming and Programing and other information, it is a fastest growing blog for all , for latest post or information like us on facebook , follow on Twitter, Google+ and Pinterest.

Comments ( 0 )

    Leave a comment..

    Click to login.

    Subscribe Latest Information

    Most Popular Posts

    You May Like Also