paytrace 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80b786c68434d78a1faac3958f4d442c7892e71c
|
4
|
+
data.tar.gz: b2d58c4ee9923fd55f8baa0f9ca3168969674bb2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 676881032b054db073a42c478d570114dcd002cf7b71d2fb36b3285919f1ca2f6c89920e9d7c1ef4424b1189aad9658c6706c7545532ed5e296d832ac8ba0a4a
|
7
|
+
data.tar.gz: f3fc461d8a087c615fe21f952b66c4346614a7b1b6c09d4cf27df23bda8784648b0b86d45b2deaa0f41e1dc97fda4851e614da6b24b5ad8662cde2c9a3965432
|
@@ -2,15 +2,32 @@ require 'paytrace'
|
|
2
2
|
|
3
3
|
module PayTrace
|
4
4
|
class RecurringTransaction
|
5
|
-
attr :id
|
5
|
+
attr :id, :amount, :customer_id, :next, :total_count, :current_count, :repeat, :description
|
6
|
+
|
6
7
|
CREATE_METHOD = "CreateRecur"
|
7
8
|
DELETE_METHOD = "DeleteRecur"
|
8
9
|
UPDATE_METHOD = "UpdateRecur"
|
9
10
|
EXPORT_APPROVED_METHOD = "ExportCustomerRecur"
|
10
11
|
EXPORT_SCHEDULED_METHOD = "ExportRecur"
|
11
12
|
|
13
|
+
def initialize(raw_response)
|
14
|
+
response_map = raw_response.split('+').map {|pair| pair.split('=')}.to_h
|
15
|
+
@id = response_map["RECURID"].to_i
|
16
|
+
@amount = response_map["AMOUNT"].to_f
|
17
|
+
@customer_id = response_map["CUSTID"]
|
18
|
+
@next = response_map["NEXT"]
|
19
|
+
@total_count = response_map["TOTALCOUNT"].to_i
|
20
|
+
@current_count = response_map["CURRENTCOUNT"].to_i
|
21
|
+
@repeat = response_map["REPEAT"].to_i
|
22
|
+
@description = response_map["DESCRIPTION"]
|
23
|
+
end
|
24
|
+
|
25
|
+
def inspect
|
26
|
+
"<RecurringTransaction:#{@id},customer id:#{@customer_id},amount: #{@amount},next: #{@next}>"
|
27
|
+
end
|
28
|
+
|
12
29
|
def self.export_scheduled(params = {})
|
13
|
-
set_request_data(EXPORT_SCHEDULED_METHOD, params)
|
30
|
+
parse_response(set_request_data(EXPORT_SCHEDULED_METHOD, params))
|
14
31
|
end
|
15
32
|
|
16
33
|
def self.export_approved(params = {})
|
@@ -18,7 +35,7 @@ module PayTrace
|
|
18
35
|
end
|
19
36
|
|
20
37
|
def self.create(params = {})
|
21
|
-
set_request_data(CREATE_METHOD, params)
|
38
|
+
parse_response(set_request_data(CREATE_METHOD, params))
|
22
39
|
end
|
23
40
|
|
24
41
|
def self.delete(params = {})
|
@@ -35,13 +52,18 @@ module PayTrace
|
|
35
52
|
end
|
36
53
|
|
37
54
|
def self.update(params = {})
|
38
|
-
set_request_data(UPDATE_METHOD, params)
|
55
|
+
parse_response(set_request_data(UPDATE_METHOD, params))
|
39
56
|
end
|
40
57
|
|
41
58
|
def self.parse_response(response)
|
42
59
|
unless response.has_errors?
|
43
60
|
values = response.values
|
44
|
-
|
61
|
+
|
62
|
+
if values.has_key?("RECURRINGPAYMENT")
|
63
|
+
new(values["RECURRINGPAYMENT"])
|
64
|
+
else
|
65
|
+
values["RECURID"]
|
66
|
+
end
|
45
67
|
end
|
46
68
|
end
|
47
69
|
|
@@ -61,7 +83,7 @@ module PayTrace
|
|
61
83
|
request.set_param(:recur_type, params[:recur_type])
|
62
84
|
|
63
85
|
gateway = PayTrace::API::Gateway.new
|
64
|
-
|
86
|
+
gateway.send_request(request)
|
65
87
|
end
|
66
88
|
end
|
67
89
|
end
|
data/lib/paytrace/version.rb
CHANGED
@@ -129,13 +129,15 @@ describe PayTrace::RecurringTransaction do
|
|
129
129
|
describe "export scheduled recurrences" do
|
130
130
|
before do
|
131
131
|
PayTrace::API::Gateway.debug = true
|
132
|
-
PayTrace::API::Gateway.next_response = "
|
132
|
+
PayTrace::API::Gateway.next_response = "RECURRINGPAYMENT~RECURID=72553+AMOUNT=9.99+CUSTID=john_doe+NEXT=4/22/2016+TOTALCOUNT=999+CURRENTCOUNT=0+REPEAT=0+DESCRIPTION=Recurring transaction+"
|
133
133
|
end
|
134
134
|
|
135
135
|
it "works" do
|
136
|
-
PayTrace::RecurringTransaction.export_scheduled({customer_id: "john_doe"})
|
136
|
+
exported = PayTrace::RecurringTransaction.export_scheduled({customer_id: "john_doe"})
|
137
137
|
PayTrace::API::Gateway.last_request.must_equal base_url(PayTrace::RecurringTransaction::EXPORT_SCHEDULED_METHOD) +
|
138
138
|
"CUSTID~john_doe|"
|
139
|
+
|
140
|
+
exported.must_be_instance_of PayTrace::RecurringTransaction
|
139
141
|
end
|
140
142
|
end
|
141
143
|
end
|
@@ -108,7 +108,10 @@ end
|
|
108
108
|
|
109
109
|
begin
|
110
110
|
log "Exporting recurring transaction..."
|
111
|
-
trace
|
111
|
+
trace do
|
112
|
+
exported = PayTrace::RecurringTransaction.export_scheduled({customer_id: "john_doe"})
|
113
|
+
log "Exported transaction:\n#{exported.to_s}"
|
114
|
+
end
|
112
115
|
rescue
|
113
116
|
log "Export failed..."
|
114
117
|
end
|