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
@@ -0,0 +1,138 @@
1
+ require_relative '../paypal_client'
2
+ include PayPalCheckoutSdk::Orders
3
+
4
+ module Samples
5
+ module CaptureIntentExamples
6
+ class CreateOrder
7
+
8
+ # This is the sample function which can be used to create an order. It uses the
9
+ # sample JSON body to create an new Order.
10
+ # The Intent in the request body should be set as "CAPTURE" for capture intent flow.
11
+ def create_order (debug=false)
12
+ body = {
13
+ intent: 'CAPTURE',
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
+ shipping_discount: {
50
+ currency_code: 'USD',
51
+ value: '10'
52
+ }
53
+ }
54
+ },
55
+ items: [
56
+ {
57
+ name: 'T-Shirt',
58
+ description: 'Green XL',
59
+ sku: 'sku01',
60
+ unit_amount: {
61
+ currency_code: 'USD',
62
+ value: '90.00'
63
+ },
64
+ tax: {
65
+ currency_code: 'USD',
66
+ value: '10.00'
67
+ },
68
+ quantity: '1',
69
+ category: 'PHYSICAL_GOODS'
70
+ },
71
+ {
72
+ name: 'Shoes',
73
+ description: 'Running, Size 10.5',
74
+ sku: 'sku02',
75
+ unit_amount: {
76
+ currency_code: 'USD',
77
+ value: '45.00'
78
+ },
79
+ tax: {
80
+ currency_code: 'USD',
81
+ value: '5.00'
82
+ },
83
+ quantity: '2',
84
+ category: 'PHYSICAL_GOODS'
85
+ }
86
+ ],
87
+ shipping: {
88
+ method: 'United States Postal Service',
89
+ name: {
90
+ full_name: 'John Doe'
91
+ },
92
+ address: {
93
+ address_line_1: '123 Townsend St',
94
+ address_line_2: 'Floor 6',
95
+ admin_area_2: 'San Francisco',
96
+ admin_area_1: 'CA',
97
+ postal_code: '94107',
98
+ country_code: 'US'
99
+ }
100
+ }
101
+ }
102
+ ]
103
+ }
104
+
105
+ request = OrdersCreateRequest::new
106
+ request.headers["prefer"] = "return=representation"
107
+ request.request_body(body)
108
+ begin
109
+ response = PayPalClient::client.execute(request)
110
+ if debug
111
+ puts "Status Code: #{response.status_code}"
112
+ puts "Status: #{response.result.status}"
113
+ puts "Order ID: #{response.result.id}"
114
+ puts "Intent: #{response.result.intent}"
115
+ puts "Links:"
116
+ for link in response.result.links
117
+ # this could also be called as link.rel or link.href but as method is a reserved keyword for ruby avoid calling link.method
118
+ puts "\t#{link["rel"]}: #{link["href"]}\tCall Type: #{link["method"]}"
119
+ end
120
+ puts "Gross Amount: #{response.result.purchase_units[0].amount.currency_code} #{response.result.purchase_units[0].amount.value}"
121
+ puts PayPalClient::openstruct_to_hash(response.result).to_json
122
+ end
123
+ return response
124
+ rescue BraintreeHttp::HttpError => ioe
125
+ # Exception occured while processing the refund.
126
+ puts " Status Code: #{ioe.status_code}"
127
+ puts " Debug Id: #{ioe.result.debug_id}"
128
+ puts " Response: #{ioe.result}"
129
+ end
130
+ end
131
+ end
132
+ end
133
+ end
134
+
135
+ # This is the driver function which invokes the createOrder function to create an sample order.
136
+ if __FILE__ == $0
137
+ Samples::CaptureIntentExamples::CreateOrder::new::create_order(true)
138
+ end
@@ -0,0 +1,58 @@
1
+ require_relative '../capture_intent_examples/create_order'
2
+ require_relative '../capture_intent_examples/capture_order'
3
+ require_relative '../refund_capture'
4
+ include BraintreeHttp
5
+
6
+ puts "Creating Order..."
7
+ create_resp = Samples::CaptureIntentExamples::CreateOrder::new::create_order
8
+ for link in create_resp.result.links
9
+ # this could also be called as link.rel or link.href but as method is a reserved keyword for ruby avoid calling link.method
10
+ puts "\t#{link["rel"]}: #{link["href"]}\tCall Type: #{link["method"]}"
11
+ end
12
+ puts "Created Successfully\n"
13
+ puts "Copy approve link and paste it in browser. Login with buyer account and follow the instructions.\nOnce approved hit enter..."
14
+
15
+ # Waiting for user input
16
+ gets
17
+
18
+ puts "Capturing Order..."
19
+ begin
20
+ capture_resp = Samples::CaptureIntentExamples::CaptureOrder::new.capture_order(create_resp.result.id)
21
+ puts "Captured Successfully\n"
22
+ puts "Status Code: #{capture_resp.status_code}"
23
+ puts "Status: #{capture_resp.result.status}"
24
+ puts "Order ID: #{capture_resp.result.id}"
25
+ puts "Intent: #{capture_resp.result.intent}"
26
+ puts "Links:"
27
+ for link in capture_resp.result.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
+ rescue => e
32
+ if e.is_a? HttpError
33
+ puts e.message
34
+ puts e.status_code
35
+ puts e.result
36
+ end
37
+ end
38
+
39
+ puts "Refunding Capture..."
40
+ begin
41
+ refund_response = Samples::RefundCapture::new::refund_capture(capture_resp.result.purchase_units[0].payments.captures[0].id)
42
+ puts "Refunded SuccessFully\n"
43
+ puts "Status Code: #{refund_response.status_code}"
44
+ puts "Status: #{refund_response.result.status}"
45
+ puts "Refund ID: #{refund_response.result.id}"
46
+ puts "Intent: #{refund_response.result.intent}"
47
+ puts "Links:"
48
+ for link in refund_response.result.links
49
+ # this could also be called as link.rel or link.href but as method is a reserved keyword for ruby avoid calling link.method
50
+ puts "\t#{link["rel"]}: #{link["href"]}\tCall Type: #{link["method"]}"
51
+ end
52
+ rescue => e
53
+ puts e.message
54
+ if e.is_a? HttpError
55
+ puts e.status_code
56
+ puts e.result
57
+ end
58
+ end
@@ -0,0 +1,43 @@
1
+ require_relative './paypal_client'
2
+ require_relative './authorize_intent_examples/create_order'
3
+ require 'json'
4
+ require 'ostruct'
5
+
6
+ include PayPalCheckoutSdk::Orders
7
+ module Samples
8
+ class GetOrder
9
+
10
+ # This function can be used to retrieve an order by passing order id as argument
11
+ def get_order(order_id)
12
+ request = OrdersGetRequest::new(order_id)
13
+ begin
14
+ response = PayPalClient::client::execute(request)
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 "Gross Amount: #{response.result.purchase_units[0].amount.currency_code} #{response.result.purchase_units[0].amount.value}"
25
+ puts PayPalClient::openstruct_to_hash(response.result).to_json
26
+ return response
27
+ rescue BraintreeHttp::HttpError => ioe
28
+ # Exception occured while processing the refund.
29
+ puts " Status Code: #{ioe.status_code}"
30
+ puts " Debug Id: #{ioe.result.debug_id}"
31
+ puts " Response: #{ioe.result}"
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ # This is the driver function which invokes the get_order function with order id to retrieve
38
+ # an sample order. For the order id, we invoke the create order to create an new order and then we are using
39
+ # the newly created order id for retrieving the order
40
+ if __FILE__ == $0
41
+ id = Samples::AuthorizeIntentExamples::CreateOrder::new::create_order.result.id;
42
+ Samples::GetOrder::new::get_order(id)
43
+ end
@@ -0,0 +1,53 @@
1
+ require_relative './paypal_client'
2
+ require_relative './capture_intent_examples/create_order'
3
+ require_relative './get_order'
4
+
5
+ include PayPalCheckoutSdk::Orders
6
+
7
+ module Samples
8
+ class PatchOrder
9
+ # Below function can be used to patch and order.
10
+ # Patch is supported on only specific set of fields.
11
+ # Please refer API docs for more info.
12
+ def patch_order(order_id)
13
+ body = [{
14
+ op:'replace',
15
+ path:"/purchase_units/@reference_id=='PUHF'/description",
16
+ value:'Sporting goods description'
17
+ },
18
+ {
19
+ op: 'replace',
20
+ path: "/purchase_units/@reference_id=='PUHF'/custom_id",
21
+ value: 'CUST-ID-HighFashions'
22
+ }
23
+ ]
24
+ request = OrdersPatchRequest::new(order_id)
25
+ request.request_body(body)
26
+ response = PayPalClient::client::execute(request)
27
+ return response
28
+ end
29
+ end
30
+ end
31
+
32
+ # Driver function which does below steps.
33
+ # 1. Create an Order
34
+ # 2. Patch fields in the newly created order.
35
+ # 3. Print the updated fields by calling the get order.
36
+ if __FILE__ == $0
37
+ begin
38
+ order= Samples::CaptureIntentExamples::CreateOrder::new::create_order.result
39
+ patch_response = Samples::PatchOrder::new::patch_order(order.id)
40
+ puts "patch_response status code ::: #{patch_response.status_code}"
41
+ if patch_response.status_code == 204
42
+ order = Samples::GetOrder::new::get_order(order.id)
43
+ puts "Updated Description: #{order.result.purchase_units[0].description}"
44
+ puts "Updated Custom Id: #{order.result.purchase_units[0].custom_id}"
45
+ puts PayPalClient::openstruct_to_hash(order.result).to_json
46
+ end
47
+ rescue BraintreeHttp::HttpError => ioe
48
+ # Exception occured while processing the refund.
49
+ puts " Status Code: #{ioe.status_code}"
50
+ puts " Debug Id: #{ioe.result.debug_id}"
51
+ puts " Response: #{ioe.result}"
52
+ end
53
+ end
@@ -0,0 +1,40 @@
1
+ require './lib/paypal-checkout-sdk'
2
+
3
+ module PayPalClient
4
+ class << self
5
+
6
+ # Setting up and Returns PayPal SDK environment with PayPal Access credentials.
7
+ # For demo purpose, we are using SandboxEnvironment. In production this will be
8
+ # LiveEnvironment.
9
+ def environment
10
+ client_id = ENV['PAYPAL_CLIENT_ID'] || '<<PAYPAL-CLIENT-ID>>'
11
+ client_secret = ENV['PAYPAL_CLIENT_SECRET'] || '<<PAYPAL-CLIENT-SECRET>>'
12
+
13
+ PayPal::SandboxEnvironment.new(client_id, client_secret)
14
+ end
15
+
16
+ # Returns PayPal HTTP client instance with environment which has access
17
+ # credentials context. This can be used invoke PayPal API's provided the
18
+ # credentials have the access to do so.
19
+ def client
20
+ PayPal::PayPalHttpClient.new(self.environment)
21
+ end
22
+
23
+ # Utility to convert Openstruct Object to JSON hash.
24
+ def openstruct_to_hash(object, hash = {})
25
+ object.each_pair do |key, value|
26
+ hash[key] = value.is_a?(OpenStruct) ? openstruct_to_hash(value) : value.is_a?(Array) ? array_to_hash(value) : value
27
+ end
28
+ hash
29
+ end
30
+
31
+ # Utility to convert Array of OpenStruct into Hash.
32
+ def array_to_hash(array, hash= [])
33
+ array.each do |item|
34
+ x = item.is_a?(OpenStruct) ? openstruct_to_hash(item) : item.is_a?(Array) ? array_to_hash(item) : item
35
+ hash << x
36
+ end
37
+ hash
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,46 @@
1
+ require_relative './paypal_client' #PayPal SDK dependency
2
+ include PayPalCheckoutSdk::Payments
3
+ module Samples
4
+ class RefundCapture
5
+
6
+ # This is the sample function performing capture refund.
7
+ # Valid capture id should be passed as an argument to this function
8
+ def refund_capture (capture_id, debug=false)
9
+ request = CapturesRefundRequest::new(capture_id)
10
+ request.prefer("return=representation")
11
+ # below request body can be populated to perform partial refund.
12
+ request.request_body({
13
+ amount: {
14
+ value: '20.00',
15
+ currency_code: 'USD'
16
+ }
17
+ });
18
+ begin
19
+ response = PayPalClient::client::execute(request)
20
+ if debug
21
+ puts "Status Code: #{response.status_code}"
22
+ puts "Status: #{response.result.status}"
23
+ puts "Refund ID: #{response.result.id}"
24
+ puts "Intent: #{response.result.intent}"
25
+ puts "Links:"
26
+ for link in response.result.links
27
+ # this could also be called as link.rel or link.href but as method is a reserved keyword for ruby avoid calling link.method
28
+ puts "\t#{link["rel"]}: #{link["href"]}\tCall Type: #{link["method"]}"
29
+ end
30
+ puts PayPalClient::openstruct_to_hash(response.result).to_json
31
+ end
32
+ rescue BraintreeHttp::HttpError => ioe
33
+ # Exception occured while processing the refund.
34
+ puts " Status Code: #{ioe.status_code}"
35
+ puts " Debug Id: #{ioe.result.debug_id}"
36
+ puts " Response: #{ioe.result}"
37
+ end
38
+ return response
39
+ end
40
+ end
41
+ end
42
+ # This is the driver function which invokes the refund capture function.
43
+ # Capture Id value should be replaced with the capture id.
44
+ if __FILE__ == $0
45
+ Samples::RefundCapture::new::refund_capture('2WB02631FY659550C', true)
46
+ end
metadata CHANGED
@@ -1,21 +1,86 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paypal-checkout-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - http://developer.paypal.com
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2018-02-04 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2019-03-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: braintreehttp
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
13
69
  description: This repository contains PayPal's Ruby SDK for Checkout REST API
