paytrace 0.1.10 → 0.1.11

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: 591818333f44a0917834bd85c0b89ae2a577a423
4
- data.tar.gz: 5b77888fe9b318bb7c2680db0ef6c2da804c90b1
3
+ metadata.gz: 2441f7bcebff6b1c3a6fcca8143734334b17a6fd
4
+ data.tar.gz: 1d28434069fb9e1d22509a89767058ab8177b864
5
5
  SHA512:
6
- metadata.gz: 0161c3a2e1a3472bc7bfb8537e6155c87657155add10b3191d40e04953c720a4ba3d6a8731a966abbd8b0de390a4e955976a7c8fe13aaa482631b93a94387b34
7
- data.tar.gz: 622e8c92d8583c832ea8a7e2aed56e79ba2e7f4a95c942a9883b61b0beb22ad32bf6d7eaf3769ad4639da5eca038cb1e87890ae7718de3015c7f5a7d0568fcdb
6
+ metadata.gz: 810bc896355a1b2037c479cf105d0e5117400558cd7b5fa96fd2f1c5dab77c13059a60311929a32987f7ff43596d42ba322149b92b5a41748d27101fd6c5888b
7
+ data.tar.gz: dd72443f179654f8682d36dfb4ce8e4b44203c91f1deefba3a1e6d5e3ab2ce67744335f01f79d6e602062e2f882291267d5e3cd64cf39f79600d5deaf92b6de4
@@ -71,7 +71,11 @@ module PayTrace
71
71
  recur_type: "RECURTYPE",
72
72
  # attach signatures
73
73
  image_data: "IMAGEDATA",
74
- image_type: "IMAGETYPE"
74
+ image_type: "IMAGETYPE",
75
+ source_zip: "SOURCEZIP",
76
+ source_state: "SOURCESTATE",
77
+ shipping_weight: "WEIGHT",
78
+ shippers: "SHIPPERS"
75
79
  }
76
80
  end
77
81
  end
@@ -43,6 +43,12 @@ module PayTrace
43
43
 
44
44
  @params[k] = v unless v.nil?
45
45
  end
46
+
47
+ def set_params(keys, params)
48
+ keys.each do |key|
49
+ set_param(key, params[key])
50
+ end
51
+ end
46
52
  end
47
53
  end
48
54
  end
@@ -88,6 +88,8 @@ module PayTrace
88
88
  EXPORT_TRANSACTIONS_METHOD = "ExportTranx"
89
89
  EXPORT_TRANSACTIONS_RESPONSE = "TRANSACTIONRECORD"
90
90
  ATTACH_SIGNATURE_METHOD = "AttachSignature"
91
+ CALCULATE_SHIPPING_COST = "CalculateShipping"
92
+ CALCULATE_SHIPPING_COST_RESPONSE = "SHIPPINGRECORD"
91
93
 
92
94
  def set_shipping_same_as_billing()
93
95
  @shipping_address = @billing_address
@@ -152,6 +154,18 @@ module PayTrace
152
154
  gateway.send_request(request)
153
155
  end
154
156
 
157
+ def self.calculate_shipping(params = {})
158
+ request = PayTrace::API::Request.new
159
+ request.set_param(:method, CALCULATE_SHIPPING_COST)
160
+ request.set_params(params.keys, params)
161
+
162
+ gateway = PayTrace::API::Gateway.new
163
+ response = gateway.send_request(request, [CALCULATE_SHIPPING_COST_RESPONSE])
164
+ unless response.has_errors?
165
+ response.values[CALCULATE_SHIPPING_COST_RESPONSE]
166
+ end
167
+ end
168
+
155
169
  private
156
170
  def add_transaction_info(request)
157
171
  request.set_param(:transaction_type, type)
@@ -1,3 +1,3 @@
1
1
  module PayTrace
2
- VERSION = "0.1.10"
2
+ VERSION = "0.1.11"
3
3
  end
@@ -30,6 +30,14 @@ describe PayTrace::API::Request do
30
30
  r.params[:billing_name].must_equal "Fred Jones"
31
31
  end
32
32
 
33
+ it "can bulk set params" do
34
+ params = {billing_name: "Fred Jones", billing_postal_code: 98133}
35
+ r = PayTrace::API::Request.new
36
+ r.set_params([:billing_name, :billing_postal_code], params)
37
+ r.params[:billing_name].must_equal "Fred Jones"
38
+ r.params[:billing_postal_code].must_equal 98133
39
+ end
40
+
33
41
  it "raises a validation exception for unknown fields" do
34
42
  r = PayTrace::API::Request.new
35
43
 
@@ -25,6 +25,23 @@ describe PayTrace::Transaction do
25
25
  result.has_errors?.must_equal false
26
26
  end
27
27
 
28
+ it "calculates shipping costs" do
29
+ PayTrace::API::Gateway.debug = true
30
+ PayTrace::API::Gateway.next_response = "SHIPPINGRECORD~SHIPPINGCOMPANY=USPS+SHIPPINGMETHOD=STANDARD POST+SHIPPINGRATE=12.72|"
31
+ params = {
32
+ #UN, PSWD, TERMS, METHOD, SOURCEZIP, SOURCESTATE, SZIP, WEIGHT, SHIPPERS, SSTATE
33
+ source_zip: 98133,
34
+ source_state: "WA",
35
+ shipping_postal_code: 94947,
36
+ shipping_weight: 5.1,
37
+ shippers: "UPS,USPS,FEDEX",
38
+ shipping_state: "CA",
39
+ shipping_country: "US"
40
+ }
41
+ result = PayTrace::Transaction.calculate_shipping(params)
42
+ result[0]['SHIPPINGCOMPANY'].must_equal "USPS"
43
+ end
44
+
28
45
  describe "create sales transactions" do
29
46
  before do
30
47
  @response = mock()
@@ -0,0 +1,60 @@
1
+ $:<< "./lib" # uncomment this to run against a Git clone instead of an installed gem
2
+
3
+ require "paytrace"
4
+
5
+ # see: http://help.paytrace.com/api-email-receipt for details
6
+
7
+ #
8
+ # Helper that loops through the response values and dumps them out
9
+ #
10
+ def dump_transaction
11
+ puts "[REQUEST] #{PayTrace::API::Gateway.last_request}"
12
+ response = PayTrace::API::Gateway.last_response_object
13
+ if(response.has_errors?)
14
+ response.errors.each do |key, value|
15
+ puts "[RESPONSE] ERROR: #{key.ljust(20)}#{value}"
16
+ end
17
+ else
18
+ response.values.each do |key, value|
19
+ puts "[RESPONSE] #{key.ljust(20)}#{value}"
20
+ end
21
+ end
22
+ end
23
+
24
+ def log(msg)
25
+ puts ">>>>>> #{msg}"
26
+ end
27
+
28
+ def trace(&block)
29
+ PayTrace::API::Gateway.debug = true
30
+
31
+ begin
32
+ yield
33
+ rescue Exception => e
34
+ raise
35
+ else
36
+ dump_transaction
37
+ end
38
+ end
39
+
40
+ PayTrace.configure do |config|
41
+ config.user_name = "demo123"
42
+ config.password = "demo123"
43
+ config.domain = "stage.paytrace.com"
44
+ end
45
+
46
+ PayTrace::API::Gateway.debug = true
47
+
48
+ trace do
49
+ params = {
50
+ #UN, PSWD, TERMS, METHOD, SOURCEZIP, SOURCESTATE, SZIP, WEIGHT, SHIPPERS, SSTATE
51
+ source_zip: 98133,
52
+ source_state: "WA",
53
+ shipping_postal_code: 94947,
54
+ shipping_weight: 5.1,
55
+ shippers: "UPS,USPS,FEDEX",
56
+ shipping_state: "CA",
57
+ shipping_country: "US"
58
+ }
59
+ PayTrace::Transaction.calculate_shipping(params)
60
+ end
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.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Trevor Redfern
@@ -138,6 +138,7 @@ files:
138
138
  - test/paytrace/recurring_transaction_spec.rb
139
139
  - test/paytrace/transaction_spec.rb
140
140
  - test/scripts/run_attach_signature.rb
141
+ - test/scripts/run_calculate_shipping_costs.rb
141
142
  - test/scripts/run_create_customer.rb
142
143
  - test/scripts/run_email_request.rb
143
144
  - test/scripts/run_export_customers.rb
@@ -184,6 +185,7 @@ test_files:
184
185
  - test/paytrace/recurring_transaction_spec.rb
185
186
  - test/paytrace/transaction_spec.rb
186
187
  - test/scripts/run_attach_signature.rb
188
+ - test/scripts/run_calculate_shipping_costs.rb
187
189
  - test/scripts/run_create_customer.rb
188
190
  - test/scripts/run_email_request.rb
189
191
  - test/scripts/run_export_customers.rb