Payment Treasure Interface Development Integrated Payment Environment Summary _php example

Source: Internet
Author: User

About Alipay's interface integration gas death is very simple, at present, there are about 3 types, instant to account, dual functions, secured transactions, only need to integrate a secured transaction, other such as instant to account integration is very easy, the status of the guarantee transactions are several, such as: whether to pay success, the seller is shipped, the buyer confirmed the harvest. and instant to the account only one kind, is whether has paid! There is a refund function at most. It's usually useless.

Through the project before: a funding platform, there is a prepaid function, the use of Alipay's dual-function collection, in fact, is to provide two kinds of payment methods, instant to the account and guarantee transactions. General buyers are cautious about choosing a guarantee.

The following specific integration process, first: Download the corresponding integrated interface package, such as instant to the account download immediately to the account, guarantee download guarantee, very do not recommend the immediate to the account modification into a guarantee or vice versa. In the case I downloaded the dual function interface file, utf8-php interface.

Download to the file are the same, instant to the account and guarantee the file is not quite the same, anyway, you can be sure that, as long as the configuration of a guaranteed Alipay interface, you can configure real-time to the account.

The files we need to modify are as follows: alipay.config.php[configuration file, just for modifying configuration Interface Developer ID and key]

alipayapi.php[keynote file, send the required post data to the file, and then responsible for jumping to the payment page]
Index.php[demo Demo page, you can not make changes, but the parameters passed in the name Chen need to read
notify_url.php returns a data page in which the status of the transaction is returned, more state we can change the database order information, which is accepted by post.
return_url.php returns a data page in which the status of the transaction is returned, more state we can change the database order information, the file is through get way.

Specific process:

The first step is to modify the configuration information:

Copy Code code as follows:

$alipay _config[' partner '] = ' xxx8511073xxxxxxxx ';
Security check codes, 32-bit characters with numbers and letters
$alipay _config[' key '] = ' xxxxxxxxnow07oajbflskxxxxxxxxxx ';


Second: Spell post data, generally only need to modify request parameters

Copy Code code as follows:

/************************** Request Parameters **************************/
Payment type
$payment _type = "1";
Must fill, cannot modify
Server Asynchronous Notification page path
$notify _url = "http://your domain/alipay/notify_url.php";
The full path to the http://format should not be added. id=123 Such custom parameters
Page Jump Sync notification page path
$return _url = "http://your domain/alipay/return_url.php";
Need to http://the full path of the format, can not add id=123 such custom parameters, can not be written as http://localhost/
Seller pays treasure Account
$seller _email = $_post[' Widseller_email '];//demo[index.php] sent over
Must fill
Merchant Order Number
$out _trade_no = $_post[' Widout_trade_no '];//.
The unique order number in the order system of the merchant website must be filled in
Order name
$subject = $_post[' Widsubject '];//ditto
Must fill
Payment Amount
$price = $_post[' Widprice '];//, is the value that you fill in the form
Must fill
Number of items
$quantity = "1";
Required, the recommended default is 1, do not change the value of a transaction as a single order rather than buy a product
Logistics cost
$logistics _fee = "0.00";
Required, i.e. freight
Logistics type
$logistics _type = "EXPRESS";
Required, three values Optional: Express (Express), POST (plain Mail), EMS (EMS)
Logistics Payment Method
$logistics _payment = "Seller_pay";
Required, two values optional: Seller_pay (seller Bear Freight), Buyer_pay (buyer bear Freight)
Order description
$body = $_post[' widbody '];
Product Display Address
$show _url = $_post[' Widshow_url '];
The full path to begin with http://, such as: http://www.ya-jing.cn
Consignee name
$receive _name = ' Firefly ';
such as: John
Consignee Address
$receive _address = $_post[' widreceive_address '];
such as: xx xxx city xxx area xxx district xxx block xxx xxx apartment xxx
Consignee postcode
$receive _zip = $_post[' Widreceive_zip '];
such as: 123456
Consignee Telephone number
$receive _phone = $_post[' Widreceive_phone '];
such as: 0571-88158090
Consignee mobile phone number
$receive _mobile = $_post[' Widreceive_mobile '];
such as: 13312341234


Third: After the completion of the data construction can be paid on the page, testing can correctly open the payment page. If it can be opened, this time can be paid, but the buyer's payment status we have not been informed, such as whether there is a successful payment, the seller has shipped. Then start the business logic processing of the return state.

Open the return_url.php file, modify according to the prompts, do the processing of the cause.

Copy Code code as follows:

--Write a program based on your business logic (the following code is for reference only)--
Get the notification return parameter of Alipay, refer to the page Jump synchronization notification parameter list in technical documentation
Merchant Order number $out _trade_no = $_get[' out_trade_no '];
Alipay transaction number $trade _no = $_get[' trade_no '];
Trading status
$trade _status = $_get[' trade_status '];
if ($_get[' trade_status '] = = ' Wait_seller_send_goods ') {//Status for success
Dealing with the business logic of your own site
if (! $order [' status ']) {//To determine if an order has been processed in the local database
Db_update ("Stx_recharge", Array ("status" =>1), Array ("OID" =>$_get
[' Out_trade_no ']); /If not processed, change the status to already processed.
The increase of money
$zd = Db_line ("stx_terminal", Array ("id" => $order [' Ztid ']);
Db_update ("Stx_terminal", Array ("Money" => $zd [' Money ']+ $order
[' money ']), array ("id" => $order [' Ztid ']);//Increase the balance to the user's account.
}
}
else if ($_get[' trade_status '] = = ' trade_finished ') {
Determine if the order has been processed on the merchant website
If no processing has been done, according to the order number (OUT_TRADE_NO) on the Merchant website Order system
Find out the details of the order and execute the merchant's business procedure.
If you have done so, do not execute business procedure of merchant
}
else {
echo "trade_status=". $_get[' Trade_status ';
}
echo "Verify successful <br/>";
echo "trade_no=". $trade _no;

Notify_url.php is the same, according to the state to write the corresponding code! There are more states in the notify_url.php file.

Copy Code code as follows:

--Write a program based on your business logic (the following code is for reference only)--
Get the notification return parameter for Alipay, refer to the list of server asynchronous notification parameters in technical documentation
Merchant Order Number
$out _trade_no = $_post[' out_trade_no '];
Alipay Trading Number
$trade _no = $_post[' trade_no '];
Trading status
$trade _status = $_post[' trade_status '];
if ($_post[' trade_status '] = = ' Wait_buyer_pay ') {
The judgment indicates that the buyer has generated a transaction in the Alipay transaction management, but has not paid
Determine if the order has been processed on the merchant website
If no processing, according to the order number (OUT_TRADE_NO) in the Merchant website Order system to find the details of the order, and the implementation of merchant business procedures
If you have done so, do not execute business procedure of merchant
echo "Success"; Please do not modify or delete
Debug, write text function to record the operation of the program is normal
Logresult ("Write the value of the code variable you want to debug, or other running result records");
}
else if ($_post[' trade_status '] = = ' Wait_seller_send_goods ') {
The judgment indicates that the buyer has generated a transaction in the Alipay transaction management and that the payment was successful, but the seller did not ship
if (! $order [' status ']) {
Db_update ("Stx_recharge", Array ("status" =>1), Array ("OID" =>$_post[' out_trade_no '));
The increase of money
$zd = Db_line ("stx_terminal", Array ("id" => $order [' Ztid ']);
Db_update ("Stx_terminal", Array ("Money" => $zd [' Money ']+ $order [' money ']), array ("id" => $order [' Ztid ']));
}
echo "Success"; Please do not modify or delete
Debug, write text function to record the operation of the program is normal
Logresult ("Write the value of the code variable you want to debug, or other running result records");
}
else if ($_post[' trade_status '] = = ' Wait_buyer_confirm_goods ') {
The judgment indicates that the seller has already sent the goods, but the buyer has not yet confirmed the operation of the receipt.
if (! $order [' status ']) {
Db_update ("Stx_recharge", Array ("status" =>1), Array ("OID" =>$_post[' out_trade_no '));
The increase of money
$zd = Db_line ("stx_terminal", Array ("id" => $order [' Ztid ']);
Db_update ("Stx_terminal", Array ("Money" => $zd [' Money ']+ $order [' money ']), array ("id" => $order [' Ztid ']));
}
echo "Success"; Please do not modify or delete
Debug, write text function to record the operation of the program is normal
Logresult ("Write the value of the code variable you want to debug, or other running result records");
}
else if ($_post[' trade_status '] = = ' trade_finished ') {
The judgment indicates that the buyer has confirmed the receipt and the transaction is completed
Determine if the order has been processed on the merchant website
If no processing, according to the order number (OUT_TRADE_NO) in the Merchant website Order system to find the details of the order, and the implementation of merchant business procedures
If you have done so, do not execute business procedure of merchant
echo "Success"; Please do not modify or delete
Debug, write text function to record the operation of the program is normal
Logresult ("Write the value of the code variable you want to debug, or other running result records");
}

Because I basically did not use the subsequent delivery processing, so in this state did not do processing, if your site is a shopping site seconds need to do the corresponding processing, such as Update status value is shipped, or unpaid, confirmed and so on. Easy to see the trading process. The order ID of Alipay will also be generated in the paid order and can be recorded in the order.

The above mentioned is this article about Alipay interface of the entire content, I hope to be proficient in the payment of Alipay interface payment Two development can be helpful.

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.