paytrace 0.0.2 → 0.0.3

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: 33236dbde03fce5f6851d0e56b1aa746f1ee5400
4
- data.tar.gz: dee3b79ad21659a2fb3ea0f7bab826c78c7e51fb
3
+ metadata.gz: 5c945b008a295eb178fcdf4eb6238a1e19d0540e
4
+ data.tar.gz: 8283c88dd500af963b802e35cc124095afdca21f
5
5
  SHA512:
6
- metadata.gz: 3cb06a3040b0d967ad67f6ff9a1a6753896337fa020ca8d9b2e967a4d03c8f8091eff4e3b126a686874890828c45b39ad584ad6f762f76af576431caa8dd1476
7
- data.tar.gz: 59a277cf612ae4e2324612b8d89846795284cb5fed9bf93d0733587b5e47a6d3c61ff42df2f778d139b02329fe16894287737a0d87c5e512a6c38a525e7e4e4a
6
+ metadata.gz: 911f0086d4990b0948f0b062f75ed26e1722abae5f5fa71ee9a5bec55ca0103c870e6d162aa7162278d0adc3143f025d8e48f6a8dfa83f3ab128bc814035c365
7
+ data.tar.gz: f783078d6185ed345a6936a35c0469df3a7667af3b7c230184d0c0e80c7b8bf54af0cd82a60241761802f69a91b168b7872646ad86a506c9a2a942d63418de5e
data/.gitignore CHANGED
@@ -16,3 +16,6 @@ test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
18
  *.swp
19
+ .vagrant
20
+ .idea/
21
+
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 Trevor Redfern
1
+ Copyright (c) 2013 Trevor Redfern Tony Hatch
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,7 +1,12 @@
1
- # PaytraceRuby
1
+ # PayTrace Ruby SDK
2
2
 
