vcx-elements 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/gem-create.gemspec +1 -1
  2. data/lib/elements.rb +59 -5
  3. metadata +2 -2
data/gem-create.gemspec CHANGED
@@ -3,7 +3,7 @@ $:.unshift 'lib'
3
3
  Gem::Specification.new do |s|
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.name = "vcx-elements"
6
- s.version = "0.2.0"
6
+ s.version = "0.2.1"
7
7
  s.date = Time.now.strftime('%Y-%m-%d')
8
8
  s.homepage = "https://github.com/livegamervcxdevteam/elementsapi.git"
9
9
  s.authors = ["livegamer"]
data/lib/elements.rb CHANGED
@@ -104,6 +104,27 @@ module Elements
104
104
  post_data("forexOffer", params)
105
105
  end
106
106
 
107
+ #def self.create_cashin_po(order, ipaddress='1.1.1.1')
108
+ #class << order
109
+ #attr_accessor :cashin_forex_elements_id, :cashin_config_id
110
+ #end
111
+
112
+ #Configurable Elements Ids
113
+ #order.cashin_forex_elements_id = '1850'
114
+ #order.cashin_config_id = '1347'
115
+
116
+ #lineItem, payment = cashin_purchase_info(order, ipaddress)
117
+
118
+ #params = {
119
+ #orderCommand: 'AUTHORIZE',
120
+ #buyerUser: {'@id' => order.user.elements_id},
121
+ #lineItems: lineItem,
122
+ #payment: payment
123
+ #}
124
+ #rs = XmlSimple.xml_in post_xml_data("purchaseOrder", params,"purchaseOrder")
125
+ #rs['id']
126
+ #end
127
+
107
128
  #Create purchase order is a class method that creates a new purchaseOrder in the elements system depending on the order type
108
129
  def self.create_purchase_order( order, ipaddress='1.1.1.1' )
109
130
  lineItems, payment = send("#{order.order_type}_purchase_info", order, ipaddress)
@@ -112,7 +133,7 @@ module Elements
112
133
 
113
134
  lineItems.each_with_index do |lineItem, index|
114
135
  params = {
115
- orderCommand: 'AUTHORIZE',
136
+ orderCommand: order.order_type=='cashin' ? 'CHARGE' : 'AUTHORIZE',
116
137
  buyerUser: {'@id' => order.user.elements_id},
117
138
  lineItems: lineItem,
118
139
  payment: payment[index]
@@ -134,6 +155,7 @@ module Elements
134
155
  elements_ids.each do |elements_id|
135
156
  XmlSimple.xml_in post_xml_data("purchaseOrder/#{elements_id}/command", params,"purchaseOrderCommand")
136
157
  end
158
+
137
159
  end
138
160
 
139
161
  #Cancel Purchase Order is a class method that cancels an order that has already been created
@@ -157,6 +179,34 @@ module Elements
157
179
  sell_purchase_info(order, ipaddress)
158
180
  end
159
181
 
182
+ #Sell Purchase Info is a class method that returns the sell line items and payment information for the order
183
+ def self.cashin_purchase_info(order, ipaddress)
184
+ #Configurable Elements Ids
185
+ cashin_forex_elements_id = '1850'
186
+ cashin_config_id = '1347'
187
+
188
+ line_items = [{ 'forexOffer' => { 'forexOfferRequest' => { '@amountFromCurrency' => order.total_due.abs, '@id' => cashin_forex_elements_id} } }]
189
+
190
+ payment_profile = order.payment_profile
191
+ payment = [{
192
+ '@configId' => cashin_config_id,
193
+ 'creditCard' => {
194
+ 'billToStreetAddress' => payment_profile.billing_address1 + payment_profile.billing_address2,
195
+ 'billToZipCode' => payment_profile.zipcode,
196
+ 'creditCardNumber' => payment_profile.account_number,
197
+ 'creditCardType' => payment_profile.account_type,
198
+ 'expDate' => payment_profile.expiration_date, #To be fixed
199
+ 'securityCode' => payment_profile.ccv,
200
+ 'firstname' => payment_profile.name.split[0],
201
+ 'surname' => payment_profile.name.split[1],
202
+ 'stateProvince' => payment_profile.state,
203
+ 'countryCode' => 'US' #To be fixed
204
+ }
205
+ }]
206
+
207
+ return line_items, payment
208
+ end
209
+
160
210
  #Sell Purchase Info is a class method that returns the sell line items and payment information for the order
161
211
  def self.sell_purchase_info(order, ipaddress)
162
212
  line_items = Array.new
@@ -201,20 +251,24 @@ module Elements
201
251
  def self.fetch_order_elements(order)
202
252
  elements_id = order.elements_id
203
253
  case order.order_type
204
- when /['sell'|'buy']/
205
- [elements_id]
254
+ when 'cashin'
255
+ [order.cashin_elements_id]
206
256
  when 'exchange'
207
257
  order.elements_id.split('|')
258
+ when /['sell'|'buy']/
259
+ [elements_id]
208
260
  end
209
261
  end
210
262
 
211
263
  #Save Order Elements is a class method that saves the elements_id from order table depending on the order type
212
264
  def self.save_order_elements(elements_ids, order)
213
265
  case order.order_type
214
- when /['sell'|'buy']/
215
- order.update_column 'elements_id', elements_ids.first
266
+ when 'cashin'
267
+ order.update_column 'cashin_elements_id', elements_ids.first
216
268
  when 'exchange'
217
269
  order.update_column 'elements_id', elements_ids.join('|')
270
+ when /['sell'|'buy']/
271
+ order.update_column 'elements_id', elements_ids.first
218
272
  end
219
273
  end
220
274
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vcx-elements
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-20 00:00:00.000000000 Z
12
+ date: 2012-09-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake