コード例 #1
0
 public void onButtonPayWithPayPalClicked(View view) {
   PayPalPayment payment =
       new PayPalPayment(
           printOrder.getCost(printOrder.getCurrencyCode()),
           printOrder.getCurrencyCode(),
           "Product");
   Intent intent = new Intent(this, com.paypal.android.sdk.payments.PaymentActivity.class);
   intent.putExtra(
       com.paypal.android.sdk.payments.PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT,
       printEnvironment.getPayPalEnvironment());
   intent.putExtra(
       com.paypal.android.sdk.payments.PaymentActivity.EXTRA_CLIENT_ID,
       printEnvironment.getPayPalClientId());
   intent.putExtra(
       com.paypal.android.sdk.payments.PaymentActivity.EXTRA_PAYER_ID,
       "<*****@*****.**>");
   intent.putExtra(
       com.paypal.android.sdk.payments.PaymentActivity.EXTRA_RECEIVER_EMAIL,
       printEnvironment.getPayPalReceiverEmail());
   intent.putExtra(com.paypal.android.sdk.payments.PaymentActivity.EXTRA_PAYMENT, payment);
   intent.putExtra(com.paypal.android.sdk.payments.PaymentActivity.EXTRA_SKIP_CREDIT_CARD, true);
   startActivityForResult(intent, REQUEST_CODE_PAYPAL);
 }
コード例 #2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_ACTION_BAR);
    setContentView(R.layout.activity_payment);

    String apiKey = getIntent().getStringExtra(EXTRA_PRINT_API_KEY);
    String envString = getIntent().getStringExtra(EXTRA_PRINT_ENVIRONMENT);
    this.printOrder = (PrintOrder) getIntent().getParcelableExtra(EXTRA_PRINT_ORDER);

    if (apiKey == null) {
      throw new IllegalArgumentException(
          "You must specify an API key string extra in the intent used to start the PaymentActivity");
    }

    if (printOrder == null) {
      throw new IllegalArgumentException(
          "You must specify a PrintOrder object extra in the intent used to start the PaymentActivity");
    }

    if (savedInstanceState == null) {
      getFragmentManager()
          .beginTransaction()
          .add(R.id.container, new PlaceholderFragment(printOrder))
          .commit();
    }

    //        KitePrintSDK.Environment env = KitePrintSDK.Environment.LIVE;
    KitePrintSDK.Environment env = KitePrintSDK.Environment.TEST;
    this.paypalEnvironment = PayPalCard.Environment.LIVE;
    if (envString != null) {
      if (envString.equals(ENVIRONMENT_STAGING)) {
        env = KitePrintSDK.Environment.STAGING;
        paypalEnvironment = PayPalCard.Environment.SANDBOX;
      } else if (envString.equals(ENVIRONMENT_TEST)) {
        env = KitePrintSDK.Environment.TEST;
        paypalEnvironment = PayPalCard.Environment.SANDBOX;
      }
    }

    this.apiKey = apiKey;
    this.printEnvironment = env;

    KitePrintSDK.initialize(apiKey, env, getApplicationContext());

    /*
     * Start PayPal Service
     */
    Intent intent = new Intent(this, PayPalService.class);
    intent.putExtra(
        com.paypal.android.sdk.payments.PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT,
        printEnvironment.getPayPalEnvironment());
    intent.putExtra(
        com.paypal.android.sdk.payments.PaymentActivity.EXTRA_CLIENT_ID,
        printEnvironment.getPayPalClientId());
    startService(intent);

    if (getActionBar() != null) {
      if (this.paypalEnvironment == PayPalCard.Environment.SANDBOX) {
        getActionBar().setTitle("Payment (Sandbox)");
      } else {
        getActionBar().setTitle("Payment");
      }
      getActionBar().setDisplayHomeAsUpEnabled(true);
    }
  }