14
70
  email: dl-paypal-checkout-api@paypal.com
15
71
  executables: []
16
72
  extensions: []
17
73
  extra_rdoc_files: []
18
74
  files:
75
+ - ".gitignore"
76
+ - Gemfile
77
+ - Gemfile.lock
78
+ - LICENSE
79
+ - README.md
80
+ - Rakefile
81
+ - gen.yml
82
+ - homepage.jpg
83
+ - init
19
84
  - lib/core/access_token.rb
20
85
  - lib/core/paypal_environment.rb
21
86
  - lib/core/paypal_http_client.rb
@@ -37,25 +102,20 @@ files:
37
102
  - lib/payments/refunds_get_request.rb
38
103
  - lib/paypal-checkout-sdk.rb
39
104
  - paypal-checkout-sdk.gemspec
40
- - spec/orders/orders_authorize_spec.rb
41
- - spec/orders/orders_capture_spec.rb
42
- - spec/orders/orders_create_spec.rb
43
- - spec/orders/orders_get_spec.rb
44
- - spec/orders/orders_helper.rb
45
- - spec/orders/orders_patch_spec.rb
46
- - spec/orders/orders_validate_spec.rb
47
- - spec/payments/authorizations_capture_spec.rb
48
- - spec/payments/authorizations_get_spec.rb
49
- - spec/payments/authorizations_reauthorize_spec.rb
50
- - spec/payments/authorizations_void_spec.rb
51
- - spec/payments/captures_get_spec.rb
52
- - spec/payments/captures_refund_spec.rb
53
- - spec/payments/refunds_get_spec.rb
54
- - spec/spec_helper.rb
55
- - spec/test_harness.rb
105
+ - samples/authorize_intent_examples/authorize_order.rb
106
+ - samples/authorize_intent_examples/capture_order.rb
107
+ - samples/authorize_intent_examples/create_order.rb
108
+ - samples/authorize_intent_examples/run_all.rb
109
+ - samples/capture_intent_examples/capture_order.rb
110
+ - samples/capture_intent_examples/create_order.rb
111
+ - samples/capture_intent_examples/run_all.rb
112
+ - samples/get_order.rb
113
+ - samples/patch_order.rb
114
+ - samples/paypal_client.rb
115
+ - samples/refund_capture.rb
56
116
  homepage: https://github.com/paypal/Checkout-Ruby-SDK
57
117
  licenses:
58
- - MIT
118
+ - https://github.com/paypal/Checkout-Ruby-SDK/blob/master/LICENSE
59
119
  metadata: {}
60
120
  post_install_message:
61
121
  rdoc_options: []
@@ -73,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
133
  version: '0'
74
134
  requirements: []
75
135
  rubyforge_project:
76
- rubygems_version: 2.7.6
136
+ rubygems_version: 2.5.2.3
77
137
  signing_key:
78
138
  specification_version: 4
79
139
  summary: This repository contains PayPal's Ruby SDK for Checkout REST API