vaulted_billing 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  module VaultedBilling
2
2
  class CreditCard
3
- attr_accessor :id
3
+ attr_accessor :vault_id
4
4
  attr_accessor :currency
5
5
  attr_accessor :card_number
6
6
  attr_accessor :cvv_number
@@ -20,5 +20,29 @@ module VaultedBilling
20
20
  send("#{key}=", value) if respond_to?("#{key}=")
21
21
  end
22
22
  end
23
+
24
+ def to_vaulted_billing; self; end
25
+
26
+ def ==(o)
27
+ self.attributes == o.attributes
28
+ end
29
+
30
+ def attributes
31
+ {
32
+ :vault_id => vault_id,
33
+ :currency => currency,
34
+ :card_number => card_number,
35
+ :cvv_number => cvv_number,
36
+ :expires_on => expires_on,
37
+ :first_name => first_name,
38
+ :last_name => last_name,
39
+ :street_address => street_address,
40
+ :locality => locality,
41
+ :region => region,
42
+ :postal_code => postal_code,
43
+ :country => country,
44
+ :phone => phone
45
+ }
46
+ end
23
47
  end
24
48
  end
@@ -1,12 +1,28 @@
1
1
  module VaultedBilling
2
2
  class Customer
3
- attr_accessor :id
3
+ attr_accessor :vault_id
4
+ attr_accessor :merchant_id
4
5
  attr_accessor :email
5
6
 
6
7
  def initialize(attributes = {})
7
8
  attributes = HashWithIndifferentAccess.new(attributes)
8
- @id = attributes[:id]
9
+ @vault_id = attributes[:vault_id]
10
+ @merchant_id = attributes[:merchant_id]
9
11
  @email = attributes[:email]
10
12
  end
13
+
14
+ def to_vaulted_billing; self; end
15
+
16
+ def ==(o)
17
+ self.attributes == o.attributes
18
+ end
19
+
20
+ def attributes
21
+ {
22
+ :vault_id => vault_id,
23
+ :merchant_id => merchant_id,
24
+ :email => email
25
+ }
26
+ end
11
27
  end
12
28
  end
@@ -1,6 +1,7 @@
1
1
  module VaultedBilling
2
2
  module Gateway
3
3
  module Response
4
+ attr_accessor :raw_response
4
5
  attr_accessor :response_message
5
6
  attr_writer :success
6
7
  def success?; @success; end
@@ -54,6 +55,7 @@ module VaultedBilling
54
55
  object.tap do |o|
55
56
  o.extend(VaultedBilling::Gateway::Response)
56
57
  o.success = options.has_key?(:success) ? options[:success] : true
58
+ o.raw_response = options[:raw_response] || ''
57
59
  yield(o) if block_given?
58
60
  end
59
61
  end
@@ -20,75 +20,87 @@ module VaultedBilling
20
20
  end
21
21
 
22
22
  def add_customer(customer)
23
+ customer = customer.to_vaulted_billing
23
24
  data = build_request('createCustomerProfileRequest') do |xml|
24
25
  xml.tag!('profile') do
25
- xml.merchantCustomerId customer.id if customer.id
26
+ xml.merchantCustomerId customer.merchant_id if customer.merchant_id
26
27
  xml.email customer.email if customer.email
27
28
  end
28
29
  end
29
30
  result = post_data(data)
30
- respond_with(customer, :success => result.success?) { |c| c.id = (result.body['createCustomerProfileResponse'] || {})['customerProfileId'] }
31
+ respond_with(customer, :success => result.success?, :raw_response => result.raw_response) { |c| c.vault_id = (result.body['createCustomerProfileResponse'] || {})['customerProfileId'] }
31
32
  end
32
33
 
33
34
  def update_customer(customer)
35
+ customer = customer.to_vaulted_billing
34
36
  result = post_data(build_request('updateCustomerProfileRequest') { |xml|
35
37
  xml.tag!('profile') {
36
- xml.merchantCustomerId customer.id
37
38
  xml.email customer.email
39
+ xml.customerProfileId customer.vault_id
38
40
  }
39
41
  })
40
- respond_with(customer, :success => result.success?)
42
+ respond_with(customer, :success => result.success?, :raw_response => result.raw_response)
41
43
  end
42
44
 
43
45
  def remove_customer(customer)
46
+ customer = customer.to_vaulted_billing
44
47
  result = post_data(build_request('deleteCustomerProfileRequest') { |xml|
45
- xml.customerProfileId customer.id
48
+ xml.customerProfileId customer.vault_id
46
49
  })
47
50
  respond_with(customer, :success => result.success?)
48
51
  end
49
52
 
50
53
  def add_customer_credit_card(customer, credit_card)
54
+ customer = customer.to_vaulted_billing
55
+ credit_card = credit_card.to_vaulted_billing
51
56
  result = post_data(build_request('createCustomerPaymentProfileRequest') { |xml|
52
- xml.customerProfileId customer.id
57
+ xml.customerProfileId customer.vault_id
53
58
  xml.paymentProfile do
54
59
  billing_info!(xml, customer, credit_card)
55
60
  credit_card_info!(xml, customer, credit_card)
56
61
  end
57
62
  })
58
- respond_with(credit_card, :success => result.success?) { |c| c.id = (result.body['createCustomerPaymentProfileResponse'] || {})['customerPaymentProfileId'] }
63
+ respond_with(credit_card, :success => result.success?, :raw_response => result.raw_response) { |c| c.vault_id = (result.body['createCustomerPaymentProfileResponse'] || {})['customerPaymentProfileId'] }
59
64
  end
60
65
 
61
66
  def update_customer_credit_card(customer, credit_card)
67
+ customer = customer.to_vaulted_billing
68
+ credit_card = credit_card.to_vaulted_billing
62
69
  result = post_data(build_request('updateCustomerPaymentProfileRequest') { |xml|
63
- xml.customerProfileId customer.id
70
+ xml.customerProfileId customer.vault_id
64
71
  xml.paymentProfile do
65
72
  billing_info!(xml, customer, credit_card)
66
73
  credit_card_info!(xml, customer, credit_card)
67
- xml.customerPaymentProfileId credit_card.id
74
+ xml.customerPaymentProfileId credit_card.vault_id
68
75
  end
69
76
  })
70
77
  respond_with(credit_card, :success => result.success?)
71
78
  end
72
79
 
73
80
  def remove_customer_credit_card(customer, credit_card)
81
+ customer = customer.to_vaulted_billing
82
+ credit_card = credit_card.to_vaulted_billing
74
83
  result = post_data(build_request('deleteCustomerPaymentProfileRequest') { |xml|
75
- xml.customerProfileId customer.id
76
- xml.customerPaymentProfileId credit_card.id
84
+ xml.customerProfileId customer.vault_id
85
+ xml.customerPaymentProfileId credit_card.vault_id
77
86
  })
78
- respond_with(credit_card, :success => result.success?)
87
+ respond_with(credit_card, :success => result.success?, :raw_response => result.raw_response)
79
88
  end
80
89
 
81
90
  def authorize(customer, credit_card, amount)
91
+ customer = customer.to_vaulted_billing
92
+ credit_card = credit_card.to_vaulted_billing
82
93
  result = post_data(build_request('createCustomerProfileTransactionRequest') { |xml|
83
94
  xml.transaction do
84
95
  xml.profileTransAuthOnly do
85
96
  xml.amount amount
86
- xml.customerProfileId customer.id
87
- xml.customerPaymentProfileId credit_card.id
97
+ xml.customerProfileId customer.vault_id
98
+ xml.customerPaymentProfileId credit_card.vault_id
88
99
  end
89
100
  end
101
+ xml.extraOptions 'x_duplicate_window=0'
90
102
  })
91
- respond_with(new_transaction_from_response(result.body), :success => result.success?)
103
+ respond_with(new_transaction_from_response(result.body), :success => result.success?, :raw_response => result.raw_response)
92
104
  end
93
105
 
94
106
  def capture(transaction_id, amount)
@@ -99,8 +111,9 @@ module VaultedBilling
99
111
  xml.transId transaction_id
100
112
  end
101
113
  end
114
+ xml.extraOptions 'x_duplicate_window=0'
102
115
  })
103
- respond_with(new_transaction_from_response(result.body), :success => result.success?)
116
+ respond_with(new_transaction_from_response(result.body), :success => result.success?, :raw_response => result.raw_response)
104
117
  end
105
118
 
106
119
  def refund(transaction_id, amount)
@@ -111,8 +124,9 @@ module VaultedBilling
111
124
  xml.transId transaction_id
112
125
  end
113
126
  end
127
+ xml.extraOptions 'x_duplicate_window=0'
114
128
  })
115
- respond_with(new_transaction_from_response(result.body), :success => result.success?)
129
+ respond_with(new_transaction_from_response(result.body), :success => result.success?, :raw_response => result.raw_response)
116
130
  end
117
131
 
118
132
  def void(transaction_id)
@@ -122,8 +136,9 @@ module VaultedBilling
122
136
  xml.transId transaction_id
123
137
  end
124
138
  end
139
+ xml.extraOptions 'x_duplicate_window=0'
125
140
  })
126
- respond_with(new_transaction_from_response(result.body), :success => result.success?)
141
+ respond_with(new_transaction_from_response(result.body), :success => result.success?, :raw_response => result.raw_response)
127
142
  end
128
143
 
129
144
 
@@ -5,28 +5,31 @@ module VaultedBilling
5
5
  class Bogus
6
6
  include VaultedBilling::Gateway
7
7
 
8
+ def initialize(options = {})
9
+ end
10
+
8
11
  def add_customer(customer)
9
- respond_with(customer) { |c| c.id = new_identifier }
12
+ respond_with(customer.to_vaulted_billing) { |c| c.vault_id = new_identifier }
10
13
  end
11
14
 
12
15
  def update_customer(customer)
13
- respond_with customer
16
+ respond_with customer.to_vaulted_billing
14
17
  end
15
18
 
16
19
  def remove_customer(customer)
17
- respond_with customer
20
+ respond_with customer.to_vaulted_billing
18
21
  end
19
22
 
20
23
  def add_customer_credit_card(customer, credit_card)
21
- respond_with(credit_card) { |c| c.id = new_identifier }
24
+ respond_with(credit_card.to_vaulted_billing) { |c| c.vault_id = new_identifier }
22
25
  end
23
26
 
24
27
  def update_customer_credit_card(customer, credit_card)
25
- respond_with credit_card
28
+ respond_with credit_card.to_vaulted_billing
26
29
  end
27
30
 
28
31
  def remove_customer_credit_card(customer, credit_card)
29
- respond_with credit_card
32
+ respond_with credit_card.to_vaulted_billing
30
33
  end
31
34
 
32
35
  def authorize(customer, credit_card, amount)
@@ -31,7 +31,7 @@ module VaultedBilling
31
31
  # via the add_customer_credit_card method.
32
32
  #
33
33
  def add_customer(customer)
34
- respond_with customer
34
+ respond_with customer.to_vaulted_billing
35
35
  end
36
36
 
37
37
  ##
@@ -40,7 +40,7 @@ module VaultedBilling
40
40
  # handled via the update_customer_credit_card method.
41
41
  #
42
42
  def update_customer(customer)
43
- respond_with customer
43
+ respond_with customer.to_vaulted_billing
44
44
  end
45
45
 
46
46
  ##
@@ -49,36 +49,36 @@ module VaultedBilling
49
49
  # handled via the remove_customer_credit_card method.
50
50
  #
51
51
  def remove_customer(customer)
52
- respond_with customer
52
+ respond_with customer.to_vaulted_billing
53
53
  end
54
54
 
55
55
  def add_customer_credit_card(customer, credit_card)
56
- response = post_data(storage_data('add_customer', customer, credit_card))
57
- respond_with(credit_card, :success => response.success?) do |c|
58
- c.id = response.body['customer_vault_id']
56
+ response = post_data(storage_data('add_customer', customer.to_vaulted_billing, credit_card.to_vaulted_billing))
57
+ respond_with(credit_card, :success => response.success?, :raw_response => response.raw_response) do |c|
58
+ c.vault_id = response.body['customer_vault_id']
59
59
  end
60
60
  end
61
61
 
62
62
  def update_customer_credit_card(customer, credit_card)
63
- response = post_data(storage_data('update_customer', customer, credit_card))
64
- respond_with(credit_card, :success => response.success?)
63
+ response = post_data(storage_data('update_customer', customer.to_vaulted_billing, credit_card.to_vaulted_billing))
64
+ respond_with(credit_card, :success => response.success?, :raw_response => response.raw_response)
65
65
  end
