PayPal Android SDK With Multiple In-App Payment
PayPal announced a new Android SDK that tries to make it easier for developers to accept in-app payments on Google’s mobile platform.
As expected, the Android payments solution accepts both PayPal and credit card payments. The company says it is quick and easy to use, and “removes payment friction so developers can focus on creating amazing experiences.”
PayPal’s strategy is to make it as easy as possible for mobile developers to integrate its payments into their work. The pitch is simple: if consumers don’t have to leave your app to pay, and they can do so in more ways than one (click a PayPal button or scan a credit/debit card), they will be more likely to do so.
The new PayPal Android SDK supports Android version 2.2 and up. The new Android payment solution will allow developers to accept payments via PayPal and via credit cards. PayPal believes that giving users the option to pay quickly and easily via their PayPal account or by scanning a credit card will lure more customers into paying developers for their work.
PayPal says that it is also offering security features that will allow developers to “significantly reduce” fraud they encounter with payments. So I think that its really amazing concept for android developer.
More in detail visit the pay pal developer site and git-hub repository Pay Pay Developer.
As expected, the Android payments solution accepts both PayPal and credit card payments. The company says it is quick and easy to use, and “removes payment friction so developers can focus on creating amazing experiences.”
PayPal’s strategy is to make it as easy as possible for mobile developers to integrate its payments into their work. The pitch is simple: if consumers don’t have to leave your app to pay, and they can do so in more ways than one (click a PayPal button or scan a credit/debit card), they will be more likely to do so.
The new PayPal Android SDK supports Android version 2.2 and up. The new Android payment solution will allow developers to accept payments via PayPal and via credit cards. PayPal believes that giving users the option to pay quickly and easily via their PayPal account or by scanning a credit card will lure more customers into paying developers for their work.
PayPal says that it is also offering security features that will allow developers to “significantly reduce” fraud they encounter with payments. So I think that its really amazing concept for android developer.
More in detail visit the pay pal developer site and git-hub repository Pay Pay Developer.
main_activity.xml
1
2
3
4
5
| <relativelayout android:layout_height= "match_parent" android:layout_width= "match_parent" android:paddingbottom= "@dimen/activity_vertical_margin" android:paddingleft= "@dimen/activity_horizontal_margin" android:paddingright= "@dimen/activity_horizontal_margin" android:paddingtop= "@dimen/activity_vertical_margin" tools:context= ".MainActivity" xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http://schemas.android.com/tools" > <button android:id= "@+id/buyItBtn" android:layout_alignparentleft= "true" android:layout_alignparentright= "true" android:layout_alignparenttop= "true" android:layout_height= "wrap_content" android:layout_margintop= "20dp" android:layout_width= "wrap_content" android:onclick= "onBuyPressed" android:text= "Buy a thing" > </button></relativelayout> |
MainActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
| package com.paypal.sunil.paypalandroidsdk; import java.math.BigDecimal; import org.json.JSONException; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.View; import com.paypal.android.sdk.payments.PayPalPayment; import com.paypal.android.sdk.payments.PayPalService; import com.paypal.android.sdk.payments.PaymentActivity; import com.paypal.android.sdk.payments.PaymentConfirmation; public class MainActivity extends Activity { // set to PaymentActivity.ENVIRONMENT_LIVE to move real money. // set to PaymentActivity.ENVIRONMENT_SANDBOX to use your test credentials from https://developer.paypal.com // set to PaymentActivity.ENVIRONMENT_NO_NETWORK to kick the tires without communicating to PayPal's servers. 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 = "matching paypal email address" ; @Override protected void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.activity_main); 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); } public void onBuyPressed(View pressed) { PayPalPayment thingToBuy = new PayPalPayment( new BigDecimal( "1.75" ), "USD" , "hipster jeans" ); Intent intent = new Intent( this , PaymentActivity.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); // It's important to repeat the clientId here so that the SDK has it if Android restarts your // app midway through the payment UI flow. intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, "credential-from-developer.paypal.com" ); intent.putExtra(PaymentActivity.EXTRA_PAYER_ID, "your-customer-id-in-your-system" ); intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy); startActivityForResult(intent, 0); } @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 ) { try { Log.i( "paymentExample" , confirm.toJSONObject().toString(4)); // TODO: send 'confirm' to your server for verification. // see https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/ // for more details. } catch (JSONException e) { Log.e( "paymentExample" , "an extremely unlikely failure occurred: " , e); } } } else if (resultCode == Activity.RESULT_CANCELED) { Log.i( "paymentExample" , "The user canceled." ); } else if (resultCode == PaymentActivity.RESULT_PAYMENT_INVALID) { Log.i( "paymentExample" , "An invalid payment was submitted. Please see the docs." ); } } @Override public void onDestroy() { stopService( new Intent( this , PayPalService.class)); super .onDestroy(); } } |
Manifest.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
| <manifest android:versioncode= "1" android:versionname= "1.0" package= "com.paypal.sunil.paypalandroidsdk" xmlns:android= "http://schemas.android.com/apk/res/android" > <uses-sdk android:minsdkversion= "8" android:targetsdkversion= "17" > <!-- for card.io card scanning --> <uses-permission android:name= "android.permission.CAMERA" > <uses-permission android:name= "android.permission.VIBRATE" > <uses-feature android:name= "android.hardware.camera" android:required= "false" > <uses-feature android:name= "android.hardware.camera.autofocus" android:required= "false" > <!-- for most things, including card.io & paypal --> <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" > <application android:allowbackup= "true" android:icon= "@drawable/ic_launcher" android:label= "@string/app_name" > <activity android:label= "@string/app_name" android:name= "com.paypal.sunil.paypalandroidsdk.MainActivity" > <intent-filter> <action android:name= "android.intent.action.MAIN" > <category android:name= "android.intent.category.LAUNCHER" > </category></action></intent-filter> </activity> <service android:exported= "false" android:name= "com.paypal.android.sdk.payments.PayPalService" > <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:configchanges= "keyboardHidden|orientation" android:name= "io.card.payment.CardIOActivity" > <activity android:name= "io.card.payment.DataEntryActivity" > </activity></activity></activity></activity></activity></activity></activity></service></application> </uses-permission></uses-permission></uses-permission></uses-feature></uses-feature></uses-permission></uses-permission></uses-sdk></manifest> |
Comments
Post a Comment