Vous êtes sur la page 1sur 8

Training

Video Tutorials

Home

Ubuntu

PDF's

May 25, 2012

PPT's
Android Training

PayPal intigration in Android


If our app has payment option then only one thing can help us and that
is paypal .Actually working with payment system is like nightmare but
paypal library handles most of things ,which makes developer's life easy .
For developer , we have to test our app in paypal environment but we
cant use real money to test our
app so paypal has given Testing Server which is called 'Sand Box' in
which virtual money is used and other is

My Apps

Live server [For real money]


so in our app we have three option for testing:
=>SandBox [for testing purpose actually it is exact copy of live paypal
but here you can use virtual money ]
=>Live server [it is live] =>Library
itself ,it works as server internally [not recommended for testing better use
sandbox] so Lets explore paypal library in sand box environment
(1)
create account in sandbox environment (2) download paypal library for
android and add it to project
(3) test code with some modification
done!!
Lest start....
(1) Create account :--

Search This Blog


Search

Follow by Email
Email address...

Submit

For create account in sanbox ,go to this link


1 of 10

Popular Posts
Create Your Own Custom
Keyboard for Android Devices
In this post i Created Simple
Keyboard which contains Some
special keys like ( France keys
) and it's supported Ca...
How to call Android contacts
list?
Hi this is very import concept to
Read Existing Contacts from
Your Emulator or Device There
are three steps to this process.
1) Permissions ...
PayPal intigration in Android
If our app has payment option then only one
thing can help us and that is paypal .Actually
working with payment system is li...
How Create Pie Chart In Android
In Genearl Graphs Play very
important role , but in android
we don't have any Graphs
related API . But with the help

of general andro...
OutOfMemory exception when decoding with
BitmapFactory
Google Android, Memory, and Bitmaps
Working on mobile devices forces one to make
conscious decisions regarding coding choices,
if for...
Solve the Debug certificate expired on error
message , Android Error: Error generating final
archive: Debug certificate expired on
long ago i tried to run my running suddenly it
showed error , but i didn't find any error in my
source code in java & XML also , T...
How to send Post data to PHP server in
android
public boolean PostData() { try { // creating
default Client HttpClient mClient = new
DefaultHttpClient(); // Connect URL ...
Android Interview Questions And Answers
What is android? Android is a stack of
software for mobile devices which has
Operating System, middleware and some key
appli...
How To Drag and Rotate Image
Using TouchEvent in Android
here i used two imageviews, one
is for Rotation another one is for
Drag classes : ===== main.xml
Tangram11.java main.xnml -------

and make acco unt .Fo r verificat io n ,paypal send yo u mail aft er verify it will be
act ivat ed in sanbo x enviro nment

no t e t hat t his sandbo x user name and pwd will

-------...

no t wo rk fo r live paypal and it is reco mmended t hat yo u sho uld no t use any real info
in sanbo x enviro nment .

in websit e go t o in t est acco unt t ab and creat e

yo ur desired acco unt


here t hree t ypes o f acco unt is available
(1)Perso nal
(2)Business
(3)Premier

[Fo r individuals who sho p o nline]

ImageView TextView Edittext in List View


using getview method And Calculating Grand
Total in android
In this programing i am explaing code For To
display Image and Text and EditText in Single
Colum in ListView files : ------- cart.xml carti...

[Fo r merchant s who use a co mpany o r gro up name]


[Fo r individuals who buy and sell o nline ]

Time

creat e o ne perso nal and o ne Business acco unt fo r t est ing t ransact io n
aft er creat ing t wo acco unt , it will sho w bo t h acco unt 's info rmat io n
fo r perso nal acco unt id is so met hing like t his
==>> hello xyz_1300948766_per@gmail.co m
fo r business acco unt id is so met hing like t his
==>> hello xyz22_1300937866_biz@gmail.co m
here '_per' means perso nal acco unt and '_biz' means business acco unt
no w i ho pe yo u have creat ed t wo acco unt ....let s mo ve t o seco nd t ask

(2) Download Library


yo u can do wnlo ad paypal library fro m here...
This zip fo lder co nt ains demo and jar file fo r develo per.
also yo u can do wnlo ad paypal t ut o rials fo r andro id here...
(3) No w impo rt pro ject 'sample demo '[which is already in zip fo lder :)] t o
yo ur wo rkspace...and run it ..

but here we will do some modification in code ...like we will add receipt
name .
so first understand how this library works ........

initWithAppID Method
The initWithAppID method creates and returns the PayPal object. You must pass in the
context and the unique application ID (appID) that PayPal has provided. You can choose
whether to use the live or sandbox server, or use non-networked (Demo) mode (see
below).

Total Pageviews

19 65 2 2
hungry Fishes

static public PayPal initWithAppID(Context context, String appID, int server)


An example of initializing the Library with this method is:

PayPal ppObj = PayPal.initWithAppID(this.getBaseContext(), "APP80W284485P519543T", PayPal.ENV_SANDBOX);


here appID is APP-80W284485P519543T which is fix for sandbox environment but
for live server it will be diffrent .here PayPal.ENV_SANDBOX ==> means we want to use
sandbox server[testing server]

PayPal.ENV_LIVE ==>> live server

PayPal.ENV_NONE ==> Do not use any PayPal servers.


Operate in demonstration mode, instead. Demonstration mode lets you view various

Followers
Join this site
w ith Google Friend Connect

Members (54) More

payment flows without requiring production or test accounts on PayPal servers. Network
calls within the library are simulated by using demonstration data held within the
library.

getCheckoutButton Method
You must get the Pay with
PayPal payment button from the Mobile Payments Library. Use this
method, which returns a CheckoutButton (a subclass of LinearLayout),
which you can place in your application.
public CheckoutButton getCheckoutButton(Context context, int style, int
textType);
Example code of getting the Payment button from the Library
is:CheckoutButton launchPayPalButton = ppObj.getCheckoutButton(this,

Already a member? Sign in

Blog Archive
11 (131)
12 (21)

PayPal.BUTTON_278x43, CheckoutButton.TEXT_PAY);

Jan (1)

//button size 278x43 and text on it is 'PAY'

Feb (1)

RelativeLayout.LayoutParams params = new

Mar (2)

RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,

Apr (4)

LayoutParams.WRAP_CONTENT);

May (4)

params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);

Dot Net Downloadable Links


IntentServise in android

launchPayPalButton.setLayoutParams(params);
launchPayPalButton.setOnClickListener(this);

PayPal intigration in Android


Top tips for converting iOS UI to Android

((RelativeLayout)findViewById(R.id.RelativeLayout01)).addView(launchPay
Jun (3)

PalButton);
we can customize button like

Aug (4)
Sep (1)

PayPal.BUTTON_152x33

Nov (1)

PayPal.BUTTON_194x37
13 (16)

PayPal.BUTTON_278x43
PayPal.BUTTON_294x45
and we can change text using
CheckoutButton.TEXT_PAYCheckoutButton.TEXT_DONATE

There are three types of payments in


Paypal..

Simple payments have a single

recipient. Parallel and Chained payments have multiple


recipients and differ in the how the payments are
split.Simple Payments
Simple payments use the PayPalPayment object which only supports a payment to a
single recipient.

Parallel Payments :Parallel Payments allow you to make payments for any amount
to any number of recipients. A parallel payment is created by making a payment
with multiple recipients with no primary recipient. From the end-user's
standpoint, a parallel payment will affect the UI by showing the details for each

recipient. Contrary to chained payments, the recipients of a parallel payment are


not linked together in terms of amount.

Chained PaymentsA chained payment is

a payment from a sender that is indirectly parallel among multiple receivers. It


is an extension of a typical payment from a sender to a receiver; however, a
receiver, known as the primary receiver, passes part of the payment to other
receivers, who are called secondary receivers.

Start the Library

ActivityThe Library uses the native Android Activity mechanism to start the
checkout flow, and to communicate completion back to you. In addition to the
onActivityResult callback, you can implement PayPalResultDelegate to be informed
immediately upon successful completion of a payment.

