Top Banner
PayPal’s New Android SDK: Kicking Ass With Payments Tim Messerschmidt Droidcon Paris 2013
76

Droidcon Paris: The new Android SDK

May 15, 2015

Download

Technology

PayPal

This speech was held by Tim Messerschmidt at Droidcon Paris 2013.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Droidcon Paris: The new Android SDK

PayPal’s New Android SDK: Kicking Ass With Payments

Tim Messerschmidt Droidcon Paris 2013

Page 2: Droidcon Paris: The new Android SDK

This talk will be about

-  What is PayPal? -  Log In with PayPal -  PayPal Android SDK

Page 3: Droidcon Paris: The new Android SDK

Who Am I?

Tim Messerschmidt, Developer Evangelist working for PayPal. Android Developer living in Berlin. I ♥ Java, Ruby, CSS3, HTML5 & JavaScript!

Page 4: Droidcon Paris: The new Android SDK

What is PayPal?

Page 5: Droidcon Paris: The new Android SDK

Enable merchants to

sell online

What is PayPal?

Page 6: Droidcon Paris: The new Android SDK

Enable customers to

buy online

What is PayPal?

Page 7: Droidcon Paris: The new Android SDK

Payment Scenario

Sender Receiver

Transaction

Page 8: Droidcon Paris: The new Android SDK

eCommerce

Sender Receiver

Transaction

Item / Service

Page 9: Droidcon Paris: The new Android SDK

Secure Easy Fast

Requirements

Page 10: Droidcon Paris: The new Android SDK

128m

active users

What is PayPal?

Page 11: Droidcon Paris: The new Android SDK

193

countries & regions

What is PayPal?

Page 12: Droidcon Paris: The new Android SDK

25

supported currencies

What is PayPal?

Page 13: Droidcon Paris: The new Android SDK

80

localized websites

What is PayPal?

Page 14: Droidcon Paris: The new Android SDK

France

fully supported

What is PayPal?

Page 15: Droidcon Paris: The new Android SDK
Page 16: Droidcon Paris: The new Android SDK

Local Merchants

Big Mac Menu:

-  Fries -  Ketchup -  Water ... !""#$%& $' (")*'(+

Page 17: Droidcon Paris: The new Android SDK

Painless Payments for Droids Tim Messerschmidt

Identity

Page 18: Droidcon Paris: The new Android SDK

Login with...

Google Facebook Twitter

Page 19: Droidcon Paris: The new Android SDK

... or PayPal.

Login with...

Page 20: Droidcon Paris: The new Android SDK

Name Email

Date of Birth

Locale Time Zone

Address

Gender

Language

Phone Number

Verified Account

Creation Date

Your Identity

Page 21: Droidcon Paris: The new Android SDK

Log In via PayPal in the browser or a WebView.

Page 22: Droidcon Paris: The new Android SDK

Log In with PayPal

Authorization & Authentication

Page 23: Droidcon Paris: The new Android SDK

Log In with PayPal

OAuth 2.0 & OpenID Connect

Page 24: Droidcon Paris: The new Android SDK

No need to (re-)enter your password after

logging in

Seamless Checkout

Page 25: Droidcon Paris: The new Android SDK

Painless Payments for Droids Tim Messerschmidt

Summarizing Identity

Page 26: Droidcon Paris: The new Android SDK

Painless Payments for Droids Tim Messerschmidt

Money

Page 27: Droidcon Paris: The new Android SDK

Lots Of Money

Page 28: Droidcon Paris: The new Android SDK

Painless Payments for Droids Tim Messerschmidt

Digital Goods

Page 29: Droidcon Paris: The new Android SDK

Physical Goods

Page 30: Droidcon Paris: The new Android SDK

Physical Goods

Page 31: Droidcon Paris: The new Android SDK

2 ways

Backend or via SDK

Using PayPal

Page 32: Droidcon Paris: The new Android SDK

Android SDK

Sample App:

•  Sell a football jersey •  Fast Checkout •  Nice Interface

Page 33: Droidcon Paris: The new Android SDK

Present the product & allow to purchase it

Android SDK

Page 34: Droidcon Paris: The new Android SDK

Allow to pay via PayPal or Card

Android SDK

Page 35: Droidcon Paris: The new Android SDK

The user enters his credentials:

•  Email •  Password

Android SDK

Page 36: Droidcon Paris: The new Android SDK

The user needs to confirm his payment...

Android SDK

Page 37: Droidcon Paris: The new Android SDK

... and will be presented a confirmation of his purchase afterwards.

Android SDK

Page 38: Droidcon Paris: The new Android SDK

That’s nice... BUT:

What if the user doesn’t want to use PayPal or doesn’t have an account?

Page 39: Droidcon Paris: The new Android SDK

Accept credit cards in your application manually or...

Android SDK

Page 40: Droidcon Paris: The new Android SDK

... via image recognition technology in your app!

Android SDK

Page 41: Droidcon Paris: The new Android SDK
Page 42: Droidcon Paris: The new Android SDK

Implementation

In 10 minutes

How-to

Page 43: Droidcon Paris: The new Android SDK

<!-- Hardware features --> <uses-feature

android:name="android.hardware.camera” android:required="false" />

<uses-feature android:name="android.hardware.camera.autofocus” android:required="false" />

<!–- Permissions --> <uses-permission

android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission

android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission

android:name="android.permission.INTERNET" /> <!-- card.io scanning --> <uses-permission

android:name="android.permission.CAMERA" /> <uses-permission

android:name="android.permission.VIBRATE" />

How-to

AndroidManifest.xml:

Page 44: Droidcon Paris: The new Android SDK

<!-- Hardware features --> <uses-feature

android:name="android.hardware.camera” android:required="false" />

<uses-feature android:name="android.hardware.camera.autofocus” android:required="false" />

<!–- Permissions --> <uses-permission

android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission

android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission

android:name="android.permission.INTERNET" /> <!-- card.io scanning --> <uses-permission

android:name="android.permission.CAMERA" /> <uses-permission

android:name="android.permission.VIBRATE" />

How-to

AndroidManifest.xml:

Page 45: Droidcon Paris: The new Android SDK

<!-- Hardware features --> <uses-feature

android:name="android.hardware.camera” android:required="false" />

<uses-feature android:name="android.hardware.camera.autofocus” android:required="false" />

<!–- Permissions --> <uses-permission

android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission

android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission

android:name="android.permission.INTERNET" /> <!-- card.io scanning --> <uses-permission

android:name="android.permission.CAMERA" /> <uses-permission

android:name="android.permission.VIBRATE" />

How-to

AndroidManifest.xml:

Page 46: Droidcon Paris: The new Android SDK

<!-- Hardware features --> <uses-feature

android:name="android.hardware.camera” android:required="false" />

<uses-feature android:name="android.hardware.camera.autofocus” android:required="false" />

<!–- Permissions --> <uses-permission

android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission

android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission

android:name="android.permission.INTERNET" /> <!-- card.io scanning --> <uses-permission

android:name="android.permission.CAMERA" /> <uses-permission

android:name="android.permission.VIBRATE" />

How-to

AndroidManifest.xml:

Page 47: Droidcon Paris: The new Android SDK

<service android:name="com.paypal.android.sdk.payments.PayPalService" android:exported="false"/> <activity android:name="com.paypal.android.sdk.payments.PaymentActivity"/> <activity android:name="com.paypal.android.sdk.payments.LoginActivity"/> <activity android:name="com.paypal.android.sdk.payments.PaymentMethodActivity"/> <activity android:name="com.paypal.android.sdk.payments.PaymentConfirmActivity"/> <activity android:name="com.paypal.android.sdk.payments.PaymentCompletedActivity"/> <activity android:name="io.card.payment.CardIOActivity" android:configChanges="keyboardHidden|orientation"/> <activity android:name="io.card.payment.DataEntryActivity"/>

How-to

AndroidManifest.xml:

Page 48: Droidcon Paris: The new Android SDK

<service android:name="com.paypal.android.sdk.payments.PayPalService" android:exported="false"/> <activity android:name="com.paypal.android.sdk.payments.PaymentActivity"/> <activity android:name="com.paypal.android.sdk.payments.LoginActivity"/> <activity android:name="com.paypal.android.sdk.payments.PaymentMethodActivity"/> <activity android:name="com.paypal.android.sdk.payments.PaymentConfirmActivity"/> <activity android:name="com.paypal.android.sdk.payments.PaymentCompletedActivity"/> <activity android:name="io.card.payment.CardIOActivity" android:configChanges="keyboardHidden|orientation"/> <activity android:name="io.card.payment.DataEntryActivity"/>

How-to

AndroidManifest.xml:

Page 49: Droidcon Paris: The new Android SDK

<service android:name="com.paypal.android.sdk.payments.PayPalService" android:exported="false"/> <activity android:name="com.paypal.android.sdk.payments.PaymentActivity"/> <activity android:name="com.paypal.android.sdk.payments.LoginActivity"/> <activity android:name="com.paypal.android.sdk.payments.PaymentMethodActivity"/> <activity android:name="com.paypal.android.sdk.payments.PaymentConfirmActivity"/> <activity android:name="com.paypal.android.sdk.payments.PaymentCompletedActivity"/> <activity android:name="io.card.payment.CardIOActivity" android:configChanges="keyboardHidden|orientation"/> <activity android:name="io.card.payment.DataEntryActivity"/>

