paytrace 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7d9079bdedb95b47c01d862b45a91d51b7ae6929
4
- data.tar.gz: e39e2b5fc949cb4d127f065dcf8ff12f74589fce
3
+ metadata.gz: 54df13f77d55b0b19c7215434197ddd5c1fd9cf4
4
+ data.tar.gz: 7c877be2ac1d13c436b509d3d2b287a6ef5f43c3
5
5
  SHA512:
6
- metadata.gz: 52603839d6579d881a622e74f4fd54e3e0c1c4e984f375bb2ab88c394c843e9577be92c83a1db500b16f66b10597f115bea8a557d38c5ec2c25d322bccd86f2f
7
- data.tar.gz: 93656c1eb5cca7cb846a8542cada0605eac5270d4261b3d0b3735ab62f09c18ad6d5face2e984e9c966d809d1e02dc179f68e9923490667ac4d4053cb2054256
6
+ metadata.gz: d71d0cd704218be550c7cbd2c79b3470c2e4231d7c0ed6a2d60c2758db4f683d20b43d8a93a3507c7eee0663b1de07a38ce9d81e27f56da8d168ccdd7e5562dd
7
+ data.tar.gz: 5847017cf082d6e7f78379fbe6f9853a918ddcba76a5a31df9f180afd7797903473a186608c1857cff5b5e7d40b9282cc959e95aea5054e68c9e71b61f3a02af
@@ -6,10 +6,15 @@ module PayTrace
6
6
  CREATE_METHOD = "CreateRecur"
7
7
  DELETE_METHOD = "DeleteRecur"
8
8
  UPDATE_METHOD = "UpdateRecur"
9
- EXPORT_SINGLE_METHOD = "ExportCustomerRecur"
9
+ EXPORT_APPROVED_METHOD = "ExportCustomerRecur"
10
+ EXPORT_SCHEDULED_METHOD = "ExportRecur"
10
11
 
11
- def self.export_single(params = {})
12
- set_request_data(EXPORT_SINGLE_METHOD, params)
12
+ def self.export_scheduled(params = {})
13
+ set_request_data(EXPORT_SCHEDULED_METHOD, params)
14
+ end
15
+
16
+ def self.export_approved(params = {})
17
+ set_request_data(EXPORT_APPROVED_METHOD, params)
13
18
  end
14
19
 
15
20
  def self.create(params = {})
@@ -1,3 +1,3 @@
1
1
  module PayTrace
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -113,17 +113,29 @@ describe PayTrace::RecurringTransaction do
113
113
  end
114
114
  end
115
115
 
116
- describe "export single recurrence" do
116
+ describe "export single approved recurrence" do
117
117
  before do
118
118
  PayTrace::API::Gateway.debug = true
119
119
  PayTrace::API::Gateway.next_response = "RESPONSE~ok|RECURID~12345|"
120
120
  end
121
121
 
122
122
  it "works" do
123
- PayTrace::RecurringTransaction.export_single({customer_id: "john_doe"})
124
- PayTrace::API::Gateway.last_request.must_equal base_url(PayTrace::RecurringTransaction::EXPORT_SINGLE_METHOD) +
123
+ PayTrace::RecurringTransaction.export_approved({customer_id: "john_doe"})
124
+ PayTrace::API::Gateway.last_request.must_equal base_url(PayTrace::RecurringTransaction::EXPORT_APPROVED_METHOD) +
125
+ "CUSTID~john_doe|"
126
+ end
127
+ end
128
+
129
+ describe "export scheduled recurrences" do
130
+ before do
131
+ PayTrace::API::Gateway.debug = true
132
+ PayTrace::API::Gateway.next_response = "RESPONSE~ok|RECURID~12345|"
133
+ end
134
+
135
+ it "works" do
136
+ PayTrace::RecurringTransaction.export_scheduled({customer_id: "john_doe"})
137
+ PayTrace::API::Gateway.last_request.must_equal base_url(PayTrace::RecurringTransaction::EXPORT_SCHEDULED_METHOD) +
125
138
  "CUSTID~john_doe|"
126
139
  end
127
140
  end
128
- # describe "bulk update recurrences"
129
141
  end
@@ -5,14 +5,16 @@ require "paytrace"
5
5
  #
6
6
  # Helper that loops through the response values and dumps them out
7
7
  #
8
- def dump_response_values(response)
8
+ def dump_transaction
9
+ puts "[REQUEST] #{PayTrace::API::Gateway.last_request}"
10
+ response = PayTrace::API::Gateway.last_response_object
9
11
  if(response.has_errors?)
10
12
  response.errors.each do |key, value|
11
- puts "#{key.ljust(20)}#{value}"
13
+ puts "[RESPONSE] ERROR: #{key.ljust(20)}#{value}"
12
14
  end
13
15
  else
14
16
  response.values.each do |key, value|
15
- puts "#{key.ljust(20)}#{value}"
17
+ puts "[RESPONSE] #{key.ljust(20)}#{value}"
16
18
  end
17
19
  end
18
20
  end
@@ -21,6 +23,14 @@ def log(msg)
21
23
  puts ">>>>>> #{msg}"
22
24
  end
23
25
 
26
+ def trace(&block)
27
+ begin
28
+ yield
29
+ ensure
30
+ dump_transaction
31
+ end
32
+ end
33
+
24
34
  PayTrace.configure do |config|
25
35
  config.user_name = "demo123"
26
36
  config.password = "demo123"
@@ -58,21 +68,25 @@ PayTrace::API::Gateway.debug = true
58
68
  begin
59
69
  log "Attempting to remove existing customer 'john_doe'..."
60
70
  c = PayTrace::Customer.new("john_doe")
61
- c.delete()
71
+ trace { c.delete() }
62
72
  rescue PayTrace::Exceptions::ErrorResponse
63
73
  log "No such cusomter... continuing..."
64
74
  end
65
75
 
66
76
  log "Creating customer john_doe..."
67
77
  begin
68
- c = PayTrace::Customer.from_cc_info({customer_id: "john_doe", credit_card: cc, billing_address: ba}.merge(extra))
69
- dump_response_values(PayTrace::API::Gateway.last_response_object)
78
+ trace do
79
+ c = PayTrace::Customer.from_cc_info({customer_id: "john_doe", credit_card: cc, billing_address: ba}.merge(extra))
80
+ log "Customer ID: #{c.id}"
81
+ end
70
82
  rescue
71
- log "Failure; raw request: #{PayTrace::API::Gateway.last_request}"
72
- raise
83
+ if PayTrace::API::Gateway.last_response_object.errors.has_key?("ERROR-171")
84
+ log "Customer already exists..."
85
+ else
86
+ log "Failure; raw request: #{PayTrace::API::Gateway.last_request}"
87
+ raise
88
+ end
73
89
  end
74
- log "Customer ID: #{c.id}"
75
- dump_response_values(PayTrace::API::Gateway.last_response_object)
76
90
 
77
91
  log "Creating recurrence for john_doe..."
78
92
  params = {
@@ -86,18 +100,21 @@ params = {
86
100
  recur_receipt: "Y",
87
101
  recur_type: "A"
88
102
  }
89
- recur_id = PayTrace::RecurringTransaction.create(params)
90
- dump_response_values(PayTrace::API::Gateway.last_response_object)
91
- log "Recurrence ID: #{recur_id}"
92
103
 
93
- log "Exporting recurring transaction..."
94
- exported = PayTrace::RecurringTransaction.export_single({customer_id: "john_doe"})
95
- dump_response_values(PayTrace::API::Gateway.last_response_object)
104
+ trace do
105
+ recur_id = PayTrace::RecurringTransaction.create(params)
106
+ log "Recurrence ID: #{recur_id}"
107
+ end
108
+
109
+ begin
110
+ log "Exporting recurring transaction..."
111
+ trace { exported = PayTrace::RecurringTransaction.export_scheduled({customer_id: "john_doe"}) }
112
+ rescue
113
+ log "Export failed..."
114
+ end
96
115
 
97
- log "Deleting recurrence #{recur_id}..."
98
- PayTrace::RecurringTransaction.delete({recur_id: recur_id})
99
- dump_response_values(PayTrace::API::Gateway.last_response_object)
116
+ log "Deleting recurrences for 'john_doe'..."
117
+ trace { PayTrace::RecurringTransaction.delete({customer_id: "john_doe"}) }
100
118
 
101
119
  log "Deleting customer 'john_doe'..."
102
- c.delete()
103
- dump_response_values(PayTrace::API::Gateway.last_response_object)
120
+ trace { c.delete() }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paytrace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Trevor Redfern