66
66
 
67
67
  def remove_customer_credit_card(customer, credit_card)
68
68
  response = post_data(core_data.merge({
69
69
  :customer_vault => 'delete_customer',
70
- :customer_vault_id => credit_card.id
70
+ :customer_vault_id => credit_card.to_vaulted_billing.vault_id
71
71
  }).to_querystring)
72
- respond_with(credit_card, :success => response.success?)
72
+ respond_with(credit_card, :success => response.success?, :raw_response => response.raw_response)
73
73
  end
74
74
 
75
75
  def authorize(customer, credit_card, amount)
76
76
  response = post_data(transaction_data('auth', {
77
- :customer_vault_id => credit_card.id,
77
+ :customer_vault_id => credit_card.to_vaulted_billing.vault_id,
78
78
  :amount => amount
79
79
  }))
80
80
  respond_with(new_transaction_from_response(response.body),
81
- :success => response.success?)
81
+ :success => response.success?, :raw_response => response.raw_response)
82
82
  end
83
83
 
84
84
  def capture(transaction_id, amount)
@@ -87,7 +87,7 @@ module VaultedBilling
87
87
  :amount => amount
88
88
  }))
89
89
  respond_with(new_transaction_from_response(response.body),
90
- :success => response.success?)
90
+ :success => response.success?, :raw_response => response.raw_response)
91
91
  end
92
92
 
93
93
  def refund(transaction_id, amount)
@@ -96,7 +96,7 @@ module VaultedBilling
96
96
  :amount => amount
97
97
  }))
98
98
  respond_with(new_transaction_from_response(response.body),
99
- :success => response.success?)
99
+ :success => response.success?, :raw_response => response.raw_response)
100
100
  end
101
101
 
102
102
  def void(transaction_id)
@@ -104,7 +104,7 @@ module VaultedBilling
104
104
  :transactionid => transaction_id
105
105
  }))
106
106
  respond_with(new_transaction_from_response(response.body),
107
- :success => response.success?)
107
+ :success => response.success?, :raw_response => response.raw_response)
108
108
  end
109
109
 
110
110
 
@@ -133,13 +133,15 @@ module VaultedBilling
133
133
  end
134
134
 
135
135
  def transaction_data(method, overrides = {})
136
- core_data.merge(overrides).to_querystring
136
+ core_data.merge({
137
+ :type => method.to_s
138
+ }).merge(overrides).to_querystring
137
139
  end
138
140
 
139
141
  def storage_data(method, customer, credit_card)
140
142
  core_data.merge({
141
143
  :customer_vault => method.to_s,
142
- :customer_vault_id => credit_card.id,
144
+ :customer_vault_id => credit_card.vault_id,
143
145
  :currency => credit_card.currency,
144
146
  :method => 'creditcard',
145
147
  :ccnumber => credit_card.card_number,
@@ -60,7 +60,7 @@ module VaultedBilling
60
60
  def post_data(data, request_headers = {})
61
61
  request = Net::HTTP::Post.new(uri.path)
62
62
  request.initialize_http_header({
63
- 'User-Agent' => "vaulted_billing #{VaultedBilling::Version}"
63
+ 'User-Agent' => "vaulted_billing/#{VaultedBilling::Version}"
64
64
  }.reverse_merge(request_headers))
65
65
  request.body = data
66
66
  response = Net::HTTP.new(uri.host, uri.port).tap do |https|
@@ -12,5 +12,22 @@ module VaultedBilling
12
12
  send("#{key}=", value) if respond_to?("#{key}=")
13
13
  end
14
14
  end
15
+
16
+ def to_vaulted_billing; self; end
17
+
18
+ def ==(o)
19
+ attributes == o.attributes
20
+ end
21
+
22
+ def attributes
23
+ {
24
+ :id => id,
25
+ :authcode => authcode,
26
+ :avs_response => avs_response,
27
+ :cvv_response => cvv_response,
28
+ :code => code,
29
+ :message => message
30
+ }
31
+ end
15
32
  end
16
33
  end
@@ -1,3 +1,3 @@
1
1
  module VaultedBilling
2
- Version = '0.0.1'
2
+ Version = '0.0.2'
3
3
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Nathaniel Bibler
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-08-23 00:00:00 -04:00
17
+ date: 2010-08-25 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency