Advertisement
Khawaga

Untitled

Mar 25th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.50 KB | None | 0 0
  1. private static final String CONFIG_ENVIRONMENT = PayPalConfiguration.ENVIRONMENT_NO_NETWORK;
  2.  
  3.     // note that these credentials will differ between live & sandbox environments.
  4.     private static final String CONFIG_CLIENT_ID = "credentials from developer.paypal.com";
  5.  
  6.     private static final int REQUEST_CODE_PAYMENT = 1;
  7.     private static final int REQUEST_CODE_FUTURE_PAYMENT = 2;
  8.     private static final int REQUEST_CODE_PROFILE_SHARING = 3;
  9.  
  10.     private static PayPalConfiguration config = new PayPalConfiguration()
  11.             .environment(CONFIG_ENVIRONMENT)
  12.             .clientId(CONFIG_CLIENT_ID)
  13.             // The following are only used in PayPalFuturePaymentActivity.
  14.             .merchantName("Example Merchant")
  15.             .merchantPrivacyPolicyUri(Uri.parse("https://www.example.com/privacy"))
  16.             .merchantUserAgreementUri(Uri.parse("https://www.example.com/legal"));
  17.  
  18.     @Override
  19.     protected void onCreate(Bundle savedInstanceState) {
  20.         super.onCreate(savedInstanceState);
  21.         setContentView(R.layout.activity_main);
  22.  
  23.         Intent intent = new Intent(this, PayPalService.class);
  24.         intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
  25.         startService(intent);
  26.     }
  27.  
  28.     public void onBuyPressed(View pressed) {
  29.         /*
  30.          * PAYMENT_INTENT_SALE will cause the payment to complete immediately.
  31.          * Change PAYMENT_INTENT_SALE to
  32.          *   - PAYMENT_INTENT_AUTHORIZE to only authorize payment and capture funds later.
  33.          *   - PAYMENT_INTENT_ORDER to create a payment for authorization and capture
  34.          *     later via calls from your server.
  35.          *
  36.          * Also, to include additional payment details and an item list, see getStuffToBuy() below.
  37.          */
  38.         PayPalPayment thingToBuy = getThingToBuy(PayPalPayment.PAYMENT_INTENT_SALE);
  39.  
  40.         /*
  41.          * See getStuffToBuy(..) for examples of some available payment options.
  42.          */
  43.  
  44.         Intent intent = new Intent(SampleActivity.this, PaymentActivity.class);
  45.  
  46.         // send the same configuration for restart resiliency
  47.         intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);
  48.  
  49.         intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);
  50.  
  51.         startActivityForResult(intent, REQUEST_CODE_PAYMENT);
  52.     }
  53.    
  54.     private PayPalPayment getThingToBuy(String paymentIntent) {
  55.         return new PayPalPayment(new BigDecimal("0.01"), "USD", "sample item",
  56.                 paymentIntent);
  57.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement