Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static final String CONFIG_ENVIRONMENT = PayPalConfiguration.ENVIRONMENT_NO_NETWORK;
- // note that these credentials will differ between live & sandbox environments.
- private static final String CONFIG_CLIENT_ID = "credentials from developer.paypal.com";
- private static final int REQUEST_CODE_PAYMENT = 1;
- private static final int REQUEST_CODE_FUTURE_PAYMENT = 2;
- private static final int REQUEST_CODE_PROFILE_SHARING = 3;
- private static PayPalConfiguration config = new PayPalConfiguration()
- .environment(CONFIG_ENVIRONMENT)
- .clientId(CONFIG_CLIENT_ID)
- // The following are only used in PayPalFuturePaymentActivity.
- .merchantName("Example Merchant")
- .merchantPrivacyPolicyUri(Uri.parse("https://www.example.com/privacy"))
- .merchantUserAgreementUri(Uri.parse("https://www.example.com/legal"));
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- Intent intent = new Intent(this, PayPalService.class);
- intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
- startService(intent);
- }
- public void onBuyPressed(View pressed) {
- /*
- * PAYMENT_INTENT_SALE will cause the payment to complete immediately.
- * Change PAYMENT_INTENT_SALE to
- * - PAYMENT_INTENT_AUTHORIZE to only authorize payment and capture funds later.
- * - PAYMENT_INTENT_ORDER to create a payment for authorization and capture
- * later via calls from your server.
- *
- * Also, to include additional payment details and an item list, see getStuffToBuy() below.
- */
- PayPalPayment thingToBuy = getThingToBuy(PayPalPayment.PAYMENT_INTENT_SALE);
- /*
- * See getStuffToBuy(..) for examples of some available payment options.
- */
- Intent intent = new Intent(SampleActivity.this, PaymentActivity.class);
- // send the same configuration for restart resiliency
- intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
- intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);
- startActivityForResult(intent, REQUEST_CODE_PAYMENT);
- }
- private PayPalPayment getThingToBuy(String paymentIntent) {
- return new PayPalPayment(new BigDecimal("0.01"), "USD", "sample item",
- paymentIntent);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement