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.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/lib/data/ca-certificates.crt +199 -280
  3. data/lib/pingpp/api_operations/delete.rb +9 -4
  4. data/lib/pingpp/app_based_resource.rb +27 -0
  5. data/lib/pingpp/balance_bonus.rb +14 -0
  6. data/lib/pingpp/balance_transaction.rb +9 -0
  7. data/lib/pingpp/balance_transfer.rb +10 -0
  8. data/lib/pingpp/batch_withdrawal.rb +11 -0
  9. data/lib/pingpp/channel.rb +8 -0
  10. data/lib/pingpp/coupon.rb +9 -0
  11. data/lib/pingpp/coupon_template.rb +29 -0
  12. data/lib/pingpp/order.rb +69 -0
  13. data/lib/pingpp/recharge.rb +36 -0
  14. data/lib/pingpp/royalty.rb +14 -0
  15. data/lib/pingpp/royalty_settlement.rb +11 -0
  16. data/lib/pingpp/royalty_template.rb +12 -0
  17. data/lib/pingpp/royalty_transaction.rb +9 -0
  18. data/lib/pingpp/settle_account.rb +12 -0
  19. data/lib/pingpp/singleton_app_based_resource.rb +26 -0
  20. data/lib/pingpp/sub_app.rb +12 -0
  21. data/lib/pingpp/sub_app_based_resource.rb +35 -0
  22. data/lib/pingpp/user.rb +9 -0
  23. data/lib/pingpp/user_based_resource.rb +35 -0
  24. data/lib/pingpp/util.rb +19 -1
  25. data/lib/pingpp/version.rb +1 -1
  26. data/lib/pingpp/withdrawal.rb +15 -0
  27. data/lib/pingpp.rb +37 -4
  28. data/test/balance_bonus_test.rb +51 -0
  29. data/test/balance_transaction_test.rb +19 -0
  30. data/test/balance_transfer_test.rb +55 -0
  31. data/test/batch_refund_test.rb +41 -0
  32. data/test/batch_transfer_test.rb +61 -0
  33. data/test/batch_withdrawal_test.rb +76 -0
  34. data/test/charge_test.rb +51 -0
  35. data/test/coupon_template_test.rb +68 -0
  36. data/test/coupon_test.rb +81 -0
  37. data/test/customs_test_bak.rb +31 -0
  38. data/test/order_test.rb +181 -0
  39. data/test/recharge_test.rb +106 -0
  40. data/test/refund_test.rb +32 -0
  41. data/test/royalty_settlement_test.rb +68 -0
  42. data/test/royalty_template_test.rb +102 -0
  43. data/test/royalty_test.rb +43 -0
  44. data/test/royalty_transaction_test.rb +24 -0
  45. data/test/settle_account_test.rb +41 -0
  46. data/test/sub_app_channel_test.rb +70 -0
  47. data/test/sub_app_test.rb +60 -0
  48. data/test/test_assistant.rb +35 -0
  49. data/test/test_data.rb +191 -0
  50. data/test/user_test.rb +42 -0
  51. data/test/withdrawal_test.rb +121 -0
  52. metadata +72 -7
  53. data/test/charge_reverse_test.rb +0 -84
  54. data/test/settle_account_tes.rb +0 -53
