Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Receiving request strings on the server-side for Alipay mobile payment

Tags:

php

alipay

I'm not entirely sure how popular or whether this question will get any responses since this question is more related to Chinese developers than those developers outside of, however, I am currently working on integrating the server-side scripting for Alipay for receiving the mobile success request strings.

I have been successfully able to provide my mobile guys (through squinting my eyes in the horrid Alipay API) the strings necessary for them to make a payment to Alipay. It follows this format [identifiable information withheld]:

_input_charset=\"utf-8\"&body=\"Order Number: 20141121_80\"&it_b_pay=\"30m\"&notify_url=\"http://somePublicFacingIP:8080/index.php?route=payment/alipay/callback\"&out_trade_no=\"80\"&partner=\"2088611100000000\"&payment_type=\"1\"&seller_id=\"[email protected]\"&service=\"mobile.securitypay.pay\"&subject=\"Order Number: 20141121_80\"&total_fee=\"10.01\"

The above string gets consumed by the Android/iOS API in their Alipay payment classes, then signed by a private key, and then sent to Alipay. Upon Alipay receiving their request, they would verify our parameter string, and send back status codes ranging from 6000 - 9000.

We've so far received resultStatus=9000 in the string that gets returned to the mobile guys, which indicates a successful payment (and by checking Alipay's wallet history we do indeed see that we've made a payment)

result = {
    memo = "";
    result = "_input_charset=\"utf-8\"&body=\"\U4ea4\U6613\U53f7 20141124_80\"&it_b_pay=\"30m\"&notify_url=\"http://publicFacingIP:8080/index.php?route=payment/alipay/callback\"&out_trade_no=\"80\"&partner=\"208861100000000\"&payment_type=\"1\"&seller_id=\"[email protected]\"&service=\"mobile.securitypay.pay\"&subject=\"\U65b0\U5143\U7d20\U7f51\U4e0a\U70b9\U9910 - \U8ba2\U5355\U7f16\U53f7 20141124_87\"&total_fee=\"0.01\"&success=\"true\"&sign_type=\"RSA\"&sign=\"reallyLongSignedString\"";
    resultStatus = 9000;
}

Here's where everything stops working:

Alipay theoretically should be sending a result string (with more parameters than shown above) also to our notify_url which we specified in our input parameters which our server needs to verify is Alipay. This result string will also be used to update our back-end so that we know the order indeed has been successful.

For some reason, Alipay simply isn't sending the result string to our specified notify_url.

What I've tried:

  1. Put a var_dump() of the POST inputs to payment/alipay/callback. Didn't receive any requests.

  2. I've tried cURLing to my public facing IP URL's payment/alipay/callback and I know it's working because I am receiving requests, so that rules out whether or not my callback URL is functioning or not.

  3. Pulling my hair out. I tested making a payment again and I can confirm pulling my hair out did not solve the issue.

As the Chinese developers often say, are there any "大神" (or gurus) out there that could offer me some advice and/or a solution?

like image 761
theGreenCabbage Avatar asked Oct 31 '22 13:10

theGreenCabbage


1 Answers

Alright, so I just got off the support call with Alipay.

We verified that they did send the request to my notify_url, but my notify class had a PHP redirect code snippet in it so it was just being redirected to my landing page (the output of their result was my main page's HTML code).

So lesson learned:

  1. Do not put redirects in notify_url

  2. Contact Alipay support - they can help more than you think (ok. Less than I think, but they still helped).

I also implemented their nasty spaghetti code of their Notify class (which is in charge of processing the return params). The code isn't pretty, the indents are all incorrect, and the comments are all in Chinese.. But it seems like it will work. So we'll ship it first then refactor && translate later..

like image 193
theGreenCabbage Avatar answered Nov 15 '22 05:11

theGreenCabbage