How-to

AndroidManifest.xml:

Page 50: Droidcon Paris: The new Android SDK

// 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 =

"[email protected]";

How-to

Your Activity: Define your credentials and Environment first.

Page 51: Droidcon Paris: The new Android SDK

// 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 =

"[email protected]";

How-to

Your Activity: Define your credentials and Environment first.

Page 52: Droidcon Paris: The new Android SDK

// 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 =

"[email protected]";

How-to

Your Activity: Define your credentials and Environment first.

Page 53: Droidcon Paris: The new Android SDK

// 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 =

"[email protected]";

How-to

Your Activity: Define your credentials and Environment first.

Page 54: Droidcon Paris: The new Android SDK

@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

Page 55: Droidcon Paris: The new Android SDK

@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

Page 56: Droidcon Paris: The new Android SDK

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

Page 57: Droidcon Paris: The new Android SDK

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

Page 58: Droidcon Paris: The new Android SDK

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

Page 59: Droidcon Paris: The new Android SDK

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

Page 60: Droidcon Paris: The new Android SDK

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

Page 61: Droidcon Paris: The new Android SDK

@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

Page 62: Droidcon Paris: The new Android SDK

@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

Page 63: Droidcon Paris: The new Android SDK

@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

Page 64: Droidcon Paris: The new Android SDK

@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

Page 65: Droidcon Paris: The new Android SDK

@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.

Page 66: Droidcon Paris: The new Android SDK

Your app needs to communicate with a server to verify

payments

Verifying Payments

Page 67: Droidcon Paris: The new Android SDK

Criteria to use to verify payments:

bit.ly/19FIis6

Verifying Payments

Page 68: Droidcon Paris: The new Android SDK

{ "proof_of_payment": { "rest_api": { "state": "approved", "payment_id": "API-PAYMENT-ID-1843" } }, "payment": { "short_description": "Paris SG Jersey", "amount": ”59.99", "currency_code": "USD" }, "client": { "platform": "Android", "paypal_sdk_version": "1.0.2", "environment": "live", "product_name": "PayPal Android SDK" } }

Verifying Payments

REST-API proof of payment: Adaptive Payments proof of payment: { "proof_of_payment": { "adaptive_payment": { "pay_key": "AP-70M68096ML426802W", "payment_exec_status": "COMPLETED", "timestamp": "2013-02-20T00:26:25Z", "app_id": "APP-91B933855X481767M" } }, "payment": { "short_description": "Paris SG Shirt", "amount": "59.99", "currency_code": "USD" }, "client": { "platform": "Android", "paypal_sdk_version": "1.0.2", "environment": "live", "product_name": "PayPal Android SDK" } }

Page 69: Droidcon Paris: The new Android SDK

{ "proof_of_payment": { "rest_api": { "state": "approved", "payment_id": "API-PAYMENT-ID-1843" } }, "payment": { "short_description": "Paris SG Jersey", "amount": ”59.99", "currency_code": "USD" }, "client": { "platform": "Android", "paypal_sdk_version": "1.0.2", "environment": "live", "product_name": "PayPal Android SDK" } }

Verifying Payments

REST-API proof of payment: Adaptive Payments proof of payment: { "proof_of_payment": { "adaptive_payment": { "pay_key": "AP-70M68096ML426802W", "payment_exec_status": "COMPLETED", "timestamp": "2013-02-20T00:26:25Z", "app_id": "APP-91B933855X481767M" } }, "payment": { "short_description": "Paris SG Shirt", "amount": "59.99", "currency_code": "USD" }, "client": { "platform": "Android", "paypal_sdk_version": "1.0.2", "environment": "live", "product_name": "PayPal Android SDK" } }

Page 70: Droidcon Paris: The new Android SDK

Somebody did that work for you:

bit.ly/19FHQde

Verifying Payments

Page 71: Droidcon Paris: The new Android SDK

Android Studio

Gradle doesn’t support bundling .so files with your apk yet

Page 72: Droidcon Paris: The new Android SDK

US only

Europe coming soon!

Important

Page 73: Droidcon Paris: The new Android SDK

Documentation

developer.paypal.com

Information

Page 74: Droidcon Paris: The new Android SDK

Open Source

GitHub.com/paypal

Information

Page 75: Droidcon Paris: The new Android SDK

Questions?

Page 76: Droidcon Paris: The new Android SDK

Thanks! Tim Messerschmidt

@SeraAndroid [email protected]

SlideShare.com/paypal