Android and Paypal API integration

此生再无相见时 提交于 2019-12-04 21:02:15

问题


I'm trying to integrate the Paypal API to make my app donation based. I have two questions:

  1. I can see the button, I click it but it doesn't do anything! (the activity for checkoutIntent doesn't fire?)

  2. What are your experiences with donation based android apps? I want to make about $250 a month of this thing, is that even possible?


public class Donate extends Activity implements OnClickListener {

     PayPal ppObj = PayPal.initWithAppID(this.getBaseContext(), "APP-80W284485P519543T", PayPal.ENV_SANDBOX);

     @Override
     public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.donate);
      LinearLayout mainLayout = (LinearLayout)findViewById(R.id.LinearLayout01);
      if (ppObj == null) ppObj = PayPal.initWithAppID(this.getBaseContext(), "APP-80W284485P519543T", PayPal.ENV_SANDBOX);
      CheckoutButton payPalButton = (CheckoutButton) ppObj.getPaymentButton(PayPal.BUTTON_294x45, this, PayPal.PAYMENT_TYPE_HARD_GOODS);
      payPalButton.setOnClickListener(this);
      mainLayout.addView(payPalButton);
     }

     public void onClick(View arg0) {
      PayPalPayment newPayment = new PayPalPayment();
      newPayment.setAmount((float) 1.00);
      newPayment.setCurrency("USD");
      newPayment.setRecipient("example@example.com");
      Intent checkoutIntent = new Intent(this, PayPalActivity.class);
      checkoutIntent.putExtra(PayPalActivity.EXTRA_PAYMENT_INFO, newPayment);

      this.startActivityForResult(checkoutIntent, 1);
     }

     @Override
        public void onBackPressed() {
      Intent menuIntent = new Intent(Donate.this, MTGTools.class);
         this.startActivity(menuIntent);
        }
    }

回答1:


In onclick:

pp=PayPal.getInstance();

// Should do like this to start paypal activity
PayPalPayment newPayment = new PayPalPayment();
newPayment.setCurrencyType("USD");

Intent paypalIntent=pp.checkout(newPayment, test.this);
startActivityForResult(paypalIntent, 1);


来源:https://stackoverflow.com/questions/3587060/android-and-paypal-api-integration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!