paypal-checkout-sdk 1.0.1 → 1.0.2

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.
Files changed (40) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +139 -0
  3. data/Gemfile +3 -0
  4. data/Gemfile.lock +48 -0
  5. data/LICENSE +86 -0
  6. data/README.md +142 -0
  7. data/Rakefile +6 -0
  8. data/gen.yml +6 -0
  9. data/homepage.jpg +0 -0
  10. data/init +0 -0
  11. data/lib/core/version.rb +1 -1
  12. data/paypal-checkout-sdk.gemspec +26 -12
  13. data/samples/authorize_intent_examples/authorize_order.rb +52 -0
  14. data/samples/authorize_intent_examples/capture_order.rb +44 -0
  15. data/samples/authorize_intent_examples/create_order.rb +191 -0
  16. data/samples/authorize_intent_examples/run_all.rb +57 -0
  17. data/samples/capture_intent_examples/capture_order.rb +50 -0
  18. data/samples/capture_intent_examples/create_order.rb +138 -0
  19. data/samples/capture_intent_examples/run_all.rb +58 -0
  20. data/samples/get_order.rb +43 -0
  21. data/samples/patch_order.rb +53 -0
  22. data/samples/paypal_client.rb +40 -0
  23. data/samples/refund_capture.rb +46 -0
  24. metadata +82 -22
  25. data/spec/orders/orders_authorize_spec.rb +0 -18
  26. data/spec/orders/orders_capture_spec.rb +0 -18
  27. data/spec/orders/orders_create_spec.rb +0 -36
  28. data/spec/orders/orders_get_spec.rb +0 -37
  29. data/spec/orders/orders_helper.rb +0 -33
  30. data/spec/orders/orders_patch_spec.rb +0 -60
  31. data/spec/orders/orders_validate_spec.rb +0 -18
  32. data/spec/payments/authorizations_capture_spec.rb +0 -18
  33. data/spec/payments/authorizations_get_spec.rb +0 -18
  34. data/spec/payments/authorizations_reauthorize_spec.rb +0 -17
  35. data/spec/payments/authorizations_void_spec.rb +0 -17
  36. data/spec/payments/captures_get_spec.rb +0 -18
  37. data/spec/payments/captures_refund_spec.rb +0 -18
  38. data/spec/payments/refunds_get_spec.rb +0 -18
  39. data/spec/spec_helper.rb +0 -109
  40. data/spec/test_harness.rb +0 -25
data/homepage.jpg ADDED
Binary file
data/init ADDED
File without changes
data/lib/core/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module PayPal
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -1,13 +1,27 @@
1
- Gem::Specification.new do |s|
2
- s.name = 'paypal-checkout-sdk'
3
- s.version = '1.0.1'
4
- s.date = '2018-02-04'
5
- s.summary = "This repository contains PayPal's Ruby SDK for Checkout REST API"
6
- s.description = "This repository contains PayPal's Ruby SDK for Checkout REST API"
7
- s.authors = ["http://developer.paypal.com"]
8
- s.email = 'dl-paypal-checkout-api@paypal.com'
9
- s.files = Dir.glob ["lib/**/*.{rb}", "spec/**/*", "*.gemspec"]
10
- s.homepage =
11
- 'https://github.com/paypal/Checkout-Ruby-SDK'
12
- s.license = 'MIT'
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'core/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'paypal-checkout-sdk'
7
+ spec.version = PayPal::VERSION
8
+ spec.summary = "This repository contains PayPal's Ruby SDK for Checkout REST API"
9
+ spec.description = "This repository contains PayPal's Ruby SDK for Checkout REST API"
10
+ spec.authors = ["http://developer.paypal.com"]
11
+ spec.email = 'dl-paypal-checkout-api@paypal.com'
12
+ spec.homepage = 'https://github.com/paypal/Checkout-Ruby-SDK'
13
+ spec.license = 'https://github.com/paypal/Checkout-Ruby-SDK/blob/master/LICENSE'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_dependency 'braintreehttp', '~> 0.5'
23
+
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec', '~> 3.0'
26
+ spec.add_development_dependency 'webmock'
13
27
  end
@@ -0,0 +1,52 @@
1
+ require_relative '../paypal_client'
2
+ include PayPalCheckoutSdk::Orders
3
+ module Samples
4
+ module AuthorizeIntentExamples
5
+ class AuthorizeOrder
6
+
7
+ # This function can be used to authorize an approved order.
8
+ def authorize_order (order_id, debug=false)
9
+ request = OrdersAuthorizeRequest::new(order_id)
10
+ request.prefer("return=representation")
11
+ # This request body can be updated with fields as per requirement. Please refer API docs for more info.
12
+ request.request_body({})
13
+ begin
14
+ response = PayPalClient::client::execute(request)
15
+ if debug
16
+ puts "Status Code: #{response.status_code}"
17
+ puts "Status: #{response.result.status}"
18
+ puts "Order ID: #{response.result.id}"
19
+ puts "Authorization ID: #{response.result.purchase_units[0].payments.authorizations[0].id}"
20
+ puts "Intent: #{response.result.intent}"
21
+ puts "Links:"
22
+ for link in response.result.links
23
+ # this could also be called as link.rel or link.href but as method is a reserved keyword for ruby avoid calling link.method
24
+ puts "\t#{link["rel"]}: #{link["href"]}\tCall Type: #{link["method"]}"
25
+ end
26
+ puts "Authorization Links:"
27
+ for link in response.result.purchase_units[0].payments.authorizations[0].links
28
+ # this could also be called as link.rel or link.href but as method is a reserved keyword for ruby avoid calling link.method
29
+ puts "\t#{link["rel"]}: #{link["href"]}\tCall Type: #{link["method"]}"
30
+ end
31
+ puts "Buyer:"
32
+ buyer = response.result.payer
33
+ puts "\tEmail Address: #{buyer.email_address}\n\tName: #{buyer.name.given_name} #{buyer.name.surname}\n\tPhone Number: #{buyer.phone.phone_number.national_number}"
34
+ puts PayPalClient::openstruct_to_hash(response.result).to_json
35
+ end
36
+ return response
37
+ rescue BraintreeHttp::HttpError => ioe
38
+ # Exception occured while processing the refund.
39
+ puts " Status Code: #{ioe.status_code}"
40
+ puts " Debug Id: #{ioe.result.debug_id}"
41
+ puts " Response: #{ioe.result}"
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ # This is the driver function which invokes the authorize_order function with approved order id
49
+ # Order Id should be replaced with an valid approved order id.
50
+ if __FILE__ == $0
51
+ Samples::AuthorizeIntentExamples::AuthorizeOrder::new::authorize_order('0CT41921GV4167455',true)
52
+ end
@@ -0,0 +1,44 @@
1
+ require_relative '../paypal_client'
2
+ include PayPalCheckoutSdk::Payments
3
+ module Samples
4
+ module AuthorizeIntentExamples
5
+ class CaptureOrder
6
+
7
+ # This function can be used to perform capture on an authorization.
8
+ # An valid authorization id dhould be passed as an argument.
9
+ def capture_order (authorization_id, debug=false)
10
+ request = AuthorizationsCaptureRequest::new(authorization_id)
11
+ request.prefer("return=representation")
12
+ #Below request bodyn can be updated with fields as per business need. Please refer API docs for more info.
13
+ request.request_body({})
14
+ begin
15
+ response = PayPalClient::client::execute(request)
16
+ if debug
17
+ puts "Status Code: #{response.status_code}"
18
+ puts "Status: #{response.result.status}"
19
+ puts "Order ID: #{response.result.id}"
20
+ puts "Intent: #{response.result.intent}"
21
+ puts "Links:"
22
+ for link in response.result.links
23
+ # this could also be called as link.rel or link.href but as method is a reserved keyword for ruby avoid calling link.method
24
+ puts "\t#{link["rel"]}: #{link["href"]}\tCall Type: #{link["method"]}"
25
+ end
26
+ puts PayPalClient::openstruct_to_hash(response.result).to_json
27
+ end
28
+ return response
29
+ rescue BraintreeHttp::HttpError => ioe
30
+ # Exception occured while processing the refund.
31
+ puts " Status Code: #{ioe.status_code}"
32
+ puts " Debug Id: #{ioe.result.debug_id}"
33
+ puts " Response: #{ioe.result}"
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ # This is the driver function which invokes the capture_order function with valid authorization id
41
+ # Authorization Id should be replaced with an valid authorization id.
42
+ if __FILE__ == $0
43
+ Samples::AuthorizeIntentExamples::CaptureOrder::new::capture_order('4KH16819Y83216409',true)
44
+ end
@@ -0,0 +1,191 @@
1
+ require_relative '../paypal_client'
2
+ require 'json'
3
+ include PayPalCheckoutSdk::Orders
4
+
5
+ module Samples
6
+ module AuthorizeIntentExamples
7
+ class CreateOrder
8
+
9
+ # This is the sample function which can be used to create an order with complete body.
10
+ # The Intent in the request body should be set as "AUTHORIZE" for authorize intent flow.
11
+ def create_order (debug=false)
12
+ body = {
13
+ intent: 'AUTHORIZE',
14
+ application_context: {
15
+ return_url: 'https://www.example.com',
16
+ cancel_url: 'https://www.example.com',
17
+ brand_name: 'EXAMPLE INC',
18
+ landing_page: 'BILLING',
19
+ shipping_preference: 'SET_PROVIDED_ADDRESS',
20
+ user_action: 'CONTINUE'
21
+ },
22
+ purchase_units: [
23
+ {
24
+ reference_id: 'PUHF',
25
+ description: 'Sporting Goods',
26
+
27
+ custom_id: 'CUST-HighFashions',
28
+ soft_descriptor: 'HighFashions',
29
+ amount: {
30
+ currency_code: 'USD',
31
+ value: '220.00',
32
+ breakdown: {
33
+ item_total: {
34
+ currency_code: 'USD',
35
+ value: '180.00'
36
+ },
37
+ shipping: {
38
+ currency_code: 'USD',
39
+ value: '20.00'
40
+ },
41
+ handling: {
42
+ currency_code: 'USD',
43
+ value: '10.00'
44
+ },
45
+ tax_total: {
46
+ currency_code: 'USD',
47
+ value: '20.00'
48
+ },
49
+ gift_wrap: {
50
+ currency_code: 'USD',
51
+ value: '10.00'
52
+ },
53
+ shipping_discount: {
54
+ currency_code: 'USD',
55
+ value: '10'
56
+ }
57
+ }
58
+ },
59
+ items: [
60
+ {
61
+ name: 'T-Shirt',
62
+ description: 'Green XL',
63
+ sku: 'sku01',
64
+ unit_amount: {
65
+ currency_code: 'USD',
66
+ value: '90.00'
67
+ },
68
+ tax: {
69
+ currency_code: 'USD',
70
+ value: '10.00'
71
+ },
72
+ quantity: '1',
73
+ category: 'PHYSICAL_GOODS'
74
+ },
75
+ {
76
+ name: 'Shoes',
77
+ description: 'Running, Size 10.5',
78
+ sku: 'sku02',
79
+ unit_amount: {
80
+ currency_code: 'USD',
81
+ value: '45.00'
82
+ },
83
+ tax: {
84
+ currency_code: 'USD',
85
+ value: '5.00'
86
+ },
87
+ quantity: '2',
88
+ category: 'PHYSICAL_GOODS'
89
+ }
90
+ ],
91
+ shipping: {
92
+ method: 'United States Postal Service',
93
+ name: {
94
+ full_name: 'John Doe'
95
+ },
96
+ address: {
97
+ address_line_1: '123 Townsend St',
98
+ address_line_2: 'Floor 6',
99
+ admin_area_2: 'San Francisco',
100
+ admin_area_1: 'CA',
101
+ postal_code: '94107',
102
+ country_code: 'US'
103
+ }
104
+ }
105
+ }
106
+ ]
107
+ }
108
+
109
+ request = OrdersCreateRequest::new
110
+ request.headers["prefer"] = "return=representation"
111
+ request.request_body(body)
112
+ begin
113
+ response = PayPalClient::client.execute(request)
114
+ if debug
115
+ puts "Order with the complete required payload"
116
+ puts "Status Code: #{response.status_code}"
117
+ puts "Status: #{response.result.status}"
118
+ puts "Order ID: #{response.result.id}"
119
+ puts "Intent: #{response.result.intent}"
120
+ puts "Links:"
121
+ for link in response.result.links
122
+ # this could also be called as link.rel or link.href but as method is a reserved keyword for ruby avoid calling link.method
123
+ puts "\t#{link["rel"]}: #{link["href"]}\tCall Type: #{link["method"]}"
124
+ end
125
+ puts "Gross Amount: #{response.result.purchase_units[0].amount.currency_code} #{response.result.purchase_units[0].amount.value}"
126
+ puts PayPalClient::openstruct_to_hash(response.result).to_json
127
+ end
128
+ return response
129
+ rescue BraintreeHttp::HttpError => ioe
130
+ # Exception occured while processing the refund.
131
+ puts " Status Code: #{ioe.status_code}"
132
+ puts " Debug Id: #{ioe.result.debug_id}"
133
+ puts " Response: #{ioe.result}"
134
+ end
135
+ end
136
+
137
+ # This is the sample function which can be used to create an order with minimum required body.
138
+ # The Intent in the request body should be set as "AUTHORIZE" for authorize intent flow.
139
+ def create_order_with_minimum_body (debug=false)
140
+ body = {
141
+ intent: 'AUTHORIZE',
142
+ application_context: {
143
+ return_url: 'https://www.example.com',
144
+ cancel_url: 'https://www.example.com'
145
+ },
146
+ purchase_units: [
147
+ {
148
+ amount: {
149
+ currency_code: 'USD',
150
+ value: '220.00'
151
+ }
152
+ }
153
+ ]
154
+ }
155
+
156
+ request = OrdersCreateRequest::new
157
+ request.headers["prefer"] = "return=representation"
158
+ request.request_body(body)
159
+ begin
160
+ response = PayPalClient::client.execute(request)
161
+ if debug
162
+ puts "Order with the minimum required payload"
163
+ puts "Status Code: #{response.status_code}"
164
+ puts "Status: #{response.result.status}"
165
+ puts "Order ID: #{response.result.id}"
166
+ puts "Intent: #{response.result.intent}"
167
+ puts "Links:"
168
+ for link in response.result.links
169
+ # this could also be called as link.rel or link.href but as method is a reserved keyword for ruby avoid calling link.method
170
+ puts "\t#{link["rel"]}: #{link["href"]}\tCall Type: #{link["method"]}"
171
+ end
172
+ puts "Gross Amount: #{response.result.purchase_units[0].amount.currency_code} #{response.result.purchase_units[0].amount.value}"
173
+ puts PayPalClient::openstruct_to_hash(response.result).to_json
174
+ end
175
+ return response
176
+ rescue BraintreeHttp::HttpError => ioe
177
+ # Exception occured while processing the refund.
178
+ puts " Status Code: #{ioe.status_code}"
179
+ puts " Debug Id: #{ioe.result.debug_id}"
180
+ puts " Response: #{ioe.result}"
181
+ end
182
+ end
183
+ end
184
+ end
185
+ end
186
+
187
+ # This is the driver function which invokes the createOrder function to create an sample order.
188
+ if __FILE__ == $0
189
+ Samples::AuthorizeIntentExamples::CreateOrder::new::create_order(true)
190
+ Samples::AuthorizeIntentExamples::CreateOrder::new::create_order_with_minimum_body(true)
191
+ end
@@ -0,0 +1,57 @@
1
+ require_relative '../paypal_client'
2
+ require_relative './create_order'
3
+ require_relative './authorize_order'
4
+ require_relative './capture_order'
5
+ require_relative '../refund_capture'
6
+ include BraintreeHttp
7
+
8
+ puts "Creating Order..."
9
+ create_resp = Samples::AuthorizeIntentExamples::CreateOrder::new::create_order
10
+ for link in create_resp.result.links
11
+ # this could also be called as link.rel or link.href but as method is a reserved keyword for ruby avoid calling link.method
12
+ puts "\t#{link["rel"]}: #{link["href"]}\tCall Type: #{link["method"]}"
13
+ end
14
+ puts "Created Successfully\n"
15
+ puts "Copy approve link and paste it in browser. Login with buyer account and follow the instructions.\nOnce approved hit enter..."
16
+
17
+ # Waiting for user input
18
+ gets
19
+
20
+ puts "Authorizing Order..."
21
+ authorize_resp = Samples::AuthorizeIntentExamples::AuthorizeOrder::new::authorize_order(create_resp.result.id)
22
+ authorization_id = authorize_resp.result.purchase_units[0].payments.authorizations[0].id
23
+ puts "Authorized Successfully"
24
+
25
+ puts "Capturing Order..."
26
+ capture_resp = Samples::AuthorizeIntentExamples::CaptureOrder::new::capture_order(authorization_id)
27
+ puts "Captured Successfully\n"
28
+ puts "Status Code: #{capture_resp.status_code}"
29
+ puts "Status: #{capture_resp.result.status}"
30
+ puts "Capture ID: #{capture_resp.result.id}"
31
+ puts "Intent: #{capture_resp.result.intent}"
32
+ puts "Links:"
33
+ for link in capture_resp.result.links
34
+ # this could also be called as link.rel or link.href but as method is a reserved keyword for ruby avoid calling link.method
35
+ puts "\t#{link["rel"]}: #{link["href"]}\tCall Type: #{link["method"]}"
36
+ end
37
+
38
+ puts "Refunding Capture..."
39
+ begin
40
+ refund_response = Samples::RefundCapture::new::refund_capture(capture_resp.result.id)
41
+ puts "Refunded SuccessFully\n"
42
+ puts "Status Code: #{refund_response.status_code}"
43
+ puts "Status: #{refund_response.result.status}"
44
+ puts "Refund ID: #{refund_response.result.id}"
45
+ puts "Intent: #{refund_response.result.intent}"
46
+ puts "Links:"
47
+ for link in refund_response.result.links
48
+ # this could also be called as link.rel or link.href but as method is a reserved keyword for ruby avoid calling link.method
49
+ puts "\t#{link["rel"]}: #{link["href"]}\tCall Type: #{link["method"]}"
50
+ end
51
+ rescue => e
52
+ puts e.message
53
+ if e.is_a? HttpError
54
+ puts e.status_code
55
+ puts e.result
56
+ end
57
+ end
@@ -0,0 +1,50 @@
1
+ require_relative '../paypal_client' #PayPal SDK dependency
2
+ include PayPalCheckoutSdk::Orders
3
+ module Samples
4
+ module CaptureIntentExamples
5
+ class CaptureOrder
6
+
7
+ # This is the sample function performing payment capture on the order.
8
+ # Approved Order id should be passed as an argument to this function
9
+ def capture_order (order_id, debug=false)
10
+ request = OrdersCaptureRequest::new(order_id)
11
+ request.prefer("return=representation")
12
+ begin
13
+ response = PayPalClient::client.execute(request)
14
+ if debug
15
+ puts "Status Code: #{response.status_code}"
16
+ puts "Status: #{response.result.status}"
17
+ puts "Order ID: #{response.result.id}"
18
+ puts "Intent: #{response.result.intent}"
19
+ puts "Links:"
20
+ for link in response.result.links
21
+ # this could also be called as link.rel or link.href but as method is a reserved keyword for ruby avoid calling link.method
22
+ puts "\t#{link["rel"]}: #{link["href"]}\tCall Type: #{link["method"]}"
23
+ end
24
+ puts "Capture Ids: "
25
+ for purchase_unit in response.result.purchase_units
26
+ for capture in purchase_unit.payments.captures
27
+ puts "\t #{capture.id}"
28
+ end
29
+ end
30
+ puts "Buyer:"
31
+ buyer = response.result.payer
32
+ puts "\tEmail Address: #{buyer.email_address}\n\tName: #{buyer.name.full_name}\n\tPhone Number: #{buyer.phone.phone_number.national_number}"
33
+ puts PayPalClient::openstruct_to_hash(response.result).to_json
34
+ end
35
+ return response
36
+ rescue BraintreeHttp::HttpError => ioe
37
+ # Exception occured while processing the refund.
38
+ puts " Status Code: #{ioe.status_code}"
39
+ puts " Debug Id: #{ioe.result.debug_id}"
40
+ puts " Response: #{ioe.result}"
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ # This is the driver function which invokes the capture order function.
47
+ # Order Id value should be replaced with the approved order id.
48
+ if __FILE__ == $0
49
+ Samples::CaptureIntentExamples::CaptureOrder::new::capture_order('4BH32103UX0864942', true)
50
+ end