3
3
  ![Build Status](https://www.codeship.io/projects/611ffe60-f3ee-0130-0299-1a84c3740ef1/status)
4
4
 
5
+ *This SDK is actively under development but should still be considered in an alpha
6
+ state. It does not provide all the access we are planning to our API at this time.
7
+ Please feel free to experiment with it and we will be regularly pushing out new
8
+ updates with increased functionality over the coming weeks*
9
+
5
10
  This gem integrates with the PayTrace API. It provides functionality to the
6
11
  publicly available functionality including:
7
12
 
@@ -14,7 +19,7 @@ publicly available functionality including:
14
19
 
15
20
  Add this line to your application's Gemfile:
16
21
 
17
- gem 'paytrace_ruby'
22
+ gem 'paytrace'
18
23
 
19
24
  And then execute:
20
25
 
@@ -22,11 +27,107 @@ And then execute:
22
27
 
23
28
  Or install it yourself as:
24
29
 
25
- $ gem install paytrace_ruby
30
+ $ gem install paytrace
26
31
 
27
32
  ## Usage
28
33
 
29
- TODO: Write usage instructions here
34
+ ### Configuring your account
35
+
36
+ You can set this up as a Rails initializer or during any other common configuration
37
+ of your application.
38
+
39
+ ```ruby
40
+ PayTrace.configure do |config|
41
+ config.user_name = "my_user_name"
42
+ config.password = "password"
43
+ end
44
+ ```
45
+
46
+ ### Transactions
47
+
48
+ Transactions can be processed utilizing class methods on the PayTrace::Transaction
49
+ class.
50
+
51
+ ```ruby
52
+ transaction = Transaction.sale(
53
+ {amount: "1.00",
54
+ credit_card: {
55
+ card_number: "1111222233334444",
56
+ expiration_year: 14,
57
+ expiration_month: 3
58
+ }
59
+ }
60
+ )
61
+
62
+ #
63
+ ## Response information is available on the transaction
64
+ #
65
+ puts transaction.response_code # 101. Your transaction was successfully approved.
66
+
67
+ #
68
+ ## All values returned are accessible through the attached response property
69
+ #
70
+ transaction.response.each do |key, value|
71
+ puts key # e.g. APPCODE
72
+ puts value # TAS671
73
+ end
74
+ ```
75
+
76
+ ### Customers
77
+
78
+ ```ruby
79
+ # running a transaction for a customer
80
+ transaction = Transaction.sale({amount: "1.00",customer_id: "my_customer_id"})
81
+
82
+ ```
83
+ ### Some Optional Fields
84
+ ```ruby
85
+ #Adding Optional Fields
86
+
87
+ transaction = Transaction.Sale(
88
+ {
89
+ amount: "1.00",
90
+ credit_card: {
91
+ card_number: "1111222233334444",
92
+ expiration_year: 14,
93
+ expiration_month: 3
94
+ },
95
+ email:"me@example.com",
96
+ description:"This is a test",
97
+ tax_amount:".50",
98
+ discretionary_data:"This is some data that is discretionary"
99
+ }
100
+ )
101
+
102
+ ```
103
+
104
+ ### Billing and Shipping Address
105
+ ```ruby
106
+ transaction = Transaction.Sale(
107
+ {amount: "1.00",
108
+ credit_card: {
109
+ card_number: "1111222233334444",
110
+ expiration_year: 14,
111
+ expiration_month: 3
112
+ },
113
+ billing_address:{
114
+ name:"Jane Doe",
115
+ street:"1234 happy st.",
116
+ street2:"apt#2",
117
+ city:"Seattle",
118
+ state:"WA",
119
+ country: "US",
120
+ postal_code:"98107"
121
+ },
122
+ shipping_address: {
123
+ #Same as billing above.
124
+ }
125
+ }
126
+ )
127
+
128
+ ```
129
+
130
+
30
131
 
31
132
  ## Contributing
32
133
 
data/lib/paytrace.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "paytrace/version"
2
2
  require "paytrace/configuration"
3
3
  require "paytrace/credit_card"
4
+ require "paytrace/customer"
4
5
  require "paytrace/transaction"
5
6
  require 'paytrace/api/fields'
6
7
  require 'paytrace/api/gateway'
@@ -0,0 +1,16 @@
1
+ module PayTrace
2
+ class Address
3
+ attr :name, :street,:street2,:city,:state, :country,:region,:postal_code
4
+
5
+ def initialize(options={})
6
+ @name = options[:name]
7
+ @street = options[:street]
8
+ @street2 = options[:street2]
9
+ @city = options[:city]
10
+ @state = options[:state]
11
+ @region = options[:region]
12
+ @country = options[:country]
13
+ @postal_code = options[:postal_code ]
14
+ end
15
+ end
16
+ end
@@ -3,14 +3,46 @@ module PayTrace
3
3
  def self.fields
4
4
  {
5
5
  amount: "AMOUNT",
6
- card_number: "CC",
7
- expiration_year: "EXPYR",
8
- expiration_month: "EXPMNTH",
9
6
  method: "METHOD",
10
7
  password: "PSWD",
11
8
  terms: "TERMS",
12
9
  transaction_type: "TRANXTYPE",
13
10
  user_name: "UN",
11
+ email: "EMAIL",
12
+ description: "DESCRIPTION",
13
+ tax_amount: "TAX",
14
+ return_clr: "RETURNCLR",
15
+ enable_partial_authentication: "ENABLEPARTIALAUTH",
16
+ discretionary_data: "DISCRETIONARY DATA",
17
+ custom_dba: "CUSTOMDBA",
18
+ invoice:"INVOICE",
19
+ transaction_id:"TRANXID",
20
+ #credit card
21
+ card_number: "CC",
22
+ expiration_year: "EXPYR",
23
+ expiration_month: "EXPMNTH",
24
+ csc: "CSC",
25
+ swipe:"SWIPE",
26
+ #billing address
27
+ billing_name: "BNAME",
28
+ billing_address: "BADDRESS",
29
+ billing_address2:"BADDRESS2",
30
+ billing_city: "BCITY",
31
+ billing_state: "BSTATE",
32
+ billing_postal_code: "BZIP",
33
+ billing_country: "BCOUNTRY",
34
+ #shipping_address
35
+ shipping_name: "SNAME",
36
+ shipping_address: "SADDRESS",
37
+ shipping_address2:"SADDRESS2",
38
+ shipping_city: "SCITY",
39
+ shipping_state: "SSTATE",
40
+ shipping_postal_code: "SZIP",
41
+ shipping_region: "SCOUNTY",
42
+ shipping_country: "SCOUNTRY",
43
+ #customer
44
+ customer_id: "CUSTID",
45
+ customer_reference_id:"CUSTREF",
14
46
  }
15
47
  end
16
48
  end
@@ -4,16 +4,15 @@ require 'paytrace/api/response'
4
4
  module PayTrace
5
5
  module API
6
6
  class Gateway
7
- DOMAIN = "paytrace.com"
8
- API_ROOT = "api/default.pay"
9
- URL = "https://#{DOMAIN}/#{API_ROOT}"
7
+ attr_accessor :connection
10
8
 
11
- def initialize(connection: Faraday.new)
12
- @connection = connection
9
+ def initialize(connection: nil)
10
+ @connection = connection
11
+ @connection ||= PayTrace.configuration.connection
13
12
  end
14
13
 
15
14
  def send_request(request)
16
- res = @connection.post URL, parmlist: request.to_parms_string
15
+ res = @connection.post PayTrace.configuration.url, parmlist: request.to_parms_string
17
16
  PayTrace::API::Response.new(res.body)
18
17
  end
19
18
  end
@@ -25,14 +25,64 @@ module PayTrace
25
25
 
26
26
  private
27
27
  def add_transaction(t)
28
- @params[:card_number] = t.credit_card.card_number
29
- @params[:expiration_month] = t.credit_card.expiration_month
30
- @params[:expiration_year] = t.credit_card.expiration_year
28
+ add_credit_card t.credit_card if t.credit_card
29
+ add_customer t.customer if t.customer
31
30
  @params[:transaction_type] = t.type
32
31
  @params[:method] = TRANSACTION_METHOD
33
32
  @params[:amount] = t.amount
33
+ load_address(t)
34
+ load_optional_fields(t) if t.optional_fields
34
35
  end
35
36
 
37
+ def add_credit_card(cc)
38
+ @params[:card_number] = cc.card_number if cc.card_number
39
+ @params[:expiration_month] = cc.expiration_month if cc.expiration_month
40
+ @params[:expiration_year] = cc.expiration_year if cc.expiration_year
41
+ @params[:swipe] = cc.swipe if cc.swipe
42
+ @params[:csc] = cc.csc if cc.csc
43
+ end
44
+
45
+ def load_optional_fields(t)
46
+ o = t.optional_fields
47
+ @params[:email] = o[:email] if o[:email]
48
+ @params[:description] = o[:description] if o[:description]
49
+ @params[:tax_amount] = o[:tax_amount] if o[:tax_amount]
50
+ @params[:return_clr] = o[:return_clr] if o[:return_clr]
51
+ @params[:enable_partial_authentication] = o[:enable_partial_authentication] if o[:enable_partial_authentication]
52
+ @params[:discretionary_data] = o[:discretionary_data] if o[:discretionary_data]
53
+ @params[:custom_dba] = o[:custom_dba] if o[:custom_dba]
54
+ end
55
+
56
+ def load_address(t)
57
+ add_shipping_address(t.shipping_address) if t.shipping_address
58
+ add_billing_address(t.billing_address) if t.billing_address
59
+ end
60
+
61
+ def add_customer(c)
62
+ @params[:customer_id] = c.customer_id
63
+ end
64
+
65
+ def add_shipping_address(s)
66
+ add_address("shipping",s)
67
+ end
68
+
69
+ def add_billing_address(b)
70
+ add_address("billing",b)
71
+ end
72
+
73
+ def add_address(address_type, address)
74
+ @params[:"#{address_type}_name"] = address.name if address.name
75
+ @params[:"#{address_type}_address"] = address.street if address.street
76
+ @params[:"#{address_type}_address2"] = address.street2 if address.street2
77
+ @params[:"#{address_type}_city"] = address.city if address.city
78
+ @params[:"#{address_type}_region"] = address.region if address.region
79
+ @params[:"#{address_type}_state"] = address.state if address.state
80
+ @params[:"#{address_type}_postal_code"] = address.postal_code if address.postal_code
81
+ @params[:"#{address_type}_country"] = address.country if address.country
82
+
83
+ end
84
+
85
+
36
86
  end
37
87
  end
38
88
  end
@@ -1,6 +1,16 @@
1
1
  module PayTrace
2
2
  class Configuration
3
- attr_accessor :user_name, :password
3
+ attr_accessor :user_name, :password, :connection, :domain, :path
4
+
5
+ def initialize
6
+ @domain = "paytrace.com"
7
+ @connection = Faraday.new
8
+ @path = "api/default.pay"
9
+ end
10
+
11
+ def url
12
+ "https://#{@domain}/#{@path}"
13
+ end
4
14
  end
5
15
 
6
16
  def self.configuration
@@ -1,11 +1,14 @@
1
1
  module PayTrace
2
2
  class CreditCard
3
- attr_accessor :card_number, :expiration_month, :expiration_year
3
+ attr_accessor :card_number, :expiration_month, :expiration_year, :swipe, :csc
4
+
5
+ def initialize(options={})
4
6
 
5
- def initialize(options = {})
6
7
  @card_number = options[:card_number]
7
8
  @expiration_month = options[:expiration_month]
8
9
  @expiration_year = options[:expiration_year]
10
+ @swipe = options[:swipe]
11
+ @csc = options[:csc]
9
12
  end
10
13
  end
11
14
  end
@@ -0,0 +1,10 @@
1
+ module PayTrace
2
+ class Customer
3
+ attr_accessor :customer_id
4
+
5
+ def initialize(customer_id: nil)
6
+ @customer_id = customer_id
7
+ end
8
+ end
9
+ end
10
+
@@ -1,17 +1,25 @@
1
1
  require 'paytrace/api/request'
2
2
  require 'paytrace/api/gateway'
3
-
3
+ require 'paytrace/address'
4
4
  module PayTrace
5
5
  module TransactionOperations
6
- def sale(amount: nil, credit_card: nil, options: {})
6
+ def sale(params)
7
+ amount = params[:amount]
8
+ cc = CreditCard.new(params[:credit_card]) if params[:credit_card]
9
+ customer = Customer.new(customer_id: params[:customer_id]) if params[:customer_id]
10
+
7
11
  t = Transaction.new(amount: amount,
8
- credit_card: credit_card,
9
- type: TransactionTypes::SALE)
12
+ credit_card: cc,
13
+ customer: customer,
14
+ type: TransactionTypes::SALE,
15
+ optional:params)
16
+
10
17
  request = PayTrace::API::Request.new(transaction: t)
11
18
  gateway = PayTrace::API::Gateway.new
12
19
  t.response = gateway.send_request(request)
13
20
  t
14
21
  end
22
+
15
23
  end
16
24
 
17
25
  class Transaction
@@ -19,18 +27,47 @@ module PayTrace
19
27
  include TransactionOperations
20
28
  end
21
29
 
22
- attr_reader :amount, :credit_card, :type
30
+ attr_reader :amount, :credit_card, :type, :customer, :billing_address, :shipping_address,:optional_fields
23
31
  attr_accessor :response
24
32
 
25
- def initialize(amount: nil, credit_card: nil, type: nil)
33
+ def set_shipping_same_as_billing()
34
+ @shipping_address = @billing_address
35
+ end
36
+
37
+
38
+
39
+ def initialize(amount: nil, credit_card: nil, customer: nil, type: nil, optional: nil )
26
40
  @amount = amount
27
- @credit_card = CreditCard.new(credit_card)
41
+ @credit_card = credit_card
28
42
  @type = type
43
+ @customer = customer
44
+ include_optional(optional) if optional
29
45
  end
30
46
 
47
+ private
48
+ def include_optional(optional)
49
+
50
+ b = optional[:billing_address]
51
+ @billing_address = PayTrace::Address.new(b) if b
52
+ s = optional[:shipping_address]
53
+ @shipping_address = PayTrace::Address.new(s) if s
54
+ if optional[:address_shipping_same_as_billing]
55
+ self.set_shipping_same_as_billing
56
+ end
57
+
58
+ #clear these out so we have a clean hash
59
+ optional[:billing_address] = nil
60
+ optional[:shipping_address] = nil
61
+
62
+ @optional_fields = optional
63
+
64
+ end
65
+
66
+
31
67
  end
32
68
 
33
69
  module TransactionTypes
34
70
  SALE = "SALE"
35
71
  end
72
+
36
73
  end
@@ -1,3 +1,3 @@
1
1
  module PayTrace
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/paytrace.gemspec CHANGED
@@ -18,9 +18,9 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "faraday"
21
+ spec.add_dependency "faraday", "~> 0.9"
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 1.3"
24
- spec.add_development_dependency "rake"
25
- spec.add_development_dependency "mocha"
24
+ spec.add_development_dependency "rake", "~> 10.1"
25
+ spec.add_development_dependency "mocha", "~> 1.0"
26
26
  end
@@ -23,4 +23,14 @@ describe PayTrace::API::Gateway do
23
23
  stubs.verify_stubbed_calls
24
24
  r.must_equal response
25
25
  end
26
+
27
+ it "initializes the connection based on the configuration" do
28
+ faraday_connection = mock
29
+ PayTrace.configure do |config|
30
+ config.connection = faraday_connection
31
+ end
32
+ gateway = PayTrace::API::Gateway.new
33
+ gateway.connection.must_equal faraday_connection
34
+ end
35
+
26
36
  end
@@ -25,12 +25,12 @@ describe PayTrace::API::Request do
25
25
  end
26
26
 
27
27
  it "can add a transaction to its param list" do