To start the PayPal payment, you must start the Library activity, using the
Android method startActivityForResult. Do this when buyers touch the Pay with
PayPal button (which you placed on your page with the getCheckoutButton method)

You must first create the PayPal intent and give it the Payment object. There are
two types of payment objects. PayPalPayment handles simple payments, which
support single receivers of payments with one transaction and a few details.
PayPalAdvancedPayment handles parallel and chained payments, which support
multiple receivers of payment with one transaction and with additional details,
such as invoice data.In the following example, the buyer checks out with a simple
payment for a single recipient:

below code is already given in sample demo provided by paypalhere you can modify
setRecipient() method and put mail id

of seller's account .also you can modify

whether you want shipping or not ,modify tax related calculation ,add invoice
data ,,it is pretty easy ...better refer Paypal reference guide for more detail

/**
* Create a PayPalPayment w hich is used for simple payments.
*
* @return Returns a PayPalPayment.
*/
private PayPalPayment exampleSimplePayment() {
// Create a basic PayPalPayment.
PayPalPayment payment = new PayPalPayment();
// Sets the currency type for this payment.
payment.setCurrencyType("USD");
// Sets the recipient for the payment. This can also be a phone number.
payment.setRecipient("helloxyz22_1300937866_biz@gmail.com");
// Sets the amount of the payment, not including tax and shipping amounts.
payment.setSubtotal(new BigDecimal("8.25"));
// Sets the payment type. This can be PAYMENT_TYPE_GOODS, PAYMENT_TYPE_SERVICE,
PAYMENT_TYPE_PERSONAL, or PAYMENT_TYPE_NONE.
payment.setPaymentType(PayPal.PAYMENT_TYPE_GOODS);

// PayPalInvoiceData can contain tax and shipping amounts. It also contains an ArrayList
of PayPalInvoiceItem w hich can
// be filled out. These are not required for any transaction.
PayPalInvoiceData invoice = new PayPalInvoiceData();
// Sets the tax amount.
invoice.setTax(new BigDecimal("10.25"));

// Sets the shipping amount.


invoice.setShipping(new BigDecimal("4.50"));

// PayPalInvoiceItem has several parameters available to it. None of these parameters is


required.
PayPalInvoiceItem item1 = new PayPalInvoiceItem();
// Sets the name of the item.
item1.setName("Pink Stuffed Bunny");
// Sets the ID. This is any ID that you w ould like to have associated w ith the item.
item1.setID("87239");
// Sets the total price w hich should be (quantity * unit price). The total prices of all
PayPalInvoiceItem should add up
// to less than or equal the subtotal of the payment.
item1.setTotalPrice(new BigDecimal("6.00"));
// Sets the unit price.
item1.setUnitPrice(new BigDecimal("2.00"));
// Sets the quantity.
item1.setQuantity(3);
// Add the PayPalInvoiceItem to the PayPalInvoiceData. Alternatively, you can create an
ArrayList<PayPalInvoiceItem>
// and pass it to the PayPalInvoiceData function setInvoiceItems().
invoice.getInvoiceItems().add(item1);

// Create and add another PayPalInvoiceItem to add to the PayPalInvoiceData.


PayPalInvoiceItem item2 = new PayPalInvoiceItem();
item2.setName("Well Wishes");
item2.setID("56691");
item2.setTotalPrice(new BigDecimal("2.25"));
item2.setUnitPrice(new BigDecimal("0.25"));
item2.setQuantity(9);
invoice.getInvoiceItems().add(item2);

// Sets the PayPalPayment invoice data.


payment.setInvoiceData(invoice);
// Sets the merchant name. This is the name of your Application or Company.
payment.setMerchantName("The Gift Store");
// Sets the description of the payment.
payment.setDescription("Quite a simple payment");
// Sets the Custom ID. This is any ID that you w ould like to have associated w ith the
payment.
payment.setCustomID("8873482296");
// Sets the Instant Payment Notification url. This url w ill be hit by the PayPal server upon
completion of the payment.
payment.setIpnUrl("http://w w w .exampleapp.com/ipn");
// Sets the memo. This memo w ill be part of the notification sent by PayPal to the
necessary parties.
payment.setMemo("Hi! I'm making a memo for a simple payment.");

return payment;
}

After Payment you w ill get Transcation Id in ResultDelegate class through PayPalResultDelegate
interface

PayPalResultDelegate interface having three methods:-

/**
* Notification that the payment has been completed successfully.
*
* @param payKey

the pay key for the payment

* @param paymentStatus

the status of the transaction

*/
public void onPaymentSucceeded(String payKey, String paymentStatus) {
//after successfull trancation it w ill give pay key through w hich w e can retrive transcation
detail in future using API call
}
/**
* Notification that the payment has failed.
*
* @param paymentStatus

the status of the transaction

* @param correlationID

the correlationID for the transaction failure

* @param payKey
* @param errorID

the pay key for the payment


the ID of the error that occurred

* @param errorMessage

the error message for the error that occurred

*/
public void onPaymentFailed(String paymentStatus, String correlationID,

}
/**
* Notification that the payment w as canceled.
*
* @param paymentStatus

the status of the transaction

*/
public void onPaymentCanceled(String paymentStatus) {

this is end of paypal integration in android , i hope you feel very easy to grasp all those
things but i recommend to go through reference given by paypal for android OS

######## How t o ret rieve Transact ion det ail by using Pay key ...######

Lets see....

For that w e use paypal api call and w e need below s details :-]

only business and premier account user can retrieve payment details ,bcoz for that you need
Api user name ,pw d and signature .those things w ill be provided to only

business and premier

account user .

Now put in headers below things in name

HttpClient httpclient = new DefaultHttpClient();


HttpPost httppost = null;
httppost = new
HttpPost("https://svcs.sandbox.paypal.com/AdaptivePayments/PaymentDetails");

httppost.setHeader("Content-Type", "application/x-w w w -form-urlencoded");

// Add your data


List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameV aluePair("X-PAYPAL-SECURITY-USERID", "id here"));
nameValuePairs.add(new BasicNameV aluePair("X-PAYPAL-SECURITY-PASSWORD", "pw d");
nameValuePairs.add(new BasicNameV aluePair("X-PAYPAL-SECURITY-SIGNATURE", "A.ir6ZUHAj9O5Wgkpf6YhhFFiUUKhjhK3lIEMcukxNT7zOO-fr1l"));
nameValuePairs.add(new BasicNameV aluePair("X-PAYPAL-APPLICATION-ID", "APP80W284485P519543T"));
nameValuePairs.add(new BasicNameV aluePair("X-PAYPAL-REQUEST-DATA-FORMAT", "nv"));
nameValuePairs.add(new BasicNameV aluePair("X-PAYPAL-RESPONSE-DATA-FORMAT",
"nv"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
and in body content w rite data :--

"payKey=AP-3TY0117788428730

{ This is test key for All sandbox applications )

&requestEnvelope.errorLanguage=en_US"

That is it ...yo u will get payment det ails in nv [name vale pair fo rmat ].....
I also have at t ached so me screen sho t s ..fo r reference ..

Some Useful Links :


------------------------ht t ps://www.x.com/developers/pay pal/document at ion-t ools/pay pal-sandboxget t ing-st art ed-guide

ht t ps://developer.pay pal.com/us/cgi-bin/devscr?cmd=_logout

ht t p://www.happy geek.in/pay pal-int egrat ion-in-android-app#!/

ht t ps://cms.pay pal.com/cms_cont ent /US/en_US/files/developer/PP_MPL_Develope


r_Guide_and_Reference_Android.pdf

ht t p://androidsnips.blogspot .in/2011/06/pay pal-int egrat ion-in-android.ht ml

ht t ps://www.x.com/developers/pay pal/sandbox

happy coding... :)
For Sample Source

Posted by sravan at 4:10 AM


Recommend this on Google

No comments:

Post a Comment
Enter your comment...

Comment as:

Publish

Google Accoun

Preview

Links to this post


Create a Link

Newer Post

Home

Older Post

Subscribe to: Post Comments (Atom)

Google+ Followers
2

Watermark template. Powered by Blogger.

Vous aimerez peut-être aussi