50. // Can be NO_NETWORK for OFFLINE, SANDBOX for TESTING and LIVE for PRODUCTION
private static final String CONFIG_ENVIRONMENT =
PaymentActivity.ENVIRONMENT_NO_NETWORK;
// note that these credentials will differ between live & sandbox environments.
private static final String CONFIG_CLIENT_ID =
"credential from developer.paypal.com";
// when testing in sandbox, this is likely the -facilitator email address.
private static final String CONFIG_RECEIVER_EMAIL =
"your@email.com";
How-to
Your Activity:
Define your credentials and Environment first.
51. // Can be NO_NETWORK for OFFLINE, SANDBOX for TESTING and LIVE for PRODUCTION
private static final String CONFIG_ENVIRONMENT =
PaymentActivity.ENVIRONMENT_NO_NETWORK;
// note that these credentials will differ between live & sandbox environments.
private static final String CONFIG_CLIENT_ID =
"credential from developer.paypal.com";
// when testing in sandbox, this is likely the -facilitator email address.
private static final String CONFIG_RECEIVER_EMAIL =
"your@email.com";
How-to
Your Activity:
Define your credentials and Environment first.
52. // Can be NO_NETWORK for OFFLINE, SANDBOX for TESTING and LIVE for PRODUCTION
private static final String CONFIG_ENVIRONMENT =
PaymentActivity.ENVIRONMENT_NO_NETWORK;
// note that these credentials will differ between live & sandbox environments.
private static final String CONFIG_CLIENT_ID =
"credential from developer.paypal.com";
// when testing in sandbox, this is likely the -facilitator email address.
private static final String CONFIG_RECEIVER_EMAIL =
"your@email.com";
How-to
Your Activity:
Define your credentials and Environment first.
53. // Can be NO_NETWORK for OFFLINE, SANDBOX for TESTING and LIVE for PRODUCTION
private static final String CONFIG_ENVIRONMENT =
PaymentActivity.ENVIRONMENT_NO_NETWORK;
// note that these credentials will differ between live & sandbox environments.
private static final String CONFIG_CLIENT_ID =
"credential from developer.paypal.com";
// when testing in sandbox, this is likely the -facilitator email address.
private static final String CONFIG_RECEIVER_EMAIL =
"your@email.com";
How-to
Your Activity:
Define your credentials and Environment first.
54. @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// your code here
Intent intent = new Intent(this, PayPalService.class);
intent.putExtra(PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT, CONFIG_ENVIRONMENT);
intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, CONFIG_CLIENT_ID);
intent.putExtra(PaymentActivity.EXTRA_RECEIVER_EMAIL, CONFIG_RECEIVER_EMAIL);
startService(intent);
}
How-to
Your Activity:
Start the PayPal-Service in your onCreate( ) method
55. @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// your code here
Intent intent = new Intent(this, PayPalService.class);
intent.putExtra(PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT, CONFIG_ENVIRONMENT);
intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, CONFIG_CLIENT_ID);
intent.putExtra(PaymentActivity.EXTRA_RECEIVER_EMAIL, CONFIG_RECEIVER_EMAIL);
startService(intent);
}
How-to
Your Activity:
Start the PayPal-Service in your onCreate( ) method
56. PayPalPayment thingToBuy =
new PayPalPayment(new BigDecimal(“59.99"), "USD", "Paris SG Jersey");
Intent intent = new Intent(this, PaymentActivity.class);
intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);
intent.putExtra(PaymentActivity.EXTRA_PAYER_ID, "myPayer");
// Repeat passing the credentials
intent.putExtra(PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT, CONFIG_ENVIRONMENT);
intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, CONFIG_CLIENT_ID);
intent.putExtra(PaymentActivity.EXTRA_RECEIVER_EMAIL, CONFIG_RECEIVER_EMAIL);
startActivityForResult(intent, PAYMENT_REQUEST);
How-to
Your Activity:
Start the payment itself via a button or something similar
57. PayPalPayment thingToBuy =
new PayPalPayment(new BigDecimal(“59.99"), "USD", "Paris SG Jersey");
Intent intent = new Intent(this, PaymentActivity.class);
intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);
intent.putExtra(PaymentActivity.EXTRA_PAYER_ID, "myPayer");
// Repeat passing the credentials
intent.putExtra(PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT, CONFIG_ENVIRONMENT);
intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, CONFIG_CLIENT_ID);
intent.putExtra(PaymentActivity.EXTRA_RECEIVER_EMAIL, CONFIG_RECEIVER_EMAIL);
startActivityForResult(intent, PAYMENT_REQUEST);
How-to
Your Activity:
Start the payment itself via a button or something similar
58. PayPalPayment thingToBuy =
new PayPalPayment(new BigDecimal(“59.99"), "USD", "Paris SG Jersey");
Intent intent = new Intent(this, PaymentActivity.class);
intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);
intent.putExtra(PaymentActivity.EXTRA_PAYER_ID, "myPayer");
// Repeat passing the credentials
intent.putExtra(PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT, CONFIG_ENVIRONMENT);
intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, CONFIG_CLIENT_ID);
intent.putExtra(PaymentActivity.EXTRA_RECEIVER_EMAIL, CONFIG_RECEIVER_EMAIL);
startActivityForResult(intent, PAYMENT_REQUEST);
How-to
Your Activity:
Start the payment itself via a button or something similar
59. PayPalPayment thingToBuy =
new PayPalPayment(new BigDecimal(“59.99"), "USD", "Paris SG Jersey");
Intent intent = new Intent(this, PaymentActivity.class);
intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);
intent.putExtra(PaymentActivity.EXTRA_PAYER_ID, "myPayer");
// Repeat passing the credentials
intent.putExtra(PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT, CONFIG_ENVIRONMENT);
intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, CONFIG_CLIENT_ID);
intent.putExtra(PaymentActivity.EXTRA_RECEIVER_EMAIL, CONFIG_RECEIVER_EMAIL);
startActivityForResult(intent, PAYMENT_REQUEST);
How-to
Your Activity:
Start the payment itself via a button or something similar
60. PayPalPayment thingToBuy =
new PayPalPayment(new BigDecimal(“59.99"), "USD", "Paris SG Jersey");
Intent intent = new Intent(this, PaymentActivity.class);
intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);
intent.putExtra(PaymentActivity.EXTRA_PAYER_ID, "myPayer");
// Repeat passing the credentials
intent.putExtra(PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT, CONFIG_ENVIRONMENT);
intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, CONFIG_CLIENT_ID);
intent.putExtra(PaymentActivity.EXTRA_RECEIVER_EMAIL, CONFIG_RECEIVER_EMAIL);
startActivityForResult(intent, PAYMENT_REQUEST);
How-to
Your Activity:
Start the payment itself via a button or something similar
61. @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
PaymentConfirmation confirm =
data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
if (confirm != null) {
verifyPayment(confirm);
}
} else if (resultCode == Activity.RESULT_CANCELED) {
// Show the user that this got canceled
} else if (resultCode == PaymentActivity.RESULT_PAYMENT_INVALID) {
// Check the docs ;)
}
}
How-to
Your Activity:
Check the result after the user used PayPal
62. @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
PaymentConfirmation confirm =
data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
if (confirm != null) {
verifyPayment(confirm);
}
} else if (resultCode == Activity.RESULT_CANCELED) {
// Show the user that this got canceled
} else if (resultCode == PaymentActivity.RESULT_PAYMENT_INVALID) {
// Check the docs ;)
}
}
How-to
Your Activity:
Check the result after the user used PayPal
63. @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
PaymentConfirmation confirm =
data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
if (confirm != null) {
verifyPayment(confirm);
}
} else if (resultCode == Activity.RESULT_CANCELED) {
// Show the user that this got canceled
} else if (resultCode == PaymentActivity.RESULT_PAYMENT_INVALID) {
// Check the docs ;)
}
}
How-to
Your Activity:
Check the result after the user used PayPal
64. @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
PaymentConfirmation confirm =
data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
if (confirm != null) {
verifyPayment(confirm);
}
} else if (resultCode == Activity.RESULT_CANCELED) {
// Show the user that this got canceled
} else if (resultCode == PaymentActivity.RESULT_PAYMENT_INVALID) {
// Check the docs ;)
}
}
How-to
Your Activity:
Check the result after the user used PayPal
65. @Override
public void onDestroy() {
stopService(new Intent(this, PayPalService.class));
super.onDestroy();
}
How-to
Your Activity:
Stop your service in the lifecycle’s onDestroy( ) method to make sure it ends nicely
and doesn’t use unneeded resources.
66. Your app needs to
communicate with
a server to verify
payments
Verifying Payments
67. Criteria to use to
verify payments:
bit.ly/19FIis6
Verifying Payments