28
- t = PayTrace::Transaction.new(amount: "23.12",
29
- credit_card: {
28
+ t = PayTrace::Transaction.new({amount: "23.12",
29
+ credit_card: PayTrace::CreditCard.new({
30
30
  card_number: "1234123412341234",
31
31
  expiration_year: 24,
32
- expiration_month: 10 },
33
- type: PayTrace::TransactionTypes::SALE)
32
+ expiration_month: 10 }),
33
+ type: PayTrace::TransactionTypes::SALE})
34
34
  r = PayTrace::API::Request.new(transaction: t)
35
35
 
36
36
  r.params[:card_number].must_equal "1234123412341234"
@@ -44,4 +44,95 @@ describe PayTrace::API::Request do
44
44
  url.must_equal "UN~test|PSWD~test|TERMS~Y|CC~1234123412341234|EXPMNTH~10|EXPYR~24|TRANXTYPE~SALE|METHOD~PROCESSTRANX|AMOUNT~23.12|"
45
45
  end
46
46
 
47
+ it "can use a customer id for processing the transaction" do
48
+ t = PayTrace::Transaction.new({amount: "12.34",
49
+ customer: PayTrace::Customer.new(customer_id: "1234"),
50
+ type: PayTrace::TransactionTypes::SALE
51
+ }
52
+ )
53
+ r = PayTrace::API::Request.new(transaction: t)
54
+ r.params[:customer_id].must_equal "1234"
55
+ r.params[:amount].must_equal "12.34"
56
+
57
+ url = r.to_parms_string
58
+
59
+ #Make sure it puts in values we expect
60
+ url.must_match /\|CUSTID~1234\|/
61
+ url.must_match /\|AMOUNT~12.34\|/
62
+ url.must_match /\|METHOD~PROCESSTRANX\|/
63
+ url.must_match /\|TRANXTYPE~SALE\|/
64
+ end
65
+
66
+ it "can include a billing address" do
67
+ t = PayTrace::Transaction.new(
68
+ optional:{
69
+ billing_address:{
70
+ name:"John Doe",
71
+ street:"1234 happy lane",
72
+ street2:"apt#2",
73
+ city:"Seattle",
74
+ state:"WA",
75
+ country: "US",
76
+ postal_code:"98107"
77
+ }
78
+ }
79
+ )
80
+ r = PayTrace::API::Request.new(transaction: t)
81
+
82
+ url = r.to_parms_string
83
+
84
+ #Make sure it puts in values we expect
85
+ url.must_match /\|BNAME~John Doe\|/
86
+ url.must_match /\|BADDRESS~1234 happy lane\|/
87
+ url.must_match /\|BADDRESS2~apt#2\|/
88
+ url.must_match /\|BCITY~Seattle\|/
89
+ url.must_match /\|BSTATE~WA\|/
90
+ url.must_match /\|BSTATE~WA\|/
91
+ url.must_match /\|BCOUNTRY~US\|/
92
+
93
+ end
94
+
95
+ it "can include misc fields as well" do
96
+ t = PayTrace::Transaction.new(
97
+ optional: {
98
+ email:"it@paytrace.com",
99
+ description:"This is a test",
100
+ tax_amount: "1.00",
101
+ return_clr: "Y",
102
+ enable_partial_authentication:"Y",
103
+ discretionary_data:"This is some data that is discretionary",
104
+ custom_dba:"NewName"
105
+ }
106
+ )
107
+
108
+ r = PayTrace::API::Request.new(transaction: t)
109
+
110
+ url = r.to_parms_string
111
+
112
+ url.must_match /\|DESCRIPTION~This is a test\|/
113
+ url.must_match /\|TAX~1.00\|/
114
+ url.must_match /\|EMAIL~it@paytrace.com\|/
115
+ url.must_match /\|RETURNCLR~Y\|/
116
+ url.must_match /\|ENABLEPARTIALAUTH~Y\|/
117
+ url.must_match /\|DISCRETIONARY DATA~This is some data that is discretionary\|/
118
+ url.must_match /\|CUSTOMDBA~NewName\|/
119
+ end
120
+
121
+ it "can do a swipe transaction" do
122
+ cc = PayTrace::CreditCard.new( {
123
+ swipe: '%B4055010000000005^J/SCOTT^1212101001020001000000701000000?;4055010000000005=12121010010270100001?'
124
+ })
125
+ t = PayTrace::Transaction.new(
126
+ amount: '1.00',
127
+ credit_card:cc
128
+ )
129
+
130
+ r = PayTrace::API::Request.new(transaction: t)
131
+ url = r.to_parms_string
132
+
133
+ url.must_match /\|AMOUNT~1.00\|/
134
+ url.must_match /\|SWIPE~%B4055010000000005/
135
+
136
+
137
+ end
47
138
  end
@@ -18,4 +18,19 @@ describe PayTrace::Configuration do
18
18
  PayTrace.configuration.user_name.must_equal "demo"
19
19
  PayTrace.configuration.password.must_equal "demo"
20
20
  end
21
+
22
+ it "has reasonable defaults" do
23
+ c = PayTrace::Configuration.new
24
+ c.domain.must_equal "paytrace.com"
25
+ c.connection.must_be_instance_of Faraday::Connection
26
+ c.url.must_equal "https://paytrace.com/api/default.pay"
27
+ c.path.must_equal "api/default.pay"
28
+ end
29
+
30
+ it "allows you to configure what domain to point at" do
31
+ PayTrace.configure do |config|
32
+ config.domain = "sandbox.paytrace.com"
33
+ end
34
+ PayTrace.configuration.url.must_equal "https://sandbox.paytrace.com/api/default.pay"
35
+ end
21
36
  end
@@ -11,4 +11,16 @@ describe PayTrace::CreditCard do
11
11
  cc.expiration_month.must_equal 10
12
12
  cc.expiration_year.must_equal 24
13
13
  end
14
+
15
+ it "can be initialized from a hash" do
16
+ cc = {credit_card: {
17
+ card_number: "1234123412341234",
18
+ expiration_month: 10,
19
+ expiration_year: 24
20
+ }}
21
+
22
+ cc = PayTrace::CreditCard.new(cc[:credit_card])
23
+ cc.card_number.must_equal "1234123412341234"
24
+
25
+ end
14
26
  end
@@ -1,26 +1,112 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '../../test_helper.rb')
2
2
 
3
3
  describe PayTrace::Transaction do
4
- it "can charge sales to a credit card" do
5
- response = mock()
6
- PayTrace::API::Gateway.any_instance.expects(:send_request).returns(response)
7
-
8
- t = PayTrace::Transaction.sale(
9
- amount: "1242.32",
10
- credit_card: {
11
- card_number: "1234123412341234",
12
- expiration_month: 10,
13
- expiration_year: 24
14
- })
15
-
16
- #Transaction is properly configured
17
- t.amount.must_equal "1242.32"
18
- t.type.must_equal PayTrace::TransactionTypes::SALE
19
-
20
- #Sets up a card
21
- t.credit_card.card_number.must_equal "1234123412341234"
22
- t.credit_card.expiration_month.must_equal 10
23
- t.credit_card.expiration_year.must_equal 24
24
- t.response.must_equal response
4
+ describe "create sales transactions" do
5
+ before do
6
+ @response = mock()
7
+ PayTrace::API::Gateway.any_instance.expects(:send_request).returns(@response)
8
+ end
9
+ it "can charge sales to a credit card" do
10
+ t = PayTrace::Transaction.sale(
11
+ {amount: "1242.32",
12
+ credit_card: {
13
+ card_number: "1234123412341234",
14
+ expiration_month: 10,
15
+ expiration_year: 24
16
+ }
17
+ })
18
+
19
+ #Transaction is properly configured
20
+ t.amount.must_equal "1242.32"
21
+ t.type.must_equal PayTrace::TransactionTypes::SALE
22
+
23
+ #Sets up a card
24
+ t.credit_card.card_number.must_equal "1234123412341234"
25
+ t.credit_card.expiration_month.must_equal 10
26
+ t.credit_card.expiration_year.must_equal 24
27
+ t.response.must_equal @response
28
+ end
29
+
30
+ it "can run a transaction for a customer" do
31
+ t = PayTrace::Transaction.sale(
32
+ {amount: "1.00",
33
+ customer_id: "123456"}
34
+ )
35
+
36
+ t.amount.must_equal "1.00"
37
+ t.type.must_equal PayTrace::TransactionTypes::SALE
38
+ t.customer.customer_id.must_equal "123456"
39
+ t.credit_card.must_be_nil
40
+ t.response.must_equal @response
41
+
42
+ end
25
43
  end