@@ -0,0 +1,9 @@
1
+ module Pingpp
2
+ class BalanceTransaction < AppBasedResource
3
+ extend Pingpp::APIOperations::List
4
+
5
+ def self.object_name
6
+ 'balance_transaction'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ module Pingpp
2
+ class BalanceTransfer < AppBasedResource
3
+ extend Pingpp::APIOperations::List
4
+ extend Pingpp::APIOperations::Create
5
+
6
+ def self.object_name
7
+ 'balance_transfer'
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ module Pingpp
2
+ class BatchWithdrawal < AppBasedResource
3
+ extend Pingpp::APIOperations::Create
4
+ extend Pingpp::APIOperations::List
5
+ include Pingpp::APIOperations::Update
6
+
7
+ def self.object_name
8
+ 'batch_withdrawal'
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,8 @@
1
+ module Pingpp
2
+ class Channel < SubAppBasedResource
3
+ extend Pingpp::APIOperations::Create
4
+ include Pingpp::APIOperations::Delete
5
+ include Pingpp::APIOperations::Update
6
+
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ module Pingpp
2
+ class Coupon < UserBasedResource
3
+ extend Pingpp::APIOperations::Create
4
+ extend Pingpp::APIOperations::List
5
+ include Pingpp::APIOperations::Delete
6
+ include Pingpp::APIOperations::Update
7
+
8
+ end
9
+ end
@@ -0,0 +1,29 @@
1
+ module Pingpp
2
+ class CouponTemplate < AppBasedResource
3
+ extend Pingpp::APIOperations::Create
4
+ extend Pingpp::APIOperations::List
5
+ include Pingpp::APIOperations::Delete
6
+ include Pingpp::APIOperations::Update
7
+
8
+ def self.object_name
9
+ 'coupon_template'
10
+ end
11
+
12
+ def self.list_coupons(coupon_template, filters={}, opts={})
13
+ opts = Util.normalize_opts(opts)
14
+ response, opts = request(:get, coupon_url(coupon_template, opts), filters, opts)
15
+ ListObject.construct_from(response, opts)
16
+ end
17
+
18
+ def self.create_coupons(coupon_template, params={}, opts={})
19
+ response, opts = request(:post, coupon_url(coupon_template, opts), params, opts)
20
+ Util.convert_to_pingpp_object(response, opts)
21
+ end
22
+
23
+ private
24
+
25
+ def self.coupon_url(coupon_template, opts={})
26
+ resource_url(opts) + "/#{coupon_template}/coupons"
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,69 @@
1
+ module Pingpp
2
+ class Order < APIResource
3
+ extend Pingpp::APIOperations::Create
4
+ extend Pingpp::APIOperations::List
5
+ include Pingpp::APIOperations::Update
6
+
7
+ def pay(params, opts={})
8
+ response, opts = request(:post, pay_url, params, opts)
9
+ initialize_from(response, opts)
10
+ end
11
+
12
+ def self.pay(id, params, opts={})
13
+ response, opts = request(:post, pay_url(id), params, opts)
14
+ Util.convert_to_pingpp_object(response, opts)
15
+ end
16
+
17
+ def self.cancel(id, opts={})
18
+ update(id, {:status => 'canceled'}, opts)
19
+ end
20
+
21
+ def self.retrieve_charge(id, charge_id, opts={})
22
+ response, opts = request(:get, "#{resource_url}/#{id}/charges/#{charge_id}", {}, opts)
23
+ Util.convert_to_pingpp_object(response, opts)
24
+ end
25
+
26
+ def self.list_charges(id, params={}, opts={})
27
+ response, opts = request(:get, "#{resource_url}/#{id}/charges", params, opts)
28
+ Util.convert_to_pingpp_object(response, opts)
29
+ end
30
+
31
+ def self.refund(id, params, opts={})
32
+ response, opts = request(:post, refund_url(id), params, opts)
33
+ Util.convert_to_pingpp_object(response, opts)
34
+ end
35
+
36
+ def refund(params, opts={})
37
+ response, opts = request(:post, refund_url, params, opts)
38
+ initialize_from(response, opts)
39
+ end
40
+
41
+ def self.retrieve_refund(id, refund_id, opts={})
42
+ response, opts = request(:get, "#{refund_url(id)}/#{refund_id}", {}, opts)
43
+ Util.convert_to_pingpp_object(response, opts)
44
+ end
45
+
46
+ def self.list_refunds(id, params={}, opts={})
47
+ response, opts = request(:get, refund_url(id), params, opts)
48
+ Util.convert_to_pingpp_object(response, opts)
49
+ end
50
+
51
+ private
52
+
53
+ def pay_url
54
+ resource_url + '/pay'
55
+ end
56
+
57
+ def self.pay_url(order)
58
+ "#{resource_url}/#{order}/pay"
59
+ end
60
+
61
+ def refund_url
62
+ resource_url + '/order_refunds'
63
+ end
64
+
65
+ def self.refund_url(order)
66
+ "#{resource_url}/#{order}/order_refunds"
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,36 @@
1
+ module Pingpp
2
+ class Recharge < AppBasedResource
3
+ extend Pingpp::APIOperations::Create
4
+ extend Pingpp::APIOperations::List
5
+
6
+ def refund(params, opts={})
7
+ response, opts = request(:post, refund_url, params, opts)
8
+ initialize_from(response, opts)
9
+ end
10
+
11
+ def self.refund(id, params, opts={})
12
+ response, opts = request(:post, refund_url(id), params, opts)
13
+ Util.convert_to_pingpp_object(response, opts)
14
+ end
15
+
16
+ def self.retrieve_refund(id, refund_id, opts={})
17
+ response, opts = request(:get, "#{refund_url(id)}/#{refund_id}", {}, opts)
18
+ Util.convert_to_pingpp_object(response, opts)
19
+ end
20
+
21
+ def self.list_refunds(id, params={}, opts={})
22
+ response, opts = request(:get, refund_url(id), params, opts)
23
+ Util.convert_to_pingpp_object(response, opts)
24
+ end
25
+
26
+ private
27
+
28
+ def refund_url
29
+ resource_url + '/refunds'
30
+ end
31
+
32
+ def self.refund_url(id)
33
+ "#{resource_url}/#{id}/refunds"
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,14 @@
1
+ module Pingpp
2
+ class Royalty < APIResource
3
+ extend Pingpp::APIOperations::List
4
+
5
+ def self.batch_update(params, opts={})
6
+ response, opts = request(:put, resource_url(opts), params, opts)
7
+ Util.convert_to_pingpp_object(response, opts)
8
+ end
9
+
10
+ def self.resource_url(opt={})
11
+ '/v1/royalties'
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ module Pingpp
2
+ class RoyaltySettlement < APIResource
3
+ extend Pingpp::APIOperations::Create
4
+ extend Pingpp::APIOperations::List
5
+ include Pingpp::APIOperations::Update
6
+
7
+ def self.object_name
8
+ 'royalty_settlement'
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ module Pingpp
2
+ class RoyaltyTemplate < APIResource
3
+ extend Pingpp::APIOperations::Create
4
+ extend Pingpp::APIOperations::List
5
+ include Pingpp::APIOperations::Update
6
+ include Pingpp::APIOperations::Delete
7
+
8
+ def self.object_name
9
+ 'royalty_template'
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ module Pingpp
2
+ class RoyaltyTransaction < APIResource
3
+ extend Pingpp::APIOperations::List
4
+
5
+ def self.object_name
6
+ 'royalty_transaction'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ module Pingpp
2
+ class SettleAccount < UserBasedResource
3
+ extend Pingpp::APIOperations::Create
4
+ extend Pingpp::APIOperations::List
5
+ include Pingpp::APIOperations::Delete
6
+ include Pingpp::APIOperations::Update
7
+
8
+ def self.object_name
9
+ 'settle_account'
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,26 @@
1
+ module Pingpp
2
+ class SingletonAppBasedResource < APIResource
3
+ def self.resource_url(opts={})
4
+ if self == SingletonAPIResource
5
+ raise NotImplementedError.new('SingletonAPIResource is an abstract class.')
6
+ end
7
+
8
+ app_id = opts[:app]
9
+ unless app_id ||= Pingpp.app_id
10
+ raise InvalidRequestError.new("Please set app_id using Pingpp.app_id = <APP_ID>", 'app_id')
11
+ end
12
+
13
+ "/v1/apps/#{app_id}/#{CGI.escape(uri_object_name.downcase)}"
14
+ end
15
+
16
+ def resource_url(opts={})
17
+ self.class.resource_url(opts)
18
+ end
19
+
20
+ def self.retrieve(params={}, opts={})
21
+ instance = self.new(params, Util.normalize_opts(opts))
22
+ instance.refresh
23
+ instance
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,12 @@
1
+ module Pingpp
2
+ class SubApp < AppBasedResource
3
+ extend Pingpp::APIOperations::Create
4
+ extend Pingpp::APIOperations::List
5
+ include Pingpp::APIOperations::Delete
6
+ include Pingpp::APIOperations::Update
7
+
8
+ def self.object_name
9
+ 'sub_app'
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,35 @@
1
+ module Pingpp
2
+ class SubAppBasedResource < APIResource
3
+
4
+ def self.object_name
5
+ class_name.downcase
6
+ end
7
+
8
+ def self.resource_url(opts={})
9
+ if self == SubAppBasedResource
10
+ raise NotImplementedError.new('SubAppBasedResource is an abstract class. You should perform actions on its subclasses (Channel, etc.)')
11
+ end
12
+
13
+ app_id = opts[:app]
14
+ unless app_id ||= Pingpp.app_id
15
+ raise InvalidRequestError.new("Please set app_id using Pingpp.app_id = <APP_ID>", 'app_id')
16
+ end
17
+
18
+ unless sub_app_id = opts[:sub_app]
19
+ raise InvalidRequestError.new("Please pass sub_app_id in opts like {:sub_app => <SUB_APP_ID>}", 'sub_app')
20
+ end
21
+
22
+ url = "/v1/apps/#{app_id}/sub_apps/#{sub_app_id}"
23
+
24
+ if opts.has_key?(:parents)
25
+ if opts[:parents].is_a?(Array)
26
+ url + "/#{opts[:parents].join('/')}/#{CGI.escape(uri_object_name.downcase)}s"
27
+ else
28
+ raise ArgumentError.new("opts[:parents] should be an Array")
29
+ end
30
+ else
31
+ url + "/#{CGI.escape(uri_object_name.downcase)}s"
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,9 @@
1
+ module Pingpp
2
+ class User < AppBasedResource
3
+ extend Pingpp::APIOperations::Create
4
+ extend Pingpp::APIOperations::List
5
+ include Pingpp::APIOperations::Delete
6
+ include Pingpp::APIOperations::Update
7
+
8
+ end
9
+ end
@@ -0,0 +1,35 @@
1
+ module Pingpp
2
+ class UserBasedResource < APIResource
3
+
4
+ def self.object_name
5
+ class_name.downcase
6
+ end
7
+
8
+ def self.resource_url(opts={})
9
+ if self == UserBasedResource
10
+ raise NotImplementedError.new('UserBasedResource is an abstract class. You should perform actions on its subclasses (BalanceTransaction, etc.)')
11
+ end
12
+
13
+ app_id = opts[:app]
14
+ unless app_id ||= Pingpp.app_id
15
+ raise InvalidRequestError.new("Please set app_id using Pingpp.app_id = <APP_ID>", 'app_id')
16
+ end
17
+
18
+ unless user_id = opts[:user]
19
+ raise InvalidRequestError.new("Please pass user_id in opts like {:user => <USER_ID>}", 'user')
20
+ end
21
+
22
+ url = "/v1/apps/#{app_id}/users/#{user_id}"
23
+
24
+ if opts.has_key?(:parents)
25
+ if opts[:parents].is_a?(Array)
26
+ url + "/#{opts[:parents].join('/')}/#{CGI.escape(uri_object_name.downcase)}s"
27
+ else
28
+ raise ArgumentError.new("opts[:parents] should be an Array")
29
+ end
30
+ else
31
+ url + "/#{CGI.escape(uri_object_name.downcase)}s"
32
+ end
33
+ end
34
+ end
35
+ end
data/lib/pingpp/util.rb CHANGED
@@ -24,7 +24,25 @@ module Pingpp
24
24
  'transfer' => Transfer,
25
25
  'batch_refund' => BatchRefund,
26
26
  'batch_transfer' => BatchTransfer,
27
- 'customs' => Customs
27
+ 'event' => Event,
28
+ 'customs' => Customs,
29
+ 'sub_app' => SubApp,
30
+ 'channel' => Channel,
31
+ 'user' => User,
32
+ 'order' => Order,
33
+ 'recharge' => Recharge,
34
+ 'withdrawal' => Withdrawal,
35
+ 'batch_withdrawal' => BatchWithdrawal,
36
+ 'balance_transfer' => BalanceTransfer,
37
+ 'balance_bonus' => BalanceBonus,
38
+ 'balance_transaction' => BalanceTransaction,
39
+ 'coupon' => Coupon,
40
+ 'coupon_template' => CouponTemplate,
41
+ 'settle_account' => SettleAccount,
42
+ 'royalty' => Royalty,
43
+ 'royalty_settlement' => RoyaltySettlement,
44
+ 'royalty_transaction' => RoyaltyTransaction,
45
+ 'royalty_template' => RoyaltyTemplate,
28
46
  }
29
47
  end
30
48
 
@@ -1,3 +1,3 @@
1
1
  module Pingpp
2
- VERSION = '2.1.3'
2
+ VERSION = '2.2.0'
3
3
  end
@@ -0,0 +1,15 @@
1
+ module Pingpp
2
+ class Withdrawal < AppBasedResource
3
+ extend Pingpp::APIOperations::Create
4
+ extend Pingpp::APIOperations::List
5
+ include Pingpp::APIOperations::Update
6
+
7
+ def self.cancel(id, opts={})
8
+ update(id, {:status => 'canceled'}, opts)
9
+ end
10
+
11
+ def self.confirm(id, opts={})
12
+ update(id, {:status => 'pending'}, opts)
13
+ end
14
+ end
15
+ end
data/lib/pingpp.rb CHANGED
@@ -23,6 +23,8 @@ require 'pingpp/api_operations/request'
23
23
  require 'pingpp/util'
24
24
  require 'pingpp/pingpp_object'
25
25
  require 'pingpp/api_resource'
26
+ require 'pingpp/app_based_resource'
27
+ require 'pingpp/user_based_resource'
26
28
  require 'pingpp/singleton_api_resource'
27
29
  require 'pingpp/list_object'
28
30
  require 'pingpp/charge'
@@ -35,6 +37,25 @@ require 'pingpp/identification'
35
37
  require 'pingpp/customs'
36
38
  require 'pingpp/batch_refund'
37
39
  require 'pingpp/batch_transfer'
40
+ require 'pingpp/user'
41
+ require 'pingpp/balance_transaction'
42
+ require 'pingpp/coupon_template'
43
+ require 'pingpp/coupon'
44
+ require 'pingpp/order'
45
+ require 'pingpp/recharge'
46
+ require 'pingpp/withdrawal'
47
+ require 'pingpp/singleton_app_based_resource'
48
+ require 'pingpp/batch_withdrawal'
49
+ require 'pingpp/sub_app'
50
+ require 'pingpp/sub_app_based_resource'
51
+ require 'pingpp/channel'
52
+ require 'pingpp/settle_account'
53
+ require 'pingpp/royalty'
54
+ require 'pingpp/royalty_settlement'
55
+ require 'pingpp/royalty_transaction'
56
+ require 'pingpp/balance_transfer'
57
+ require 'pingpp/balance_bonus'
58
+ require 'pingpp/royalty_template'
38
59
 
39
60
  # Errors
40
61
  require 'pingpp/errors/pingpp_error'
@@ -57,6 +78,7 @@ module Pingpp
57
78
  Errno::ETIMEDOUT,
58
79
  RestClient::Conflict,
59
80
  RestClient::RequestTimeout,
81
+ RestClient::BadGateway,
60
82
  ].freeze
61
83
 
62
84
  @api_base = 'https://api.pingxx.com'
@@ -67,16 +89,18 @@ module Pingpp
67
89
  @open_timeout = 30
68
90
  @timeout = 80
69
91
 
70
- @max_network_retries = 0
92
+ @max_network_retries = 1
71
93
  @max_network_retry_delay = 2
72
94
  @initial_network_retry_delay = 0.5
73
95
 
96
+ @bad_gateway_match = true
97
+
74
98
  HEADERS_TO_PARSE = [:pingpp_one_version, :pingpp_sdk_version]
75
99
 
76
100
  class << self
77
101
  attr_accessor :api_key, :api_base, :verify_ssl_certs, :api_version,
78
102
  :parsed_headers, :private_key, :pub_key, :app_id, :timeout,
79
- :open_timeout
103
+ :open_timeout, :bad_gateway_match
80
104
  attr_reader :max_network_retry_delay, :initial_network_retry_delay
81
105
  end
82
106
 
@@ -405,8 +429,17 @@ module Pingpp
405
429
  end
406
430
 
407
431
  def self.should_retry?(e, retry_count)
408
- retry_count < self.max_network_retries &&
409
- RETRY_EXCEPTIONS.any? { |klass| e.is_a?(klass) }
432
+ if retry_count >= self.max_network_retries
433
+ return false
434
+ elsif !RETRY_EXCEPTIONS.any? { |klass| e.is_a?(klass) }
435
+ return false
436
+ elsif e.is_a?(RestClient::BadGateway)
437
+ if self.bad_gateway_match && !e.response.to_s.match(/.+DOCTYPE.+http\-equiv.+refresh.+content.+/m)
438
+ return false
439
+ end
440
+ end
441
+
442
+ return true
410
443
  end
411
444
 
412
445
  def self.sleep_time(retry_count)
@@ -0,0 +1,51 @@
1
+ require File.expand_path('../test_assistant', __FILE__)
2
+ require "digest/md5"
3
+
4
+ module Pingpp
5
+ class BalanceBonusTest < Test::Unit::TestCase
6
+ # 创建 balance_bonus 余额赠送
7
+ should "execute should return a new balance_bonus when passed correct parameters" do
8
+ order_no = Digest::MD5.hexdigest(Time.now.to_i.to_s)[0,12]
9
+
10
+ params = {
11
+ :order_no => order_no, # 余额赠送订单号
12
+ :amount => 100, # 金额, 人民币单位:分(如订单总金额为 1 元,此处请填 100)
13
+ :user => existed_user_id, # 收款用户
14
+ :description => "余额赠送"
15
+ }
16
+
17
+ o = Pingpp::BalanceBonus.create(
18
+ params,
19
+ { :app => get_app_id }
20
+ )
21
+
22
+ assert o.order_no == params[:order_no]
23
+ assert o.app == get_app_id
24
+ assert o.amount == 100
25
+ assert o.user == params[:user]
26
+ assert o.kind_of?(Pingpp::BalanceBonus)
27
+ end
28
+
29
+ should "execute should return an balance_bonus list when passed correct parameters" do
30
+ o = Pingpp::BalanceBonus.list(
31
+ { :per_page => 3 },
32
+ { :app => get_app_id }
33
+ )
34
+
35
+ assert o.object == 'list'
36
+ assert o.data.count <= 3
37
+ assert o.kind_of?(Pingpp::ListObject)
38
+ assert o.data[0].kind_of?(Pingpp::BalanceBonus)
39
+ end
40
+
41
+ should "execute should return an exist balance_bonus when passed correct id" do
42
+ o = Pingpp::BalanceBonus.retrieve(
43
+ existed_balance_bonus_id,
44
+ { :app => get_app_id }
45
+ )
46
+
47
+ assert o.object == 'balance_bonus'
48
+ assert o.kind_of?(Pingpp::BalanceBonus)
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,19 @@
1
+ require File.expand_path('../test_assistant', __FILE__)
2
+
3
+ module Pingpp
4
+ class BalanceTransactionTest < Test::Unit::TestCase
5
+ should "execute should return a balance_transaction list when passed correct parameters" do
6
+ txns = Pingpp::BalanceTransaction.list({:per_page => 3})
7
+
8
+ assert txns.object == 'list'
9
+ assert txns.data.count <= 3
10
+ end
11
+
12
+ should "execute should return an exist balance_transaction when passed correct id" do
13
+ txn = Pingpp::BalanceTransaction.retrieve(get_txn_id)
14
+
15
+ assert txn.object == 'balance_transaction'
16
+ assert txn.id == get_txn_id
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,55 @@
1
+ require File.expand_path('../test_assistant', __FILE__)
2
+ require "digest/md5"
3
+
4
+ module Pingpp
5
+ class BalanceTransferTest < Test::Unit::TestCase
6
+ # 创建 balance_transfer
7
+ should "execute should return a new balance_transfer when passed correct parameters" do
8
+ order_no = Digest::MD5.hexdigest(Time.now.to_i.to_s)[0,12]
9
+
10
+ params = {
11
+ :order_no => order_no, # 转账订单号
12
+ :amount => 1, # 转账总金额, 人民币单位:分(如订单总金额为 1 元,此处请填 100)
13
+ :user => existed_user_id_for_balance_transfer, # 转出用户
14
+ :recipient => existed_user_id, # 转入用户
15
+ :description => "用户间转账" # 描述
16
+ }
17
+
18
+ o = Pingpp::BalanceTransfer.create(
19
+ params,
20
+ { :app => get_app_id }
21
+ )
22
+
23
+ assert o.order_no == params[:order_no]
24
+ assert o.app == get_app_id
25
+ assert o.amount == params[:amount]
26
+ assert o.user == params[:user]
27
+ assert o.recipient == params[:recipient]
28
+ assert o.kind_of?(Pingpp::BalanceTransfer)
29
+ end
30
+
31
+ # 查询 balance_transfer 列表
32
+ should "execute should return an balance_transfer list when passed correct parameters" do
33
+ o = Pingpp::BalanceTransfer.list(
34
+ { :per_page => 3 },
35
+ { :app => get_app_id }
36
+ )
37
+
38
+ assert o.object == 'list'
39
+ assert o.data.count <= 3
40
+ assert o.kind_of?(Pingpp::ListObject)
41
+ assert o.data[0].kind_of?(Pingpp::BalanceTransfer)
42
+ end
43
+
44
+ # 查询单笔 balance_transfer
45
+ should "execute should return an exist balance_transfer when passed correct id" do
46
+ o = Pingpp::BalanceTransfer.retrieve(
47
+ existed_balance_transfer_id,
48
+ { :app => get_app_id }
49
+ )
50
+
51
+ assert o.object == 'balance_transfer'
52
+ assert o.kind_of?(Pingpp::BalanceTransfer)
53
+ end
54
+ end
55
+ end