music_today_api_wrapper 28.01.16.01 → 28.02

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: a13056078b8cc16fbad4bda85904b64408bf482e
4
- data.tar.gz: 28133c7238ed7b90e95d8d820c00a199c92a00d1
3
+ metadata.gz: d177561a770f957fb9dc97fcf90b9e6f904d2f9b
4
+ data.tar.gz: 41488a370a54d81e70eb972c74f99f9abf9bb5d1
5
5
  SHA512:
6
- metadata.gz: 6ed88428f63fe91742ff8eb6622edb68167ce9461fb47c472516dd0e58555a88b012900c9f9ee49c5e16e77eb888ee335162a5c4906e4c86e719903fe214ca39
7
- data.tar.gz: 4b2944d6e7c45feeb21c8dbfa5923bc024b149856275a776d14e4054bca2d1289fc7be0a1f319d26fc3dbd48b1b1370af6bec7de5fc8c0bf5cb0669e8055804a
6
+ metadata.gz: 057de96e4e23fbc4c73c294a21184b9e42ec9227cd3b7d0d3a6716703940d9fdaefe644085d96ced16e03bdd808f2ceb7896d4200ca91a4442776d0c1ae45b46
7
+ data.tar.gz: fe4d06879c9f64a7289a8069275cec77ed1882f0e4777cf736a2569d80fd9baee29088b9907db44397a4136e08612f7e9a4fc2f96a3277a02d7d32f5785e7f4d
@@ -32,4 +32,9 @@ module MusicTodayApiWrapper
32
32
  checkout_services = Services::CheckoutServices.new
33
33
  checkout_services.checkout(address, items)
34
34
  end
35
+
36
+ def self.purchase(order)
37
+ checkout_services = Services::CheckoutServices.new
38
+ checkout_services.purchase(order)
39
+ end
35
40
  end
@@ -37,7 +37,7 @@ module MusicTodayApiWrapper
37
37
  validateOnly: false,
38
38
  taxPrepaid: false,
39
39
  billing: { customer: @customer.as_hash,
40
- payment: @payment.as_hash },
40
+ payments: [@payment.as_hash] },
41
41
  currency: 'USD',
42
42
  destinations: @destinations.map(&:as_hash),
43
43
  lineItems: @items.map(&:as_hash),
@@ -0,0 +1,25 @@
1
+ module MusicTodayApiWrapper
2
+ module Resources
3
+ module Purchase
4
+ class Invoice
5
+ attr_accessor :id, :sub_total, :shipping, :taxes, :total
6
+
7
+ def initialize(id, sub_total, shipping, taxes)
8
+ @id = id
9
+ @sub_total = sub_total.to_f
10
+ @shipping = shipping.to_f
11
+ @taxes = taxes.to_f
12
+ @total = (@sub_total + @shipping + @taxes).round(2)
13
+ end
14
+
15
+ def self.from_hash(hash)
16
+ totals = hash['billing']['totals']
17
+ Invoice.new(hash['orderNumber'],
18
+ totals['subtotal'],
19
+ totals['shipping'],
20
+ totals['totalTax'])
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -52,6 +52,14 @@ module MusicTodayApiWrapper
52
52
  end
53
53
  end
54
54
 
55
+ def purchase(params)
56
+ @common_response.work do
57
+ url = "#{@url}/order/submit"
58
+ @common_response.data[:order] =
59
+ post(url, {}, params)['orders'].first
60
+ end
61
+ end
62
+
55
63
  private
56
64
 
57
65
  def get(url, options = {})
@@ -2,6 +2,7 @@ require 'rest_clients/music_today_rest_client'
2
2
  require 'rest_clients/common_response'
3
3
  require 'resources/purchase/item'
4
4
  require 'resources/checkout/session'
5
+ require 'resources/purchase/invoice'
5
6
 
6
7
  module MusicTodayApiWrapper
7
8
  module Services
@@ -34,6 +35,16 @@ module MusicTodayApiWrapper
34
35
  Resources::Checkout::Session.from_hash(response.data[:session])
35
36
  end
36
37
  end
38
+
39
+ def purchase(order)
40
+ @common_response.work do
41
+ orders = [order.as_hash]
42
+ response = @rest_client.purchase(orders: orders)
43
+ return response unless response.success?
44
+ @common_response.data[:invoice] =
45
+ Resources::Purchase::Invoice.from_hash(response.data[:order])
46
+ end
47
+ end
37
48
  end
38
49
  end
39
50
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: music_today_api_wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 28.01.16.01
4
+ version: '28.02'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pablo Gonzaga
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-01-28 00:00:00.000000000 Z
12
+ date: 2016-02-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -225,6 +225,7 @@ files:
225
225
  - lib/resources/hash.rb
226
226
  - lib/resources/image.rb
227
227
  - lib/resources/product.rb
228
+ - lib/resources/purchase/invoice.rb
228
229
  - lib/resources/purchase/item.rb
229
230
  - lib/resources/purchase/shipping_option.rb
230
231
  - lib/resources/string.rb