44
+ describe "adding address info" do
45
+ it "can take a shipping address" do
46
+ t = PayTrace::Transaction.new(
47
+ optional:{
48
+ shipping_address: {
49
+ name: "Bob Smith",
50
+ street: "1234 happy lane",
51
+ street2: "suit 234",
52
+ city:"Seattle",
53
+ state:"WA",
54
+ country:"USA",
55
+ postal_code:"98107"
56
+ }
57
+ }
58
+ )
59
+ s = t.shipping_address
60
+ s.name.must_equal "Bob Smith"
61
+ s.street.must_equal "1234 happy lane"
62
+ s.street2.must_equal "suit 234"
63
+ s.city.must_equal "Seattle"
64
+ s.state.must_equal "WA"
65
+ s.country.must_equal "USA"
66
+ s.postal_code.must_equal "98107"
67
+
68
+ end
69
+ it "can take a billing address" do
70
+ t = PayTrace::Transaction.new(
71
+ optional: {
72
+ billing_address: {
73
+ street: "1234 happy lane",
74
+ street2: "suit 234",
75
+ city:"Seattle",
76
+ state:"WA",
77
+ country:"USA",
78
+ postal_code:"98107"
79
+ }
80
+ }
81
+ )
82
+ b = t.billing_address
83
+ b.street.must_equal "1234 happy lane"
84
+ b.street2.must_equal "suit 234"
85
+ b.city.must_equal "Seattle"
86
+ b.state.must_equal "WA"
87
+ b.country.must_equal "USA"
88
+ b.postal_code.must_equal "98107"
89
+ end
90
+
91
+ it "will return the same address if set to billing shipping same address" do
92
+ address = {
93
+ street: "1234 happy lane",
94
+ street2: "suit 234",
95
+ city:"Seattle",
96
+ state:"WA",
97
+ country:"USA",
98
+ postal_code:"98107"
99
+ }
100
+
101
+ t = PayTrace::Transaction.new(
102
+ optional: { billing_address: address
103
+ } )
104
+ t.set_shipping_same_as_billing
105
+
106
+ t.shipping_address.must_equal t.billing_address
107
+ end
108
+
109
+
110
+ end
111
+
26
112
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paytrace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Trevor Redfern
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-05 00:00:00.000000000 Z
11
+ date: 2014-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '0.9'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '0.9'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -42,30 +42,30 @@ dependencies:
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '10.1'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '10.1'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: mocha
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '1.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '1.0'
69
69
  description: Integration with PayTrace Payment Gateway
70
70
  email:
71
71
  - trevor@paytrace.com
@@ -76,21 +76,20 @@ files:
76
76
  - ".gitignore"
77
77
  - ".ruby-gemset"
78
78
  - ".ruby-version"
79
- - ".vagrant/machines/default/virtualbox/action_provision"
80
- - ".vagrant/machines/default/virtualbox/action_set_name"
81
- - ".vagrant/machines/default/virtualbox/id"
82
79
  - Gemfile
83
80
  - LICENSE.txt
84
81
  - README.md
85
82
  - Rakefile
86
83
  - Vagrantfile
87
84
  - lib/paytrace.rb
85
+ - lib/paytrace/address.rb
88
86
  - lib/paytrace/api/fields.rb
89
87
  - lib/paytrace/api/gateway.rb
90
88
  - lib/paytrace/api/request.rb
91
89
  - lib/paytrace/api/response.rb
92
90
  - lib/paytrace/configuration.rb
93
91
  - lib/paytrace/credit_card.rb
92
+ - lib/paytrace/customer.rb
94
93
  - lib/paytrace/transaction.rb
95
94
  - lib/paytrace/version.rb
96
95
  - paytrace.gemspec
@@ -1 +0,0 @@
1
- 1393536090
@@ -1 +0,0 @@
1
- 1393536080
@@ -1 +0,0 @@
1
- a966b052-f49f-413f-a0a3-60539add62a1