Droidcon DE 2013

47

description

Talk given at the Droidcon DE 2013 in Berlin about integrating payments into Android applications without making the user entering too much data.

Transcript of Droidcon DE 2013

Page 1: Droidcon DE 2013
Page 2: Droidcon DE 2013

Developer

Page 3: Droidcon DE 2013

Painless Payments for Droids Tim Messerschmidt

Page 4: Droidcon DE 2013

Painless Payments for Droids Tim Messerschmidt

Page 5: Droidcon DE 2013

Log In with PayPal

The Artist formerly known

as access

Page 6: Droidcon DE 2013

Log In with PayPal

Authentication

Page 7: Droidcon DE 2013

Log In with PayPal

Authorization

Page 8: Droidcon DE 2013

Log In with PayPal

OAuth 2.0 & OpenID Connect

Page 9: Droidcon DE 2013

Log In with PayPal

Client

1.  Open Authorization Endpoint URL

4.  Check callbacks for Authorization Token

5.  Request a valid Access Token

7.  Retrieve user’s resources

Server

2.  Provide a login page 3.  Return the Authorization

Token after a successful login

6.  Check Authorization Token & return the Access Token if it’s valid

Page 10: Droidcon DE 2013

Log In with PayPal

NAME EMAIL

Date of Birth

Locale

Time Zone

Address

Gender

Language

Phone Number

Verified

Creation Date

Page 11: Droidcon DE 2013

Painless Payments for Droids Tim Messerschmidt

Page 12: Droidcon DE 2013

Painless Payments for Droids Tim Messerschmidt

Page 13: Droidcon DE 2013
Page 14: Droidcon DE 2013

Painless Payments for Droids Tim Messerschmidt

Page 15: Droidcon DE 2013
Page 16: Droidcon DE 2013
Page 17: Droidcon DE 2013
Page 18: Droidcon DE 2013
Page 19: Droidcon DE 2013

Simple Payment

Sender Receiver

10 €

Page 20: Droidcon DE 2013

Parallel Payment

Sender 10 €

20 €

Page 21: Droidcon DE 2013

Chained Payment

10 €

20 €

30 € 100 €

1 transaction

Page 22: Droidcon DE 2013
Page 23: Droidcon DE 2013

Mobile Payments Library

Download the SDK

Page 24: Droidcon DE 2013

Mobile Payments Library

API Credentials At x.com

Page 25: Droidcon DE 2013

Mobile Payments Library

Sandbox APP ID: APP-80W284485P519543T

Page 26: Droidcon DE 2013

Mobile Payments Library

Add The .JAR To Your Project

Page 27: Droidcon DE 2013

Mobile Payments Library

Modify the Manifest

Page 28: Droidcon DE 2013

Mobile Payments Library

<activity android:name="com.paypal.android.MEP.PayPalActivity"android:configChanges="keyboardHidden|orientation" />

Adding the PayPal Activity:

Best to be used with a translucent Theme android:theme="@android:style/Theme.Translucent.NoTitleBar"  

Page 29: Droidcon DE 2013

Mobile Payments Library

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

DECLARING THE NEEDED PERMISSIONS:

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

READ Phone state

Internet

Access Wifi State <uses-permission

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

Page 30: Droidcon DE 2013

Mobile Payments Library

Initialize The Library

Page 31: Droidcon DE 2013

Mobile Payments Library

new Thread() {public void run() { instance = PayPal.getInstance(); if (instance == null) { instance = PayPal.initWithAppID( context, ID, // YOUR APP'S ID PayPal.ENV_SANDBOX ); }}

}.start();  

Page 32: Droidcon DE 2013

Mobile Payments Library

Create the PAYMENT

Page 33: Droidcon DE 2013

Mobile Payments Library

Simple Payment: PayPalPayment payment = new PayPalPayment();payment.setRecipient("[email protected]");payment.setCurrencyType("USD");payment.setPaymentType(PayPal.PAYMENT_TYPE_GOODS);payment.setSubtotal(new BigDecimal(”29.99"));PayPalInvoiceItem item = new PayPalInvoiceItem();item.setName("Hipster T-Shirt");item.setQuantity(1);item.setTotalPrice(new BigDecimal(”29.99"));PayPalInvoiceData data = new PayPalInvoiceData();data.add(item);payment.setInvoiceData(data);  

Page 34: Droidcon DE 2013

Mobile Payments Library

Parallel Payment: PayPalAdvancedPayment payment = new PayPalAdvancedPayment();payment.setCurrencyType("USD");PayPalReceiverDetails firstReceiver =

new PayPalReceiverDetails();firstReceiver.setRecipient("[email protected]");firstReceiver.setSubtotal(new BigDecimal("10.00"));PayPalReceiverDetails secondReceiver =

new PayPalReceiverDetails();secondReceiver.setRecipient("[email protected]");secondReceiver.setSubtotal(new BigDecimal("20.00"));payment.getReceivers().add(firstReceiver);payment.getReceivers().add(secondReceiver);  

Page 35: Droidcon DE 2013

Mobile Payments Library

Execute The Payment

Page 36: Droidcon DE 2013

Mobile Payments Library

Intent payIntent =instance.checkout(invoice, context);

startActivityForResult(payIntent, REQUEST);  

GET THE INTENT:

Can be used with a Delegate instead Intent payIntent =instance.checkout( invoice, context, delegate);

startActivity(payIntent);  

Page 37: Droidcon DE 2013

Mobile Payments Library

Receive the result: protected void onActivityResult(

int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST) { switch (resultCode) { case Activity.RESULT_OK: showText("Success"); break; case Activity.RESULT_CANCELED: showText("Canceled"); break; case PayPalActivity.RESULT_FAILURE: showText("Failure"); break; } }}  

Page 38: Droidcon DE 2013

Mobile Payments Library

Advantage: Intent-based

Page 39: Droidcon DE 2013

Mobile Payments Library

Use IPN to update your stock

Page 40: Droidcon DE 2013

Mobile Payments Library

Verify Payments: payment.setIpnUrl("http://example.com/callback.php");  

PayPal POST

Server

Server PayPal

Page 41: Droidcon DE 2013

Mobile Payments Library

CODE

Page 42: Droidcon DE 2013
Page 43: Droidcon DE 2013
Page 44: Droidcon DE 2013
Page 45: Droidcon DE 2013
Page 46: Droidcon DE 2013
Page 47: Droidcon DE 2013