pingpp 2.1.3 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/data/ca-certificates.crt +199 -280
- data/lib/pingpp/api_operations/delete.rb +9 -4
- data/lib/pingpp/app_based_resource.rb +27 -0
- data/lib/pingpp/balance_bonus.rb +14 -0
- data/lib/pingpp/balance_transaction.rb +9 -0
- data/lib/pingpp/balance_transfer.rb +10 -0
- data/lib/pingpp/batch_withdrawal.rb +11 -0
- data/lib/pingpp/channel.rb +8 -0
- data/lib/pingpp/coupon.rb +9 -0
- data/lib/pingpp/coupon_template.rb +29 -0
- data/lib/pingpp/order.rb +69 -0
- data/lib/pingpp/recharge.rb +36 -0
- data/lib/pingpp/royalty.rb +14 -0
- data/lib/pingpp/royalty_settlement.rb +11 -0
- data/lib/pingpp/royalty_template.rb +12 -0
- data/lib/pingpp/royalty_transaction.rb +9 -0
- data/lib/pingpp/settle_account.rb +12 -0
- data/lib/pingpp/singleton_app_based_resource.rb +26 -0
- data/lib/pingpp/sub_app.rb +12 -0
- data/lib/pingpp/sub_app_based_resource.rb +35 -0
- data/lib/pingpp/user.rb +9 -0
- data/lib/pingpp/user_based_resource.rb +35 -0
- data/lib/pingpp/util.rb +19 -1
- data/lib/pingpp/version.rb +1 -1
- data/lib/pingpp/withdrawal.rb +15 -0
- data/lib/pingpp.rb +37 -4
- data/test/balance_bonus_test.rb +51 -0
- data/test/balance_transaction_test.rb +19 -0
- data/test/balance_transfer_test.rb +55 -0
- data/test/batch_refund_test.rb +41 -0
- data/test/batch_transfer_test.rb +61 -0
- data/test/batch_withdrawal_test.rb +76 -0
- data/test/charge_test.rb +51 -0
- data/test/coupon_template_test.rb +68 -0
- data/test/coupon_test.rb +81 -0
- data/test/customs_test_bak.rb +31 -0
- data/test/order_test.rb +181 -0
- data/test/recharge_test.rb +106 -0
- data/test/refund_test.rb +32 -0
- data/test/royalty_settlement_test.rb +68 -0
- data/test/royalty_template_test.rb +102 -0
- data/test/royalty_test.rb +43 -0
- data/test/royalty_transaction_test.rb +24 -0
- data/test/settle_account_test.rb +41 -0
- data/test/sub_app_channel_test.rb +70 -0
- data/test/sub_app_test.rb +60 -0
- data/test/test_assistant.rb +35 -0
- data/test/test_data.rb +191 -0
- data/test/user_test.rb +42 -0
- data/test/withdrawal_test.rb +121 -0
- metadata +72 -7
- data/test/charge_reverse_test.rb +0 -84
- data/test/settle_account_tes.rb +0 -53
@@ -0,0 +1,41 @@
|
|
1
|
+
require File.expand_path('../test_assistant', __FILE__)
|
2
|
+
require "digest/md5"
|
3
|
+
|
4
|
+
module Pingpp
|
5
|
+
class BatchRefundTest < Test::Unit::TestCase
|
6
|
+
should "execute should return a new batch_refund when passed correct parameters" do
|
7
|
+
batch_no = Digest::MD5.hexdigest(Time.now.to_i.to_s)[0,12]
|
8
|
+
|
9
|
+
params = {
|
10
|
+
:app => get_app_id,
|
11
|
+
:batch_no => batch_no,
|
12
|
+
:charges => make_charges_for_batch_refund,
|
13
|
+
:description => 'This is a batch_refund test.',
|
14
|
+
:metadata => {
|
15
|
+
:custom_key => 'custom_content'
|
16
|
+
}
|
17
|
+
}
|
18
|
+
|
19
|
+
batre = Pingpp::BatchRefund.create(params)
|
20
|
+
assert batre.object == 'batch_refund'
|
21
|
+
|
22
|
+
assert batre.charges == params[:charges]
|
23
|
+
assert batre.batch_no = params[:batch_no]
|
24
|
+
end
|
25
|
+
|
26
|
+
should "execute should return a batch_refund list" do
|
27
|
+
batres = Pingpp::BatchRefund.list(:per_page => 3)
|
28
|
+
|
29
|
+
assert batres.object == 'list'
|
30
|
+
assert batres.url.start_with?('/v1/batch_refunds')
|
31
|
+
assert batres.data.length <= 3
|
32
|
+
end
|
33
|
+
|
34
|
+
should "execute should return an exist batch_refund when passed correct id" do
|
35
|
+
batre = Pingpp::BatchRefund.retrieve(get_bat_re_id)
|
36
|
+
|
37
|
+
assert batre.id == get_bat_re_id
|
38
|
+
assert batre.object == 'batch_refund'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require File.expand_path('../test_assistant', __FILE__)
|
2
|
+
require "digest/md5"
|
3
|
+
|
4
|
+
module Pingpp
|
5
|
+
class BatchTransferTest < Test::Unit::TestCase
|
6
|
+
should "execute should return a new batch_transfer when passed correct parameters" do
|
7
|
+
batch_no = Digest::MD5.hexdigest(Time.now.to_i.to_s)[0,12]
|
8
|
+
|
9
|
+
params = {
|
10
|
+
:app => get_app_id,
|
11
|
+
:batch_no => batch_no,
|
12
|
+
:channel => 'alipay',
|
13
|
+
:amount => 1000,
|
14
|
+
:type => 'b2c',
|
15
|
+
:description => 'This is a batch_transfer test.',
|
16
|
+
:metadata => {
|
17
|
+
:custom_key => 'custom_content'
|
18
|
+
},
|
19
|
+
:currency => 'cny',
|
20
|
+
:recipients => [
|
21
|
+
{
|
22
|
+
:account => 'account01@gmail.com',
|
23
|
+
:amount => 300,
|
24
|
+
:name => 'name01'
|
25
|
+
}, {
|
26
|
+
:account => 'account02@gmail.com',
|
27
|
+
:amount => 300,
|
28
|
+
:name => 'name02'
|
29
|
+
}, {
|
30
|
+
:account => 'account03@gmail.com',
|
31
|
+
:amount => 400,
|
32
|
+
:name => 'name03'
|
33
|
+
}
|
34
|
+
]
|
35
|
+
}
|
36
|
+
|
37
|
+
battr = Pingpp::BatchTransfer.create(params)
|
38
|
+
|
39
|
+
assert battr.object == 'batch_transfer'
|
40
|
+
assert battr.amount == params[:amount]
|
41
|
+
assert battr.batch_no = params[:batch_no]
|
42
|
+
assert battr.app == params[:app]
|
43
|
+
assert battr.recipients.count == params[:recipients].count
|
44
|
+
end
|
45
|
+
|
46
|
+
should "execute should return a batch_transfer list" do
|
47
|
+
batres = Pingpp::BatchTransfer.list(:per_page => 3)
|
48
|
+
|
49
|
+
assert batres.object == 'list'
|
50
|
+
assert batres.url.start_with?('/v1/batch_transfers')
|
51
|
+
assert batres.data.count <= 3
|
52
|
+
end
|
53
|
+
|
54
|
+
should "execute should return an exist batch_transfer when passed correct id" do
|
55
|
+
batre = Pingpp::BatchTransfer.retrieve(get_bat_tr_id)
|
56
|
+
|
57
|
+
assert batre.id == get_bat_tr_id
|
58
|
+
assert batre.object == 'batch_transfer'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require File.expand_path('../test_assistant', __FILE__)
|
2
|
+
|
3
|
+
module Pingpp
|
4
|
+
class BatchWithdrawalTest < Test::Unit::TestCase
|
5
|
+
# 创建 batch_withdrawal (确认)
|
6
|
+
should "return a batch_withdrawal object when passed correct parameters" do
|
7
|
+
withdrawal_ids = get_created_withdrawals
|
8
|
+
if withdrawal_ids.count > 0
|
9
|
+
params = {
|
10
|
+
:withdrawals => withdrawal_ids,
|
11
|
+
|
12
|
+
# optional|string; 确认为 pending,取消为 canceled
|
13
|
+
:status => "pending",
|
14
|
+
}
|
15
|
+
o = Pingpp::BatchWithdrawal.create(params)
|
16
|
+
|
17
|
+
assert o.kind_of?(Pingpp::BatchWithdrawal)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# 创建 batch_withdrawal (取消)
|
22
|
+
should "return a batch_withdrawal(canceled) object when passed correct parameters" do
|
23
|
+
withdrawal_ids = get_created_withdrawals
|
24
|
+
if withdrawal_ids.count > 0
|
25
|
+
params = {
|
26
|
+
:withdrawals => withdrawal_ids,
|
27
|
+
|
28
|
+
# optional|string; 确认为 pending,取消为 canceled
|
29
|
+
:status => "canceled",
|
30
|
+
}
|
31
|
+
o = Pingpp::BatchWithdrawal.create(params)
|
32
|
+
|
33
|
+
assert o.kind_of?(Pingpp::BatchWithdrawal)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# 查询单笔 batch_withdrawal
|
38
|
+
should "return an existed batch_withdrawal object when passed correct id" do
|
39
|
+
o = Pingpp::BatchWithdrawal.retrieve(existed_batch_withdrawal_id)
|
40
|
+
|
41
|
+
assert o.kind_of?(Pingpp::BatchWithdrawal)
|
42
|
+
end
|
43
|
+
|
44
|
+
# 查询 batch_withdrawal 列表
|
45
|
+
should "return a batch_withdrawal list object" do
|
46
|
+
params = {
|
47
|
+
:page => 1,
|
48
|
+
:per_page => 3,
|
49
|
+
}
|
50
|
+
o = Pingpp::BatchWithdrawal.list(params)
|
51
|
+
|
52
|
+
assert o.kind_of?(Pingpp::ListObject)
|
53
|
+
assert o.data[0].kind_of?(Pingpp::BatchWithdrawal)
|
54
|
+
end
|
55
|
+
|
56
|
+
def get_created_withdrawals
|
57
|
+
o = Pingpp::Withdrawal.list(
|
58
|
+
{
|
59
|
+
:per_page => 1,
|
60
|
+
:page => 1,
|
61
|
+
:status => 'created',
|
62
|
+
:channel => 'alipay',
|
63
|
+
:created => { :gte => 1503158400 }
|
64
|
+
},
|
65
|
+
{ :app => get_app_id } # App 信息
|
66
|
+
)
|
67
|
+
|
68
|
+
withdrawals = []
|
69
|
+
o.data.each { |withdrawal|
|
70
|
+
withdrawals.push(withdrawal.id)
|
71
|
+
}
|
72
|
+
|
73
|
+
return withdrawals
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/test/charge_test.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require File.expand_path('../test_assistant', __FILE__)
|
2
|
+
require "digest/md5"
|
3
|
+
|
4
|
+
module Pingpp
|
5
|
+
class ChargeTest < Test::Unit::TestCase
|
6
|
+
should "execute should return a new, fully executed charge when passed correct parameters" do
|
7
|
+
order_no = Digest::MD5.hexdigest(Time.now.to_i.to_s)[0,12]
|
8
|
+
channel = 'wx'
|
9
|
+
|
10
|
+
params = {
|
11
|
+
:order_no => order_no,
|
12
|
+
:app => { :id => get_app_id },
|
13
|
+
:channel => channel, # 支付使用的第三方支付渠道取值,请参考:https://www.pingxx.com/api#api-c-new
|
14
|
+
:amount => 128000, # 订单总金额, 人民币单位:分(如订单总金额为 1 元,此处请填 100)
|
15
|
+
:client_ip => "127.0.0.1", # 发起支付请求客户端的 IP 地址,格式为 IPV4,如: 127.0.0.1
|
16
|
+
:currency => "cny",
|
17
|
+
:subject => "Your Subject",
|
18
|
+
:body => "Your Body",
|
19
|
+
:extra => {}
|
20
|
+
}
|
21
|
+
|
22
|
+
c = Pingpp::Charge.create(params)
|
23
|
+
|
24
|
+
assert c.order_no == params[:order_no]
|
25
|
+
assert c.app == get_app_id
|
26
|
+
assert c.channel == params[:channel]
|
27
|
+
assert c.amount == params[:amount]
|
28
|
+
assert c.paid == false
|
29
|
+
end
|
30
|
+
|
31
|
+
should "execute should return a charge list when passed correct parameters" do
|
32
|
+
l = Pingpp::Charge.list(
|
33
|
+
:app => { :id => get_app_id },
|
34
|
+
:limit => 3,
|
35
|
+
:paid => true,
|
36
|
+
:refunded => false
|
37
|
+
)
|
38
|
+
|
39
|
+
assert l.object == 'list'
|
40
|
+
assert l.data.count <= 3
|
41
|
+
end
|
42
|
+
|
43
|
+
should "execute should return an exist charge when passed correct charge id" do
|
44
|
+
ch_id = get_charge_id
|
45
|
+
c = Pingpp::Charge.retrieve(ch_id)
|
46
|
+
|
47
|
+
assert c.object == 'charge'
|
48
|
+
assert c.id == ch_id
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require File.expand_path('../test_assistant', __FILE__)
|
2
|
+
require "digest/md5"
|
3
|
+
|
4
|
+
module Pingpp
|
5
|
+
class CouponTemplateTest < Test::Unit::TestCase
|
6
|
+
# 创建优惠券模版
|
7
|
+
should "execute should return a new coupon_template when passed correct parameters" do
|
8
|
+
ctmpl = Pingpp::CouponTemplate.create({
|
9
|
+
# 类型 required|integer; 优惠券模板的类型 1:现金券;2:折扣券
|
10
|
+
:type => 1,
|
11
|
+
|
12
|
+
# 折扣金额 conditional|integer; 当 type 为 1 时,必传。
|
13
|
+
:amount_off => 30,
|
14
|
+
|
15
|
+
# 折扣百分比 conditional|integer; 例: 20 表示 8 折, 100 表示免费。当 type 为 2 时,必传。
|
16
|
+
# :percent_off => 15,
|
17
|
+
|
18
|
+
# optional|integer; 订单金额大于等于该值时,优惠券有效(适用于满减);0 表示无限制,默认 0。
|
19
|
+
:amount_available => 100,
|
20
|
+
})
|
21
|
+
|
22
|
+
assert ctmpl.kind_of?(Pingpp::CouponTemplate)
|
23
|
+
end
|
24
|
+
|
25
|
+
# 查询优惠券模板列表
|
26
|
+
should "execute should return a coupon_template list when passed correct parameters" do
|
27
|
+
ctmpl = Pingpp::CouponTemplate.list({:per_page => 3})
|
28
|
+
|
29
|
+
assert ctmpl.kind_of?(Pingpp::ListObject)
|
30
|
+
assert ctmpl.data.count <= 3
|
31
|
+
assert ctmpl.data[0].kind_of?(Pingpp::CouponTemplate)
|
32
|
+
end
|
33
|
+
|
34
|
+
# 查询优惠券模板
|
35
|
+
should "execute should return an exist coupon_template when passed correct id" do
|
36
|
+
ctmpl = Pingpp::CouponTemplate.retrieve(get_coupon_template_id)
|
37
|
+
|
38
|
+
assert ctmpl.kind_of?(Pingpp::CouponTemplate)
|
39
|
+
assert ctmpl.object == 'coupon_template'
|
40
|
+
assert ctmpl.id == get_coupon_template_id
|
41
|
+
end
|
42
|
+
|
43
|
+
# 更新优惠券模板
|
44
|
+
should "execute should return an updated coupon_template when passed correct id" do
|
45
|
+
new_params = { :metadata => { :custom_key => Digest::MD5.hexdigest(Time.now.to_i.to_s)[0,12] }}
|
46
|
+
ctmpl = Pingpp::CouponTemplate.update(
|
47
|
+
get_coupon_template_id,
|
48
|
+
new_params
|
49
|
+
)
|
50
|
+
|
51
|
+
assert ctmpl.kind_of?(Pingpp::CouponTemplate)
|
52
|
+
assert ctmpl.id == get_coupon_template_id
|
53
|
+
assert ctmpl.metadata.custom_key == new_params[:metadata][:custom_key]
|
54
|
+
end
|
55
|
+
|
56
|
+
# 删除优惠券模板
|
57
|
+
should "return a deleted object when passed existed coupon_template id" do
|
58
|
+
begin
|
59
|
+
o = Pingpp::CouponTemplate.delete(coupon_template_id_to_delete)
|
60
|
+
|
61
|
+
assert o.deleted
|
62
|
+
rescue => e
|
63
|
+
assert e.kind_of?(Pingpp::InvalidRequestError)
|
64
|
+
assert e.message.include?("未找到") || e.message.include?("No such coupon_template")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/test/coupon_test.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
require File.expand_path('../test_assistant', __FILE__)
|
2
|
+
|
3
|
+
module Pingpp
|
4
|
+
class CouponTest < Test::Unit::TestCase
|
5
|
+
# 为用户创建优惠券
|
6
|
+
should "return a new coupon for user when passed correct parameters" do
|
7
|
+
begin
|
8
|
+
o = Pingpp::Coupon.create(
|
9
|
+
{ :coupon_template => existed_coupon_template_id },
|
10
|
+
{ :user => get_user_id }
|
11
|
+
)
|
12
|
+
|
13
|
+
assert o.kind_of?(Pingpp::Coupon)
|
14
|
+
rescue => e
|
15
|
+
assert e.kind_of?(Pingpp::InvalidRequestError) || e.kind_of?(Pingpp::ChannelError)
|
16
|
+
assert e.message.include?("优惠券已到达当前用户最大生成数量") || e.message.include?("coupon exceed max user circulation")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# 查询用户的优惠券列表
|
21
|
+
should "execute should return a coupon when passed correct parameters" do
|
22
|
+
coupons = Pingpp::Coupon.list({:per_page => 3}, {:user => get_user_id})
|
23
|
+
|
24
|
+
assert coupons.kind_of?(Pingpp::ListObject)
|
25
|
+
assert coupons.data.count <= 3
|
26
|
+
assert coupons.data[0].kind_of?(Pingpp::Coupon)
|
27
|
+
end
|
28
|
+
|
29
|
+
# 查询用户的优惠券
|
30
|
+
should "execute should return a coupon object when passed correct parameters" do
|
31
|
+
coupon_id, user_id = coupon_id_and_user
|
32
|
+
coupon = Pingpp::Coupon.retrieve(coupon_id, {:user => user_id})
|
33
|
+
|
34
|
+
assert coupon.kind_of?(Pingpp::Coupon)
|
35
|
+
end
|
36
|
+
|
37
|
+
# 更新用户的优惠券
|
38
|
+
should "return a updated coupon object when passed correct id and parameters" do
|
39
|
+
coupon_id, user_id = coupon_id_and_user_to_update
|
40
|
+
o = Pingpp::Coupon.update(
|
41
|
+
coupon_id,
|
42
|
+
{ :metadata => { :new_key => 'new value' } },
|
43
|
+
{ :user => user_id }
|
44
|
+
)
|
45
|
+
|
46
|
+
assert o.kind_of?(Pingpp::Coupon)
|
47
|
+
end
|
48
|
+
|
49
|
+
# 删除用户的优惠券
|
50
|
+
should "execute should return a deleted object when passed correct parameters" do
|
51
|
+
coupon_id, user_id = coupon_id_and_user_to_delete
|
52
|
+
begin
|
53
|
+
deleted = Pingpp::Coupon.delete(coupon_id, {}, {:user => user_id})
|
54
|
+
|
55
|
+
assert deleted.deleted
|
56
|
+
rescue => e
|
57
|
+
assert e.kind_of?(Pingpp::InvalidRequestError)
|
58
|
+
assert e.message.include?("未找到") || e.message.include?("No such coupon")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# 使用优惠券模板批量创建优惠券
|
63
|
+
should "execute should return a coupon list made from coupon_template when passed correct coupon_template_id and parameters" do
|
64
|
+
user_id = Digest::MD5.hexdigest(Time.now.to_i.to_s)[0,12]
|
65
|
+
coupons = Pingpp::CouponTemplate.create_coupons(get_coupon_template_id, {:users => [user_id]})
|
66
|
+
|
67
|
+
assert coupons.kind_of?(Pingpp::ListObject)
|
68
|
+
assert coupons.data.count <= 3
|
69
|
+
assert coupons.data[0].kind_of?(Pingpp::Coupon)
|
70
|
+
end
|
71
|
+
|
72
|
+
# 查询优惠券模板创建的优惠券列表
|
73
|
+
should "execute should return a coupon list made from coupon_template when passed correct coupon_template_id" do
|
74
|
+
coupons = Pingpp::CouponTemplate.list_coupons(get_coupon_template_id, {:per_page => 3})
|
75
|
+
|
76
|
+
assert coupons.kind_of?(Pingpp::ListObject)
|
77
|
+
assert coupons.object == 'list'
|
78
|
+
assert coupons.data.count <= 3
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.expand_path('../test_assistant', __FILE__)
|
2
|
+
require "digest/md5"
|
3
|
+
|
4
|
+
module Pingpp
|
5
|
+
class CustomsTest < Test::Unit::TestCase
|
6
|
+
should "execute should return a new customs when passed correct parameters" do
|
7
|
+
order_no = Digest::MD5.hexdigest(Time.now.to_i.to_s)[0,12]
|
8
|
+
channel = 'upacp'
|
9
|
+
|
10
|
+
params = {
|
11
|
+
:app => get_app_id,
|
12
|
+
:charge => get_charge_id,
|
13
|
+
:channel => channel,
|
14
|
+
:trade_no => order_no,
|
15
|
+
:customs_code => 'GUANGZHOU',
|
16
|
+
:amount => 10,
|
17
|
+
:transport_amount => 1,
|
18
|
+
:is_split => true,
|
19
|
+
:sub_order_no => 'subord11010002',
|
20
|
+
:extra => {
|
21
|
+
:pay_account => '1234567890',
|
22
|
+
:certif_type => '02',
|
23
|
+
:customer_name => 'name',
|
24
|
+
:certif_id => '1234',
|
25
|
+
:tax_amount => 1
|
26
|
+
}
|
27
|
+
}
|
28
|
+
cu = Pingpp::Customs.create(params)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/test/order_test.rb
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
require File.expand_path('../test_assistant', __FILE__)
|
2
|
+
require "digest/md5"
|
3
|
+
|
4
|
+
module Pingpp
|
5
|
+
class OrderTest < Test::Unit::TestCase
|
6
|
+
# 创建订单 (order)
|
7
|
+
should "execute should return a new, fully executed order when passed correct parameters" do
|
8
|
+
order_no = Digest::MD5.hexdigest(Time.now.to_i.to_s)[0,12]
|
9
|
+
|
10
|
+
params = {
|
11
|
+
:merchant_order_no => order_no,
|
12
|
+
:app => get_app_id,
|
13
|
+
:amount => 100, # 订单总金额, 人民币单位:分(如订单总金额为 1 元,此处请填 100)
|
14
|
+
:client_ip => "127.0.0.1", # 发起支付请求客户端的 IP 地址,格式为 IPV4,如: 127.0.0.1
|
15
|
+
:currency => "cny",
|
16
|
+
:subject => "Your Subject",
|
17
|
+
:body => "Your Body",
|
18
|
+
:uid => get_user_id,
|
19
|
+
|
20
|
+
# 分润信息 optional|hash; 指定用户的形式
|
21
|
+
:royalty_users => [
|
22
|
+
{ :user => 'user_007', :amount => 30 },
|
23
|
+
{ :user => 'test_user_001', :amount => 20 },
|
24
|
+
],
|
25
|
+
|
26
|
+
# 分润模版 optional|string; 该参数与 royalty_users 同时传时,会忽略 royalty_template
|
27
|
+
# :royalty_template => existed_royalty_template_id,
|
28
|
+
}
|
29
|
+
|
30
|
+
o = Pingpp::Order.create(params)
|
31
|
+
|
32
|
+
assert o.merchant_order_no == params[:merchant_order_no]
|
33
|
+
assert o.app == get_app_id
|
34
|
+
assert o.amount == 100
|
35
|
+
assert o.paid == false
|
36
|
+
end
|
37
|
+
|
38
|
+
# 查询订单列表
|
39
|
+
should "execute should return an order list when passed correct parameters" do
|
40
|
+
o = Pingpp::Order.list(
|
41
|
+
{
|
42
|
+
:app => get_app_id,
|
43
|
+
:per_page => 3,
|
44
|
+
:paid => true,
|
45
|
+
:refunded => false,
|
46
|
+
}
|
47
|
+
)
|
48
|
+
|
49
|
+
assert o.object == 'list'
|
50
|
+
assert o.data.count <= 3
|
51
|
+
assert o.kind_of?(Pingpp::ListObject)
|
52
|
+
assert o.data[0].kind_of?(Pingpp::Order)
|
53
|
+
end
|
54
|
+
|
55
|
+
# 取消一笔订单
|
56
|
+
should "execute should return an canceled order when passed correct id" do
|
57
|
+
begin
|
58
|
+
o = Pingpp::Order.cancel(order_to_cancel)
|
59
|
+
|
60
|
+
assert o.object == 'order'
|
61
|
+
assert o.kind_of?(Pingpp::Order)
|
62
|
+
assert o.status == 'canceled'
|
63
|
+
rescue => e
|
64
|
+
assert e.kind_of?(Pingpp::InvalidRequestError)
|
65
|
+
assert e.message.include?("已取消") || e.message.include?("canceled") ||
|
66
|
+
e.message.include?("expired") || e.message.include?("已过期")
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
# 查询一笔存在的订单
|
72
|
+
should "execute should return an exist order when passed correct id" do
|
73
|
+
o = Pingpp::Order.retrieve(existed_order_id)
|
74
|
+
|
75
|
+
assert o.object == 'order'
|
76
|
+
assert o.kind_of?(Pingpp::Order)
|
77
|
+
assert o.id == existed_order_id
|
78
|
+
end
|
79
|
+
|
80
|
+
# 为一笔已创建的订单创建支付 (charge)
|
81
|
+
should "execute should return an order with credential when passed correct id and parameters" do
|
82
|
+
begin
|
83
|
+
o = Pingpp::Order.pay(
|
84
|
+
order_to_pay,
|
85
|
+
{
|
86
|
+
:charge_amount => 1000,
|
87
|
+
:channel => 'balance'
|
88
|
+
}
|
89
|
+
)
|
90
|
+
|
91
|
+
assert o.kind_of?(Pingpp::Order)
|
92
|
+
rescue => e
|
93
|
+
assert e.kind_of?(Pingpp::InvalidRequestError)
|
94
|
+
assert e.message.include?("已支付") || e.message.include?("paid")
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# 查询 order 的 charge 列表
|
99
|
+
should "return a charge list object" do
|
100
|
+
order_id, _ = existed_charge_id_of_order
|
101
|
+
o = Pingpp::Order.list_charges(
|
102
|
+
order_id,
|
103
|
+
{ :per_page => 3, :page => 1 }
|
104
|
+
)
|
105
|
+
|
106
|
+
assert o.object == 'list'
|
107
|
+
assert o.kind_of?(Pingpp::ListObject)
|
108
|
+
assert o.data[0].kind_of?(Pingpp::Charge)
|
109
|
+
end
|
110
|
+
|
111
|
+
# 查询 order 的 charge 对象
|
112
|
+
should "should return a charge object" do
|
113
|
+
order_id, charge_id = existed_charge_id_of_order
|
114
|
+
o = Pingpp::Order.retrieve_charge(
|
115
|
+
order_id,
|
116
|
+
charge_id
|
117
|
+
)
|
118
|
+
|
119
|
+
assert o.kind_of?(Pingpp::Charge)
|
120
|
+
end
|
121
|
+
|
122
|
+
# 查询 order 的退款列表
|
123
|
+
should "should return a list object of refunds already created" do
|
124
|
+
order_id, _ = existed_refund_id_of_order
|
125
|
+
o = Pingpp::Order.list_refunds(
|
126
|
+
order_id,
|
127
|
+
{ :per_page => 3, :page => 1 }
|
128
|
+
)
|
129
|
+
|
130
|
+
assert o.object == 'list'
|
131
|
+
assert o.kind_of?(Pingpp::ListObject)
|
132
|
+
assert o.data[0].kind_of?(Pingpp::Refund)
|
133
|
+
end
|
134
|
+
|
135
|
+
# 发起 order 的退款
|
136
|
+
should "should return a list object of new refunds" do
|
137
|
+
order_id, charge_id = order_and_charge_to_refund
|
138
|
+
o = Pingpp::Order.refund(
|
139
|
+
order_id,
|
140
|
+
{
|
141
|
+
# optional. 要退款的 Charge ID,不填则将 Order 包含的所有 Charge 都退款。
|
142
|
+
:charge => charge_id,
|
143
|
+
|
144
|
+
# optional. 退款金额,不填则退剩余可退金额。
|
145
|
+
:charge_amount => 1,
|
146
|
+
|
147
|
+
# required.
|
148
|
+
:description => '退款信息',
|
149
|
+
|
150
|
+
# optional. 退款模式。原路退回:to_source,退至余额:to_balance。默认为原路退回。
|
151
|
+
:refund_mode => 'to_source',
|
152
|
+
|
153
|
+
# optional. 退款资金来源。unsettled_funds:使用未结算资金退款;recharge_funds:使用可用余额退款。
|
154
|
+
# 该参数仅适用于所有微信渠道,包括 wx、wx_pub、wx_pub_qr、wx_lite、wx_wap 五个渠道。
|
155
|
+
# :funding_source => 'unsettled_funds',
|
156
|
+
|
157
|
+
# optional. 退分润的用户列表,默认分润全退,不是分润全退时,需要填写所有分润的用户。
|
158
|
+
# :royalty_users => [
|
159
|
+
# { :user => '', :amount_refunded => 10 }
|
160
|
+
# ],
|
161
|
+
}
|
162
|
+
)
|
163
|
+
|
164
|
+
assert o.object == 'list'
|
165
|
+
assert o.kind_of?(Pingpp::ListObject)
|
166
|
+
assert o.data[0].kind_of?(Pingpp::Refund)
|
167
|
+
end
|
168
|
+
|
169
|
+
# 查询 order 的退款
|
170
|
+
should "should return a refund object" do
|
171
|
+
order_id, refund_id = existed_refund_id_of_order
|
172
|
+
o = Pingpp::Order.retrieve_refund(
|
173
|
+
order_id,
|
174
|
+
refund_id
|
175
|
+
)
|
176
|
+
|
177
|
+
assert o.kind_of?(Pingpp::Refund)
|
178
|
+
assert o.id == refund_id
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|