Professional Documents
Culture Documents
Specification
Service Name
create_partner_trade_by_buyer
Version1.0
Alipay.com
Table of Content
1 Introduction ........................................................................................................ 4
1.1 Overview ............................................................................................................................... 4
1.2 Reader .................................................................................................................................. 4
1.3 Glossary ................................................................................................................................ 4
1.4 Technical Service.................................................................................................................. 5
8 Signature Algorithms....................................................................................... 31
8.1 Generate Pre-sign string ..................................................................................................... 31
8.1.1 Parameters to sign ................................................................................................... 31
8.1.2 Generate Pre-sign string .......................................................................................... 31
8.2 Signature Generation .......................................................................................................... 32
8.2.1 MD5 Signature ......................................................................................................... 32
Alipay.com Version1.0
Page 2
Alipay.com Version1.0
Page 3
1 Introduction
1.1 Overview
The function that Escrow Payment provides is, the third-party (Alipay)
guarantees the buyer can receive goods and seller can get the money. The
procedure is: Buyer Pay-> Seller Send Goods-> Buyer Confirm Goods->
Seller Confirm Money.
1.2 Reader
This document is meant for web developer, maintenance staff and manager with
substantial website development capability, who understands not only at least
one of following programming language, ASP, PHP, JAVA and ASP.net, but also
the SQL database language.
1.3 Glossary
Figure 1-1 Glossary of Terms
Term
Description
Escrow Payment
The third-party (Alipay) guarantees the buyer can receive goods and seller can get
the money. The procedure is: Buyer Pay-> Seller Send Goods-> Buyer Confirm
Goods-> Seller Confirm Money.
Return
The Website Synchronous Redirect Mode. Under this mode, after the buyer finish
the payment, the Alipay website redirects back to the partner website and returns
the result data to partner synchronously and automatically.
Notify
The Server Asynchronous Response Mode. Under this mode, after the trade status
changes, the Alipay server posts the notification to the partner server
asynchronously and initiatively.
Red Envelopes
Alipay Red Envelopes containing cash which can be used in some transaction.
Cartoon
Alipay cartoon connects user account with bank cards, transfer funds without
opening online banking, and enjoy Alipay Examine Before Payment grantee.
Request
Alipay.com Version1.0
page 4
Customer Hotline0571-88158090
2 Function Demo
2.1 With Alipay account
Step 1: Choose an item and make the payment in Alipay system.
(1)
Choose an item, and click the button Buy Now (<>) as Figure 2-1
shows.
(2)
Alipay.com Version1.0
page 5
(3)
Order confirmed, click the button Pay Now (<>) as Figure 2-3
shows.
Select a logistics method as Figure 2-4 shows. Fill the account () and
password () in the textboxes respectively, then click Go To Alipay button
(<>) to continue.
Alipay.com Version1.0
page 6
Step 3: Enter to the Alipay Cashier () and input payment password to pay.
With default delivery address, the cashier page is like what Figure 2-5.
Without default delivery address, access the Alipay Escrow Payment detail page
and click the Pay button (<>). (Check the Figure 2-6) Then access a new page
to add the delivery address as Figure 2-7 shows.
Alipay.com Version1.0
page 7
Alipay.com Version1.0
page 8
Choose an item, and click the button Buy Now (<>) as Figure 2-1
shows.
Alipay.com Version1.0
page 9
(6)
Order confirmed, click the button Pay Now (<>) as Figure 2-3
shows.
Select a logistics method as Figure 2-12 shows. Fill the email address or telephone
number (Email ) in the textbox of Pay Without Alipay Account (
), then click button Next (<>) directly to continue.
Alipay.com Version1.0
page 10
Step 3: Enter to the Alipay Cashier () and accomplish the payment through other
channels.
Alipay.com Version1.0
page 11
3 Interaction Mode
Alipay System
Partner System
Alipay.com Version1.0
page 12
(1)
Partner, based on Alipay API specification, generate a data set and the signature
through programming.
(2)
Send data set to Alipay system through the way of page re-direction or posting
form.
(3)
When receiving the data set, Alipay perform a set of security validation before
dealing with these data.
(4) Return response data
Alipay will response the processed data to partner in the following two manners:
(5)
The program reconstructs the URL link automatically, then the buyer
current page redirects automatically and synchronously to the partner
pre-set URL address with response data(Parameter name: return_url,
if partner does not set it, this operation will be ignored.).
Alipay server posts the notification to the partner server
asynchronously and initiatively (Parameter name: notify_url, if partner
does not set it, this operation will be ignored.)
After partner receive the response data from return page (the parameter
return_url identified) or notify page (the parameter notify_url identified), its own
business logic (i.e. acquire token, order update) can be continued.
Alipay.com Version1.0
page 13
Parameter
Parameter
Name
Type(l
ength)
Description
Optional
Example
Basic Parameters
service
create_direct
_pay_by_use
r
20881010119
13539
gbk
String
MD5
Sign
String
7d314d22efb
a4f336fb1876
97793b9d2
Notify URL
String(
190)
http://api.test.
alipay.net/atin
terface/receiv
e_return.htm
String
http://api.test.
alipay.net/atin
terface/receiv
e_return.htm
API Name
String
partner
Partner ID
String(
16)
_input_chars
et
Encode
Charset
String
sign_type
Sign Type
sign
notify_url
return_url
Return URL
API name
Business Parameters
out_trade_no
Out Trade
Number
String(
64)
68431922806
47118
subject
Subject
String(
256)
Apple
payment_typ
e
Payment
Type
String(
4)
logistics_typ
e
Logistics
Type
String
POST
Alipay.com Version1.0
page 14
Parameter
Name
Type(l
ength)
Description
Optional
Example
Logistics
Fee
String
10
BUYER_PAY
Default value is 0.
First logistics payment type
logistics_pa
yment
Logistics
Payment
Type
String
price
Price
Numb
er
10.00
quantity
Quantity
Numb
er
Goods quantity.
seller_email
Seller Email
String(
100)
alipay-test01
@alipay.com
buyer_email
Buyer Email
String(
100)
tstable01@ali
pay.com
Seller ID
String(
16)
20880020070
18966
20880020070
18955
tstable02@ali
pay.com
tstable03@ali
pay.com
seller_id
buyer_id
Buyer ID
String(
16)
seller_accou
nt_name
Seller
Account
Name
String(
100)
buyer_accou
nt_name
Buyer
Account
Name
String(
100)
Alipay.com Version1.0
page 15
total_fee
body
show_url
discount
Parameter
Name
Total Fee
Body
Show URL
Discount
Type(l
ength)
Description
Numb
er
String(
1000)
String(
400)
Numb
er
Optional
Example
100
Gundam
MKII,
Y
Miniature
Bracelet
http://www.36
0buy.com/pro
duct/113714.
html
0.00
receive_nam
e
Receivers
Name
String(
128)
Receiver Name.
Ricky
receive_addr
ess
Receivers
Address
String(
256)
Receivers Address.
5th Avenue,
New York
City
receive_zip
Receivers
Post Code
String(
20)
123456
receive_pho
ne
Receivers
Phone
Number
String(
30)
02161686888
Alipay.com Version1.0
page 16
Parameter
Name
Type(l
ength)
receive_mob
ile
Receivers
Mobile
Phone
Number
String
logistics_typ
e_1
Logistics
Type 1
Description
Optional
Example
13800000000
EMS
BUYER_PAY
POST
BUYER_PAY
7d
logistics_fee
_1
Logistics
Fee 1
String
logistics_pay
ment_1
Logistics
Payment
Type 1
String
logistics_typ
e_2
Logistics
Type 2
String
logistics_fee
_2
Logistics
Fee 2
String
logistics_pay
ment_2
t_s_send_1
Logistics
Payment
Type 2
(Seller) No
Sending
Goods In
Time, Allow
Refiund
String
Alipay.com Version1.0
Unit: d.
If partner set the parameter
it_b_pay, this parameter must
not be set.
page 17
t_s_send_2
t_b_rec_post
Parameter
Name
(Seller) No
Sending
Goods In
Time,
Suggest
Refiund
(Buyer) No
Confirming
Received
Goods In
Time,
Type(l
ength)
Description
Optional
Example
Unit: d.
7d
7d
1h
201103290c9
f9f2c03db426
7a4c8e1bfe3
adfd52
Finish
Trade
Automatical
ly (Post)
Unit: d.
If partner set the parameter
it_b_pay, this parameter must
not be set.
Set time limit for an unfinished
transaction, if expired, the
transaction will be closed
automatically.
Value Range: 1m~15d
it_b_pay
Expiration
Time
String(
3)
token
Token
String(
40)
Alipay.com Version1.0
page 18
4.3 Example
https://mapi.alipay.com/gateway.do?body=nokia+n8&logistics_type=EMS&logist
ics_fee=10&subject=nokia+n8&sign_type=MD5&receive_address=%C9%CF%B
A%A3%C6%D5%CD%D3%C7%F8&receive_name=%CB%D5%CB%CC&recei
ve_phone=02161686888&out_trade_no=3700918952085934&logistics_fee_1=1
&buyer_account_name=zhoubo_buyer%40alitest.com&logistics_fee_2=12&logi
stics_type_1=EMS&logistics_type_2=POST&buyer_email=zhoubo_buyer%40ali
test.com&t_b_rec_post=7d&total_fee=3000&quantity=1&partner=20880020070
18916¬ify_url=http%3A%2F%2F10.2.4.200%3A88%2F&t_s_send_1=7d&ag
ent=2088002007018916&t_b_pay=7d&t_s_send_2=7d&discount=-3&return_url
=http%3A%2F%2F10.2.4.200%3A88%2Fatinterface%2Freceive_Return.htm&si
gn=5bf3f7c3b5398b5e177a2537922b74c2&price=3003&seller_account_name=
zhoubo_seller%40alitest.com&service=create_partner_trade_by_buyer&receive
_mobile=13816843057&logistics_payment_1=BUYER_PAY&logistics_payment
_2=BUYER_PAY&seller_email=zhoubo_seller%40alitest.com&receive_zip=200
062&logistics_payment=BUYER_PAY&payment_type=1
Notice
This
Example
is
for
your
is https://mapi.alipay.com/gateway.do
Alipay.com Version1.0
referene
only,
Alipay
page 19
gateway
Paramet
er
Parameter
Name
Type(l
ength)
Description
Optional
Example
Basic Parameters
is_success
Success
mark
String(
1)
sign_type
Sign Type
String
MD5
sign
Sign
String
7d314d22efba4
f336fb1876977
93b9d2
partner
Partner ID
String(
16)
208810101191
3539
charset
Encode
Charset
String
gbk
RqPnCoPT3K9
%2Fvwbh3I%2
BODmZS9o4q
ChHwPWbaS7
UMBJpUnBJlzg
42y9A8gQlzU6
m3fOhG
Business Parameters
notify_id
Notify ID
String
Alipay.com Version1.0
page 20
Parameter
Name
Type(l
ength)
notify_type
Notify Type
String
Description
Optional
Notify Type
Indicates the trade status
changes.
Notify Time (Alipay showed
time)
Example
trade_status_s
ync
2008-10-23
13:17:39
notify_time
Notify Time
Date
subject
Subject
String
Glove
trade_no
Trade
Number
String(
16)
200810230321
0710
price
Price
Numb
er
10.00
quantity
Quantity
Numb
er
Goods quantity.
seller_emai
l
Seller Email
String(
100)
alipay-test01@
alipay.com
buyer_ema
il
Buyer Email
String(
100)
tstable01@alip
ay.com
Seller ID
String(
16)
208800200701
8966
Buyer ID
String(
16)
208800200701
8955
0.00
seller_id
buyer_id
discount
Discount
Numb
er
Format: yyyy-MM-dd
HH:mm:ss
Alipay.com Version1.0
page 21
Parameter
Name
Type(l
ength)
total_fee
Total Fee
Numb
er
trade_statu
s
Trade
Status
String
is_total_fe
e_adjust
Is Total Fee
Adjust
use_coup
on
Description
Total Amount of the
transactionUnitRMB Yuan
Value Range [0.01
100000000.00]accurate to two
decimal places.
Optional
Example
100
WAIT_SELLER
_SEND_GOOD
S
String
Use
Coupon
String
out_trade
_no
Out Trade
Number
String(
64)
684319228064
7118
body
Body
String(
1000)
payment_t
ype
Payment
Type
String(
4)
logistics_t
ype
Logistics
Type
String
logistics_f
ee
Logistics
Fee
String
logistics_p
ayment
Logistics
Payment
Type
String
gmt_logist
ics_modif
y
GMT
Logistics
Status is
Modified
Date
buyer_acti
ons
Buyer
Actions
String
Gundam MKII,
Miniature
Bracelet
POST
10
BUYER_PAY
2010-12-15
18:42:12
WAIT_SELLER
_SEND_GOOD
S
Alipay.com Version1.0
page 22
Parameter
Name
Type(l
ength)
seller_acti
ons
Seller
Actions
String
gmt_creat
e
GMT
Create
Date
gmt_paym
ent
GMT
Payment
Date
refund_st
atus
Refund
Status
String
gmt_refun
d
GMT
Refund
Date
receive_n
ame
Receivers
Name
String(
128)
receive_a
ddress
Receivers
Address
receive_zi
p
Description
Please refer to Chapter 11.6
Transaction Status
Optional
Example
SEND_GOOD
S
2008-10-22
20:49:31
2008-10-22
20:49:50
WAIT_SELLER
_AGREE
2008-10-29
19:38:25
Receiver Name.
Ricky
String(
256)
Receivers Address.
5th Avenue,
New York City
Receivers
Post Code
String(
20)
123456
receive_p
hone
Receivers
Phone
Number
String(
30)
02161686888
receive_m
obile
Receivers
Mobile
Phone
Number
String
13800000000
5.3 Example
http://www.xxx.com/alipay/return_url.php?body=2G%e5%bd%95%e9%9f%b3%
e7%ac%94&buyer_email=zhoubo_buyer%40alitest.com&buyer_id=2088102010
217422&discount=0.00&gmt_create=2011-01-05+16%3A04%3A22&gmt_logisti
cs_modify=2011-01-05+16%3A04%3A30&gmt_payment=2011-01-05+16%3A0
5%3A26&is_success=T&is_total_fee_adjust=Y&logistics_fee=10.00&logistics_p
ayment=BUYER_PAY&logistics_type=POST¬ify_id=RqPnCoPT3K9%252Fv
wbh3I%252BFiox8ptihzJoEoaWZbNBCD%252FU8bYsc57yqnRUNEpX00RjhlXr
Alipay.com Version1.0
page 23
Notice
This
Example
is
for
your
is https://mapi.alipay.com/gateway.do
referene
only,
Alipay
gateway
Parame Paramet
ter
er Name
Type(len
gth)
Description
Optiona
l
Example
Basic Parameters
notify_tim
e
Notify
Time
Date
notify_typ
e
Notify
Type
String
Notify Type
Alipay.com Version1.0
2008-10-23 13:17:39
trade_status_sync
page 24
Type(len
gth)
Description
Optiona
l
Example
RqPnCoPT3K9%2F
vwbh3I%2BODmZS
9o4qChHwPWbaS7
UMBJpUnBJlzg42y9
A8gQlzU6m3fOhG
notify_id
Notify ID
String
sign_type
Sign
Type
String
MD5
sign
Sign
String
Refer to Chapter 8
Signature Algorithm
7d314d22efba4f336f
b187697793b9d2
Business Parameters
trade_no
Trade
Number
String(16)
2008102303210710
subject
Subject
String(256
)
Glove
10.00
price
Price
Number
quantity
Quantity
Number
Goods quantity.
seller_em
ail
Seller
Email
String(100
)
alipay-test01@alipay
.com
buyer_e
mail
Buyer
Email
String(100
)
tstable01@alipay.co
m
A unique partner ID to
identify a contracted Alipay
Account.
2088002007018966
2088002007018955
seller_id
Seller ID
String(16)
buyer_id
Buyer
ID
String(16)
Alipay.com Version1.0
page 25
discount
Discoun
t
Type(len
gth)
Number
Description
Alipay system makes the
total fee plus discount, when
there is discount, the value
must be negative.
Optiona
l
Example
0.00
100
WAIT_SELLER_SE
ND_GOODS
total_fee
Total
Fee
trade_sta
tus
Trade
Status
String
is_total_f
ee_adjust
Is Total
Fee
Adjust
String
use_cou
pon
Use
Coupon
String
out_trad
e_no
Out
Trade
Number
String(64)
6843192280647118
Body
String(100
0)
body
Number
payment
_type
Paymen
t Type
String(4)
logistics
_type
Logistic
s Type
String
logistics
_fee
Logistic
s Fee
String
Gundam MKII,
Y
Miniature
Bracelet
POST
10
Alipay.com Version1.0
page 26
Type(len
gth)
logistics
_payme
nt
Logistic
s
Paymen
t Type
gmt_logi
stics_m
odify
GMT
Logistic
s Status
is
Modified
Date
buyer_a
ctions
Buyer
Actions
String
seller_a
ctions
Seller
Actions
String
gmt_cre
ate
GMT
Create
gmt_pay
ment
GMT
Paymen
t
Date
refund_
status
Refund
Status
String
gmt_ref
und
GMT
Refund
Date
receive_
name
Receive
rs
Name
String(128
)
receive_
address
Receive
rs
Address
receive_
zip
receive_
phone
Description
Optiona
l
Example
BUYER_PAY
2010-12-15 18:42:12
WAIT_SELLER_SE
ND_GOODS
SEND_GOODS
2008-10-22 20:49:31
2008-10-22 20:49:50
WAIT_SELLER_AG
REE
2008-10-29 19:38:25
Receiver Name.
Ricky
String(256
)
Receivers Address.
Receive
rs Post
Code
String(20)
123456
Receive
rs
Phone
Number
String(30)
02161686888
Date
Alipay.com Version1.0
page 27
receive_
mobile
Receive
rs
Mobile
Phone
Number
Type(len
gth)
String
Optiona
l
Description
Example
13800000000
6.3 Example
http://www.xxx.com/alipay/notify_url.php?discount=-3.00&logistics_type=EMS&r
eceive_zip=200062&payment_type=1&subject=nokia+n8&logistics_fee=10.00&t
rade_no=2010123002662342&buyer_email=zhoubo_buyer%40alitest.com¬if
y_type=trade_status_sync&gmt_create=2010-12-30+11%3A34%3A40&quantity
=1&logistics_payment=BUYER_PAY&out_trade_no=709651609727679¬ify_
time=2010-12-30+11%3A35%3A31&seller_id=2088102010217433&body=nokia
+n8&trade_status=WAIT_SELLER_SEND_GOODS&is_total_fee_adjust=N&gmt
_payment=2010-12-30+11%3A35%3A31&total_fee=3010.00&seller_email=zho
ubo_seller%40alitest.com&price=3003.00&buyer_id=2088102010217422&recei
ve_mobile=13816843057&gmt_logistics_modify=2010-12-30+11%3A34%3A40
&receive_phone=02161686888¬ify_id=8fd9bf041402c20669653e69b5cece3
404&receive_name=%CB%D5%CB%CC&use_coupon=N&sign_type=MD5&sig
n=b18c14fadbc76d2def8fa65c1ca82751&receive_address=%C9%CF%BA%A3
%C6%D5%CD%D3%C7%F8
Notice
This
Example
is
for
your
is https://mapi.alipay.com/gateway.do
referene
only,
Alipay
gateway
After successfully finish the payment, the buyer will see an Alipay
trade-sucess page, this page will stay for a few seconds and automatically
redirect to the page partner named. (return_url)
Alipay.com Version1.0
page 28
(5)
(6)
(7)
(8)
Due to Alipay will try to validate the return_url, so do not set it on local host.
For instance:
Wrong:
http://localhost/alipay/return_url.php
http://localhost:80/alipay/return_url.php
Right
http://www.xxx.comalipay/return_url.php
http://121.1.1.255alipay/return_url.php
(5)
(6)
(7)
Alipay.com Version1.0
page 29
Trigger Condition
Description
Default Value
TRADE_FINISHED
Transaction Finished
true
TRADE_SUCCESS
Payment Success
true
WAIT_BUYER_PAY
Transaction Created
false
TRADE_CLOSED
Transaction Closed
false
Note
Alipay.com Version1.0
page 30
(2)
After the completion of a transaction, partner may call batch refund API,
Alipay system will send a notification to partner, detail information please
refer to Batch Refund API Specifiaction
When a partner use refund service, system will sent a notification includes
parameter refund_status and gmt_refund to partner
8 Signature Algorithms
8.1 Generate Pre-sign string
8.1.1 Parameters to sign
In the list of request parameters, all of them need to be signed except sign
sign_type . (in some case even sign_type also need to be signed)
In the list of response parameters, all of them need to be signed except sign
sign_type.
Alipay.com Version1.0
page 31
page 32
Purpose
Validate a notification is from Alipay Server, ensure the authenticity of the
response data.
Mechanism
Acquire the parameter notify ID (notify_id), assemble it into a URL according to
Alipay requirement, e.g.:
https://www.alipay.com/cooperate/gateway.do?service=notify_verify&partner=20
88002396712354¬ify_id=RqPnCoPT3K9%252Fvwbh3I%252BFioE227%252
BPfNMl8jwyZqMIiXQWxhOCmQ5MQO%252FWd93rvCB%252BaiGg
or
http://notify.alipay.com/trade/notify_query.do?&partner=2088002396712354¬
ify_id=RqPnCoPT3K9%252Fvwbh3I%252BFioE227%252BPfNMl8jwyZqMIiXQ
WxhOCmQ5MQO%252FWd93rvCB%252BaiGg
Alipay.com Version1.0
page 33
11 Appendix
11.1 Escrow Payment Error Code
Figure 11-1 Escrow Payment Error Code
Error Code
ILLEGAL_PAYMENT_TYPE
ILLEGAL_FEE_PARAM
PRODUCT_NOT_EXIST
EXPARTNER_INFO_UNCORRECT
TRADE_DATA_MATCH_ERROR
LOGISTICS_CHOOSE_ERROR
ILLEGAL_REQUEST
SELLER_NOT_EXIST
SELLER_NOT_IN_SPECIFIED_SELLERS
SELF_TIMEOUT_NOT_SUPPORT
TRADE_BUYER_NOT_MATCH
TRADE_SELLER_NOT_MATCH
Alipay.com Version1.0
page 34
Alipay.com Version1.0
page 35
Error Code
ILLEGAL_SIGN
ILLEGAL_DYN_MD5_KEY
ILLEGAL_ENCRYPT
Type
Description
Goods Purchase
01
02
04
Type
Description
POST
Post
EXPRESS
EMS
EMS
Alipay.com Version1.0
page 36
Type
Description
BUYER_PAY
SELLER_PAY
BUYER_PAY_AFTER_RECEIVE
Status
Description
WAIT_BUYER_PAY
WAIT_SELLER_SEND_GOODS
WAIT_BUYER_CONFIRM_GOODS
TRADE_FINISHED
TRADE_CLOSED
Status
Description
WAIT_SELLER_AGREE
SELLER_REFUSE_BUYER
WAIT_BUYER_RETURN_GOODS
Alipay.com Version1.0
page 37
Description
WAIT_SELLER_CONFIRM_GOODS
REFUND_SUCCESS
Refund success
REFUND_CLOSED
Refund closed
Alipay.com Version1.0
page 38