PayPal account payment

Source: Internet
Author: User

This is a mobile payment, and the server provides support. It uses the mobile payment to transfer userid and price to a PayPal connection, (This connection includes a servlet that redirects to the server ). I am working on the server, so let's talk about the server processing.

I have learned some Paypal payment materials, so I know that PayPal will send a "memo" parameter when requesting this servlet. This parameter is set to "USERID/priceid/random", which is passed by the mobile phone end and placed in it. I only need to know the order of this parameter, then, extract and save it to the database. The Code is as follows. First, you can use the following code to test what the other party requested:

// Test PayPal feed URL log
Bufferedinputstream Bis = new bufferedinputstream (req. getinputstream ());
Datainputstream Dis = new datainputstream (bis );

Bytearrayoutputstream buffer = new bytearrayoutputstream ();
Byte [] packet = new byte [1, 1024];
Int numbytesread = 0;

While (numbytesread = dis. Read (packet ))! =-1)
Buffer. Write (packet, 0, numbytesread );

Byte [] arr = buffer. tobytearray ();

String text = NULL;
Try {
TEXT = new string (ARR, encode );
} Catch (unsupportedencodingexception e ){

TEXT = new string (ARR );
}
Log.info ("in paypalfeed ----" + text); // you can find out what PayPal delivers.

Bis. Close ();
Dis. Close ();
}
Catch (exception ex ){
Ex. printstacktrace ();
}

When you know What it passes, you can use the following code to process other logic:

String memo = Req. getparameter ("memo ");

System. Out. println ("Memo =>" + memo );
List <string> memoparam = mobileobjectconfigutil. getmemoparam (Memo );
If (memoparam! = NULL & memoparam. Size ()> 0 ){
Userid = memoparam. Get (0 );
If (memoparam. Get (1 )! = NULL ){
Priceid = memoparam. Get (1 );
}
If (memoparam. Get (2 )! = NULL ){
Randomid = memoparam. Get (2 );
}
}

Paymentinforservice = (paymentinforservice) application. lookupbean (paymentinforserviceimpl. bean_name );

If (stringutil. isnotblank (userid) & stringutil. isnotblank (priceid) & stringutil. isnotblank (randomid )){

Paymentinfor payinfor = paymentinforservice. getpaymentbymemo (userid, priceid, randomid );


If (payinfor = NULL ){
// Save the payment information
Paymentinfor = new paymentinfor ();
Paymentinfor. setuser (sapuser) paymentinforservice. Get (sapuser. Class, long. valueof (userid )));
Paymentinfor. setcreditprice (creditpackage) paymentinforservice. Get (creditpackage. Class, long. valueof (priceid )));
Paymentinfor. setrandomid (randomid );
Paymentinfor. setdatetimeadd (calendar. getinstance (). gettime ());

Paymentinforservice. Save (paymentinfor );

// Add credit (processing logic)
Creditpackage = paymentinfor. getcreditprice ();
Credit = paymentinforservice. findbyuserid (userid );
If (credit! = NULL ){
Credit. settotalcredit (double. valueof (credit. gettotalcredit () + creditpackage. getcredits ()));
Paymentinforservice. Update (credit );
}

}

}

Supplement the detailed code of the mobileobjectconfigutil. getmemoparam (Memo) method.

Public static list <string> getmemoparam (string memostr ){

List <string> resultlist = new arraylist <string> ();
If (memostr! = NULL &&! "". Inclusignorecase (memostr )){
If (memostr. Contains ("/")){
String [] STR = memostr. Split ("/");
For (INT I = 0; I <Str. length; I ++ ){
Resultlist. Add (STR [I]);
}
} Else {
Resultlist. Add (memostr );
}
}
Return resultlist;
}

The above is a PayPal request to our servlet, so how do you know whether the request is successful? You need an interface on the mobile phone end that continuously requests the server to query whether the data is in the database? Remember, the data stored above is transmitted from the mobile phone end, so he knows what data he transmits (userid, priceid, randomid ), according to these three parameters, the paymentinfor table is queried. If this record exists, the request is successful.

It may be relatively simple for everyone, but it is easy to understand. I didn't feel this simple before, so I wrote it down.

 

 

 

 

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.