spree_paypal_api_checkout 0.0.9 → 0.1.0
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
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 53c335900fbbe782e6fc7cfa78b36f258b514a9d9b9400cef65f7fb8c7cf69c7
|
|
4
|
+
data.tar.gz: 946f4fa867ded14d6c7f494df8d8e21377721b682df09fe7cffd312540268540
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0d1754cdff574bb9bbe6b798663c02686228ec3a0e7fe30281b87dea2264245d2f296e849ad44145282305766678b5956834a8a44f0ed17c38e6a644abeb0719
|
|
7
|
+
data.tar.gz: aef76e65dae6694919ddc17f3c290de2a49be957ac913a9a0ba4863bfe0f1a576d7a10c7e7fcce1a658e087c1b48786514f21c329354094024a124b961986801
|
data/README.md
CHANGED
|
@@ -8,13 +8,14 @@ module Spree
|
|
|
8
8
|
additional_adjustments = order.all_adjustments.additional
|
|
9
9
|
tax_adjustments = additional_adjustments.tax
|
|
10
10
|
shipping_adjustments = additional_adjustments.shipping
|
|
11
|
+
promotion_adjustments = additional_adjustments.promotion
|
|
11
12
|
|
|
12
13
|
additional_adjustments.eligible.each do |adjustment|
|
|
13
14
|
# Because PayPal doesn't accept $0 items at all. See #10
|
|
14
15
|
# https://cms.paypal.com/uk/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_ECCustomizing
|
|
15
16
|
# "It can be a positive or negative value but not zero."
|
|
16
17
|
next if adjustment.amount.zero?
|
|
17
|
-
next if tax_adjustments.include?(adjustment) || shipping_adjustments.include?(adjustment)
|
|
18
|
+
next if tax_adjustments.include?(adjustment) || shipping_adjustments.include?(adjustment) || promotion_adjustments.include?(adjustment)
|
|
18
19
|
|
|
19
20
|
items << {
|
|
20
21
|
name: adjustment.label,
|
|
@@ -26,7 +27,7 @@ module Spree
|
|
|
26
27
|
}
|
|
27
28
|
end
|
|
28
29
|
|
|
29
|
-
pp_response = provider.create_order(order, express_checkout_request_details(order, items))
|
|
30
|
+
pp_response = provider.create_order(order, express_checkout_request_details(order: order, items: items, tax_adjustments: tax_adjustments, promotion_adjustments: promotion_adjustments))
|
|
30
31
|
|
|
31
32
|
render json: pp_response
|
|
32
33
|
end
|
|
@@ -48,6 +49,7 @@ module Spree
|
|
|
48
49
|
def proceed
|
|
49
50
|
order = current_order || raise(ActiveRecord::RecordNotFound)
|
|
50
51
|
order.payments.last.source.update(transaction_id: params[:transaction_id])
|
|
52
|
+
order.payments.last.update(response_code: params[:transaction_id])
|
|
51
53
|
order.next
|
|
52
54
|
path = checkout_state_path(order.state)
|
|
53
55
|
if order.complete?
|
|
@@ -81,7 +83,7 @@ module Spree
|
|
|
81
83
|
}
|
|
82
84
|
end
|
|
83
85
|
|
|
84
|
-
def express_checkout_request_details order
|
|
86
|
+
def express_checkout_request_details order:, items:, tax_adjustments:, promotion_adjustments:
|
|
85
87
|
{
|
|
86
88
|
intent: 'CAPTURE',
|
|
87
89
|
purchase_units: [
|
|
@@ -93,6 +95,18 @@ module Spree
|
|
|
93
95
|
item_total: {
|
|
94
96
|
currency_code: current_order.currency,
|
|
95
97
|
value: items.sum{|r| (r[:unit_amount][:value] * r[:quantity]) }
|
|
98
|
+
},
|
|
99
|
+
shipping: {
|
|
100
|
+
currency_code: current_order.currency,
|
|
101
|
+
value: current_order.shipments.sum(:cost)
|
|
102
|
+
},
|
|
103
|
+
tax_total: {
|
|
104
|
+
currency_code: current_order.currency,
|
|
105
|
+
value: tax_adjustments.sum(:amount)
|
|
106
|
+
},
|
|
107
|
+
discount: {
|
|
108
|
+
currency_code: current_order.currency,
|
|
109
|
+
value: promotion_adjustments.sum(:amount).abs
|
|
96
110
|
}
|
|
97
111
|
}
|
|
98
112
|
},
|
|
@@ -20,28 +20,14 @@ module Spree
|
|
|
20
20
|
'paypal_checkout'
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
def generate_client_token
|
|
24
|
-
uri = URI.parse("https://#{preferred_server}/v1/identity/generate-token")
|
|
25
|
-
request = Net::HTTP::Post.new(uri)
|
|
26
|
-
request['Authorization'] = "Bearer #{generate_access_token}"
|
|
27
|
-
request.content_type = "application/json"
|
|
28
|
-
|
|
29
|
-
req_options = { use_ssl: uri.scheme == "https" }
|
|
30
|
-
|
|
31
|
-
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
|
32
|
-
response = http.request(request)
|
|
33
|
-
end
|
|
34
|
-
return response
|
|
35
|
-
end
|
|
36
|
-
|
|
37
23
|
def generate_access_token
|
|
38
24
|
uri = URI.parse("https://#{preferred_server}/v1/oauth2/token")
|
|
39
25
|
request = Net::HTTP::Post.new(uri)
|
|
40
26
|
request.basic_auth("#{preferred_api_key}", "#{preferred_secret_key}")
|
|
41
|
-
request.content_type =
|
|
42
|
-
request.body =
|
|
27
|
+
request.content_type = 'application/json'
|
|
28
|
+
request.body = 'grant_type=client_credentials'
|
|
43
29
|
|
|
44
|
-
req_options = { use_ssl: uri.scheme ==
|
|
30
|
+
req_options = { use_ssl: uri.scheme == 'https' }
|
|
45
31
|
|
|
46
32
|
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
|
47
33
|
response = http.request(request)
|
|
@@ -49,46 +35,24 @@ module Spree
|
|
|
49
35
|
return JSON.parse(response.read_body)['access_token']
|
|
50
36
|
end
|
|
51
37
|
|
|
38
|
+
def generate_client_token
|
|
39
|
+
uri = URI.parse("https://#{preferred_server}/v1/identity/generate-token")
|
|
40
|
+
return post_response(uri)
|
|
41
|
+
end
|
|
42
|
+
|
|
52
43
|
def create_order order, body
|
|
53
44
|
uri = URI.parse("https://#{preferred_server}/v2/checkout/orders")
|
|
54
|
-
|
|
55
|
-
request['Authorization'] = "Bearer #{generate_access_token}"
|
|
56
|
-
request.content_type = "application/json"
|
|
57
|
-
|
|
58
|
-
request.body = body.to_json
|
|
59
|
-
req_options = { use_ssl: uri.scheme == "https" }
|
|
60
|
-
|
|
61
|
-
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
|
62
|
-
response = http.request(request)
|
|
63
|
-
end
|
|
64
|
-
return JSON.parse(response.read_body)
|
|
45
|
+
return post_response(uri, body)
|
|
65
46
|
end
|
|
66
47
|
|
|
67
48
|
def capture_payment order_id
|
|
68
49
|
uri = URI.parse("https://#{preferred_server}/v2/checkout/orders/#{order_id}/capture")
|
|
69
|
-
|
|
70
|
-
request['Authorization'] = "Bearer #{generate_access_token}"
|
|
71
|
-
request.content_type = "application/json"
|
|
72
|
-
req_options = { use_ssl: uri.scheme == "https" }
|
|
73
|
-
|
|
74
|
-
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
|
75
|
-
response = http.request(request)
|
|
76
|
-
end
|
|
77
|
-
return JSON.parse(response.read_body)
|
|
50
|
+
return post_response(uri)
|
|
78
51
|
end
|
|
79
52
|
|
|
80
53
|
def refund_payment id, body
|
|
81
54
|
uri = URI.parse("https://#{preferred_server}/v2/payments/captures/#{id}/refund")
|
|
82
|
-
|
|
83
|
-
request['Authorization'] = "Bearer #{generate_access_token}"
|
|
84
|
-
request.body = body.to_json
|
|
85
|
-
request.content_type = "application/json"
|
|
86
|
-
req_options = { use_ssl: uri.scheme == "https" }
|
|
87
|
-
|
|
88
|
-
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
|
89
|
-
response = http.request(request)
|
|
90
|
-
end
|
|
91
|
-
return JSON.parse(response.read_body)
|
|
55
|
+
return post_response(uri, body)
|
|
92
56
|
end
|
|
93
57
|
|
|
94
58
|
def purchase(amount, express_checkout, gateway_options={})
|
|
@@ -134,6 +98,19 @@ module Spree
|
|
|
134
98
|
end
|
|
135
99
|
refund_transaction_response
|
|
136
100
|
end
|
|
101
|
+
|
|
102
|
+
def post_response uri, body={}
|
|
103
|
+
request = Net::HTTP::Post.new(uri)
|
|
104
|
+
request['Authorization'] = "Bearer #{generate_access_token}"
|
|
105
|
+
request.content_type = 'application/json'
|
|
106
|
+
req_options = { use_ssl: uri.scheme == 'https' }
|
|
107
|
+
|
|
108
|
+
request.body = body.to_json if body.present?
|
|
109
|
+
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
|
110
|
+
response = http.request(request)
|
|
111
|
+
end
|
|
112
|
+
return JSON.parse(response.read_body)
|
|
113
|
+
end
|
|
137
114
|
end
|
|
138
115
|
end
|
|
139
116
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Gem::Specification.new do |s|
|
|
2
2
|
s.name = "spree_paypal_api_checkout".freeze
|
|
3
|
-
s.version = "0.0
|
|
3
|
+
s.version = "0.1.0"
|
|
4
4
|
|
|
5
5
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
|
6
6
|
s.require_paths = ["lib".freeze]
|