paypal-sdk-rest-pmrb 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +15 -0
  3. data/README.md +265 -0
  4. data/Rakefile +15 -0
  5. data/data/DigiCertHighAssuranceEVRootCA.pem +23 -0
  6. data/data/DigiCertSHA2ExtendedValidationServerCA.pem +28 -0
  7. data/data/paypal.crt +193 -0
  8. data/lib/generators/paypal/sdk/USAGE +3 -0
  9. data/lib/generators/paypal/sdk/install_generator.rb +17 -0
  10. data/lib/generators/paypal/sdk/templates/paypal.rb +2 -0
  11. data/lib/generators/paypal/sdk/templates/paypal.yml +29 -0
  12. data/lib/paypal-sdk-core.rb +38 -0
  13. data/lib/paypal-sdk-rest.rb +2 -0
  14. data/lib/paypal-sdk/core/api.rb +20 -0
  15. data/lib/paypal-sdk/core/api/base.rb +169 -0
  16. data/lib/paypal-sdk/core/api/data_types/array_with_block.rb +44 -0
  17. data/lib/paypal-sdk/core/api/data_types/base.rb +225 -0
  18. data/lib/paypal-sdk/core/api/data_types/enum.rb +26 -0
  19. data/lib/paypal-sdk/core/api/data_types/simple_types.rb +52 -0
  20. data/lib/paypal-sdk/core/api/ipn.rb +66 -0
  21. data/lib/paypal-sdk/core/api/rest.rb +177 -0
  22. data/lib/paypal-sdk/core/authentication.rb +66 -0
  23. data/lib/paypal-sdk/core/config.rb +253 -0
  24. data/lib/paypal-sdk/core/credential.rb +16 -0
  25. data/lib/paypal-sdk/core/credential/base.rb +27 -0
  26. data/lib/paypal-sdk/core/credential/certificate.rb +32 -0
  27. data/lib/paypal-sdk/core/credential/signature.rb +22 -0
  28. data/lib/paypal-sdk/core/credential/third_party/subject.rb +25 -0
  29. data/lib/paypal-sdk/core/credential/third_party/token.rb +39 -0
  30. data/lib/paypal-sdk/core/exceptions.rb +112 -0
  31. data/lib/paypal-sdk/core/logging.rb +50 -0
  32. data/lib/paypal-sdk/core/openid_connect.rb +140 -0
  33. data/lib/paypal-sdk/core/openid_connect/api.rb +50 -0
  34. data/lib/paypal-sdk/core/openid_connect/data_types.rb +73 -0
  35. data/lib/paypal-sdk/core/openid_connect/get_api.rb +28 -0
  36. data/lib/paypal-sdk/core/openid_connect/request_data_type.rb +52 -0
  37. data/lib/paypal-sdk/core/openid_connect/set_api.rb +36 -0
  38. data/lib/paypal-sdk/core/util.rb +11 -0
  39. data/lib/paypal-sdk/core/util/http_helper.rb +171 -0
  40. data/lib/paypal-sdk/core/util/oauth_signature.rb +64 -0
  41. data/lib/paypal-sdk/core/util/ordered_hash.rb +165 -0
  42. data/lib/paypal-sdk/rest.rb +39 -0
  43. data/lib/paypal-sdk/rest/api.rb +23 -0
  44. data/lib/paypal-sdk/rest/data_types.rb +2597 -0
  45. data/lib/paypal-sdk/rest/error_hash.rb +39 -0
  46. data/lib/paypal-sdk/rest/get_api.rb +20 -0
  47. data/lib/paypal-sdk/rest/request_data_type.rb +53 -0
  48. data/lib/paypal-sdk/rest/set_api.rb +42 -0
  49. data/lib/paypal-sdk/rest/version.rb +7 -0
  50. data/spec/README.md +22 -0
  51. data/spec/config/cacert.pem +171 -0
  52. data/spec/config/cert_key.pem +33 -0
  53. data/spec/config/paypal.yml +35 -0
  54. data/spec/config/sample_data.yml +3 -0
  55. data/spec/core/api/data_type_spec.rb +289 -0
  56. data/spec/core/api/rest_spec.rb +211 -0
  57. data/spec/core/config_spec.rb +192 -0
  58. data/spec/core/logging_spec.rb +28 -0
  59. data/spec/core/openid_connect_spec.rb +153 -0
  60. data/spec/invoice_examples_spec.rb +38 -0
  61. data/spec/log/http.log +175 -0
  62. data/spec/log/rest_http.log +0 -0
  63. data/spec/payments_examples_spec.rb +437 -0
  64. data/spec/payouts_examples_spec.rb +74 -0
  65. data/spec/rest/data_types_spec.rb +62 -0
  66. data/spec/rest/error_hash_spec.rb +83 -0
  67. data/spec/spec_helper.rb +37 -0
  68. data/spec/subscription_examples_spec.rb +227 -0
  69. data/spec/support/sample_data.rb +5 -0
  70. data/spec/web_profile_examples_spec.rb +106 -0
  71. data/spec/webhooks_examples_spec.rb +93 -0
  72. metadata +177 -0
@@ -0,0 +1,5 @@
1
+ module SampleData
2
+ def samples
3
+ @@samples ||= YAML.load(File.read(File.expand_path("../../config/sample_data.yml", __FILE__)))
4
+ end
5
+ end
@@ -0,0 +1,106 @@
1
+ require 'spec_helper'
2
+
3
+ describe "WebProfiles" do
4
+
5
+ WebProfileAttributes = {
6
+ "name" => "YeowZa! T-Shirt Shop",
7
+ "presentation" => {
8
+ "brand_name" => "YeowZa! Paypal",
9
+ "logo_image" => "http://www.yeowza.com",
10
+ "locale_code" => "US"
11
+ },
12
+ "input_fields" => {
13
+ "allow_note" => true,
14
+ "no_shipping" => 0,
15
+ "address_override" => 1
16
+ },
17
+ "flow_config" => {
18
+ "landing_page_type" => "billing",
19
+ "bank_txn_pending_url" => "http://www.yeowza.com"
20
+ }
21
+ }
22
+
23
+ describe "Examples" do
24
+ describe "WebProfile", :integration => true do
25
+ it "Create" do
26
+
27
+ api = API.new
28
+ $webprofile = WebProfile.new(WebProfileAttributes.merge( :token => api.token ))
29
+
30
+ # generate a random number and append it to name
31
+ suffix = Random.rand(1000000000).to_s
32
+ $randname = $webprofile.name + suffix
33
+ $webprofile.name = $randname
34
+
35
+ # create webhook
36
+ $webprofile.create
37
+ expect($webprofile).to be_an_instance_of(WebProfile)
38
+ expect($webprofile.name.to_s).to eq($randname)
39
+ end
40
+
41
+ it "List" do
42
+ list = WebProfile.get_list
43
+ expect(list.size).to be > 1
44
+ expect(list.first).to be_an_instance_of(WebProfileList)
45
+ end
46
+
47
+ it "Retrieve" do
48
+ webprofile = WebProfile.find($webprofile.id)
49
+ expect(webprofile).to be_an_instance_of(WebProfile)
50
+ expect(webprofile.name.to_s).to eq($randname)
51
+ end
52
+
53
+ it "Update" do
54
+ # append "-test" to web profile name
55
+ webprofile = WebProfile.find($webprofile.id)
56
+ webprofile.name += "-test"
57
+ webprofile.update
58
+
59
+ # check whether the name was updated
60
+ webprofile = WebProfile.find($webprofile.id)
61
+ expect(webprofile.name).to eq($randname + "-test")
62
+ webprofile.name = $randname
63
+ webprofile.update
64
+
65
+ # revert updated profile name for next test run
66
+ webprofile = WebProfile.find($webprofile.id)
67
+ expect(webprofile.name).to eq($randname)
68
+ end
69
+
70
+ it "Partial update" do
71
+ # retrieve web profile to perform partial update on
72
+ webprofile = WebProfile.find($webprofile.id)
73
+
74
+ # set up partial update
75
+ h = {"op" => "replace",
76
+ "path" => "/presentation/brand_name",
77
+ "value" => "new_brand_name"}
78
+
79
+ # do partial update by sending a patch request
80
+ expect(webprofile.partial_update( [h] )).to be_truthy
81
+ webprofile = WebProfile.find($webprofile.id)
82
+ expect(webprofile.presentation.brand_name).to eq("new_brand_name")
83
+
84
+ # restore original value for the next test run
85
+ h = {"op" => "replace",
86
+ "path" => "/presentation/brand_name",
87
+ "value" => "brand_name"}
88
+ expect(webprofile.partial_update( [h] )).to be_truthy
89
+ expect(WebProfile.find($webprofile.id).presentation.brand_name).to eq("brand_name")
90
+ end
91
+
92
+ it "Delete" do
93
+ # delete newly created web profile from above create test
94
+ expect($webprofile.delete).to be_truthy
95
+
96
+ # make sure it is not retrieved from the system
97
+ begin
98
+ webprofile = WebProfile.find($webprofile.id)
99
+ expect(webprofile).to be_nil
100
+ fail "WebProfile with ID=#{$webprofile.id} has not been deleted"
101
+ rescue ResourceNotFound
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,93 @@
1
+ require "spec_helper"
2
+ require "securerandom"
3
+
4
+ describe "Webhooks" do
5
+
6
+ webhookAttributes = {
7
+ :url => "https://www.yeowza.com/paypal_webhook_"+SecureRandom.hex(8),
8
+ :event_types => [
9
+ {
10
+ :name => "PAYMENT.AUTHORIZATION.CREATED"
11
+ },
12
+ {
13
+ :name => "PAYMENT.AUTHORIZATION.VOIDED"
14
+ }
15
+ ]
16
+ }
17
+
18
+ describe "PayPal::SDK::Core::API::DataTypes::WebhookEvent" do
19
+ describe "get event by id via .find" do
20
+ it "exists" do
21
+ expect(WebhookEvent).to respond_to(:find)
22
+ end
23
+ end
24
+ end
25
+
26
+ describe "Notifications", :integration => true do
27
+ it "create webhook" do
28
+ $webhook = PayPal::SDK::REST::Webhook.new(webhookAttributes)
29
+ expect($webhook.create).to be_truthy
30
+ end
31
+
32
+ it "get webhook" do
33
+ $result = PayPal::SDK::REST::Webhook.get($webhook.id)
34
+ expect($result).to be_a PayPal::SDK::REST::Webhook
35
+ expect($result.id).to eql $webhook.id
36
+ end
37
+
38
+ it "get all webhooks" do
39
+ $webhooks_list = PayPal::SDK::REST::Webhook.all()
40
+ expect($webhooks_list.webhooks.length).not_to be_nil
41
+ end
42
+
43
+ it "get subscribed webhook event types" do
44
+ $webhook_event_types = PayPal::SDK::REST::Webhook.get_event_types($webhook.id)
45
+ expect($webhook_event_types.event_types.length).to eql $webhook.event_types.length
46
+ end
47
+
48
+ it "delete webhook" do
49
+ expect($webhook.delete).to be_truthy
50
+ end
51
+ end
52
+
53
+ describe "Validation", :integration => true do
54
+
55
+ transmission_id = "dfb3be50-fd74-11e4-8bf3-77339302725b"
56
+ timestamp = "2015-05-18T15:45:13Z"
57
+ webhook_id = "4JH86294D6297924G"
58
+ actual_signature = "thy4/U002quzxFavHPwbfJGcc46E8rc5jzgyeafWm5mICTBdY/8rl7WJpn8JA0GKA+oDTPsSruqusw+XXg5RLAP7ip53Euh9Xu3UbUhQFX7UgwzE2FeYoY6lyRMiiiQLzy9BvHfIzNIVhPad4KnC339dr6y2l+mN8ALgI4GCdIh3/SoJO5wE64Bh/ueWtt8EVuvsvXfda2Le5a2TrOI9vLEzsm9GS79hAR/5oLexNz8UiZr045Mr5ObroH4w4oNfmkTaDk9Rj0G19uvISs5QzgmBpauKr7Nw++JI0pr/v5mFctQkoWJSGfBGzPRXawrvIIVHQ9Wer48GR2g9ZiApWg=="
59
+ event_body = '{"id":"WH-0G2756385H040842W-5Y612302CV158622M","create_time":"2015-05-18T15:45:13Z","resource_type":"sale","event_type":"PAYMENT.SALE.COMPLETED","summary":"Payment completed for $ 20.0 USD","resource":{"id":"4EU7004268015634R","create_time":"2015-05-18T15:44:02Z","update_time":"2015-05-18T15:44:21Z","amount":{"total":"20.00","currency":"USD"},"payment_mode":"INSTANT_TRANSFER","state":"completed","protection_eligibility":"ELIGIBLE","protection_eligibility_type":"ITEM_NOT_RECEIVED_ELIGIBLE,UNAUTHORIZED_PAYMENT_ELIGIBLE","parent_payment":"PAY-86C81811X5228590KKVNARQQ","transaction_fee":{"value":"0.88","currency":"USD"},"links":[{"href":"https://api.sandbox.paypal.com/v1/payments/sale/4EU7004268015634R","rel":"self","method":"GET"},{"href":"https://api.sandbox.paypal.com/v1/payments/sale/4EU7004268015634R/refund","rel":"refund","method":"POST"},{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-86C81811X5228590KKVNARQQ","rel":"parent_payment","method":"GET"}]},"links":[{"href":"https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-0G2756385H040842W-5Y612302CV158622M","rel":"self","method":"GET"},{"href":"https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-0G2756385H040842W-5Y612302CV158622M/resend","rel":"resend","method":"POST"}]}'
60
+ cert_url = "https://api.sandbox.paypal.com/v1/notifications/certs/CERT-360caa42-fca2a594-a5cafa77"
61
+
62
+ it "verify common name" do
63
+ cert = PayPal::SDK::REST::WebhookEvent.get_cert(cert_url)
64
+ valid = PayPal::SDK::REST::WebhookEvent.verify_common_name(cert)
65
+ expect(valid).to be_truthy
66
+ end
67
+
68
+ it "verify get expected signature" do
69
+ expected_sig = PayPal::SDK::REST::WebhookEvent.get_expected_sig(transmission_id, timestamp, webhook_id, event_body)
70
+ expect(expected_sig).eql?("dfb3be50-fd74-11e4-8bf3-77339302725b|2015-05-18T15:45:13Z|4JH86294D6297924G|2771810304")
71
+ end
72
+
73
+ it "verify expiry" do
74
+ cert = PayPal::SDK::REST::WebhookEvent.get_cert(cert_url)
75
+ valid = PayPal::SDK::REST::WebhookEvent.verify_expiration(cert)
76
+ expect(valid).to be_truthy
77
+ end
78
+
79
+ it "verify cert chain" do
80
+ cert = PayPal::SDK::REST::WebhookEvent.get_cert(cert_url)
81
+ cert_store = PayPal::SDK::REST::WebhookEvent.get_cert_chain
82
+ valid = PayPal::SDK::REST::WebhookEvent.verify_cert_chain(cert_store, cert)
83
+ expect(valid).to be_truthy
84
+ end
85
+
86
+ it "verify" do
87
+ valid = PayPal::SDK::REST::WebhookEvent.verify(transmission_id, timestamp, webhook_id, event_body, cert_url, actual_signature)
88
+ expect(valid).to be_truthy
89
+ end
90
+ end
91
+
92
+
93
+ end
metadata ADDED
@@ -0,0 +1,177 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: paypal-sdk-rest-pmrb
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.8.0
5
+ platform: ruby
6
+ authors:
7
+ - PayPal
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-08-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: coveralls
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: xml-simple
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: multi_json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ description:
56
+ email:
57
+ - piers@varyonic.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - Gemfile
63
+ - README.md
64
+ - Rakefile
65
+ - data/DigiCertHighAssuranceEVRootCA.pem
66
+ - data/DigiCertSHA2ExtendedValidationServerCA.pem
67
+ - data/paypal.crt
68
+ - lib/generators/paypal/sdk/USAGE
69
+ - lib/generators/paypal/sdk/install_generator.rb
70
+ - lib/generators/paypal/sdk/templates/paypal.rb
71
+ - lib/generators/paypal/sdk/templates/paypal.yml
72
+ - lib/paypal-sdk-core.rb
73
+ - lib/paypal-sdk-rest.rb
74
+ - lib/paypal-sdk/core/api.rb
75
+ - lib/paypal-sdk/core/api/base.rb
76
+ - lib/paypal-sdk/core/api/data_types/array_with_block.rb
77
+ - lib/paypal-sdk/core/api/data_types/base.rb
78
+ - lib/paypal-sdk/core/api/data_types/enum.rb
79
+ - lib/paypal-sdk/core/api/data_types/simple_types.rb
80
+ - lib/paypal-sdk/core/api/ipn.rb
81
+ - lib/paypal-sdk/core/api/rest.rb
82
+ - lib/paypal-sdk/core/authentication.rb
83
+ - lib/paypal-sdk/core/config.rb
84
+ - lib/paypal-sdk/core/credential.rb
85
+ - lib/paypal-sdk/core/credential/base.rb
86
+ - lib/paypal-sdk/core/credential/certificate.rb
87
+ - lib/paypal-sdk/core/credential/signature.rb
88
+ - lib/paypal-sdk/core/credential/third_party/subject.rb
89
+ - lib/paypal-sdk/core/credential/third_party/token.rb
90
+ - lib/paypal-sdk/core/exceptions.rb
91
+ - lib/paypal-sdk/core/logging.rb
92
+ - lib/paypal-sdk/core/openid_connect.rb
93
+ - lib/paypal-sdk/core/openid_connect/api.rb
94
+ - lib/paypal-sdk/core/openid_connect/data_types.rb
95
+ - lib/paypal-sdk/core/openid_connect/get_api.rb
96
+ - lib/paypal-sdk/core/openid_connect/request_data_type.rb
97
+ - lib/paypal-sdk/core/openid_connect/set_api.rb
98
+ - lib/paypal-sdk/core/util.rb
99
+ - lib/paypal-sdk/core/util/http_helper.rb
100
+ - lib/paypal-sdk/core/util/oauth_signature.rb
101
+ - lib/paypal-sdk/core/util/ordered_hash.rb
102
+ - lib/paypal-sdk/rest.rb
103
+ - lib/paypal-sdk/rest/api.rb
104
+ - lib/paypal-sdk/rest/data_types.rb
105
+ - lib/paypal-sdk/rest/error_hash.rb
106
+ - lib/paypal-sdk/rest/get_api.rb
107
+ - lib/paypal-sdk/rest/request_data_type.rb
108
+ - lib/paypal-sdk/rest/set_api.rb
109
+ - lib/paypal-sdk/rest/version.rb
110
+ - spec/README.md
111
+ - spec/config/cacert.pem
112
+ - spec/config/cert_key.pem
113
+ - spec/config/paypal.yml
114
+ - spec/config/sample_data.yml
115
+ - spec/core/api/data_type_spec.rb
116
+ - spec/core/api/rest_spec.rb
117
+ - spec/core/config_spec.rb
118
+ - spec/core/logging_spec.rb
119
+ - spec/core/openid_connect_spec.rb
120
+ - spec/invoice_examples_spec.rb
121
+ - spec/log/http.log
122
+ - spec/log/rest_http.log
123
+ - spec/payments_examples_spec.rb
124
+ - spec/payouts_examples_spec.rb
125
+ - spec/rest/data_types_spec.rb
126
+ - spec/rest/error_hash_spec.rb
127
+ - spec/spec_helper.rb
128
+ - spec/subscription_examples_spec.rb
129
+ - spec/support/sample_data.rb
130
+ - spec/web_profile_examples_spec.rb
131
+ - spec/webhooks_examples_spec.rb
132
+ homepage: https://github.com/paypal-merchants-rb/PayPal-Ruby-SDK
133
+ licenses:
134
+ - PayPal SDK License
135
+ metadata: {}
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubygems_version: 3.0.1
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: The PayPal REST SDK provides Ruby APIs to create, process and manage payment.
155
+ test_files:
156
+ - spec/README.md
157
+ - spec/config/cacert.pem
158
+ - spec/config/cert_key.pem
159
+ - spec/config/paypal.yml
160
+ - spec/config/sample_data.yml
161
+ - spec/core/api/data_type_spec.rb
162
+ - spec/core/api/rest_spec.rb
163
+ - spec/core/config_spec.rb
164
+ - spec/core/logging_spec.rb
165
+ - spec/core/openid_connect_spec.rb
166
+ - spec/invoice_examples_spec.rb
167
+ - spec/log/http.log
168
+ - spec/log/rest_http.log
169
+ - spec/payments_examples_spec.rb
170
+ - spec/payouts_examples_spec.rb
171
+ - spec/rest/data_types_spec.rb
172
+ - spec/rest/error_hash_spec.rb
173
+ - spec/spec_helper.rb
174
+ - spec/subscription_examples_spec.rb
175
+ - spec/support/sample_data.rb
176
+ - spec/web_profile_examples_spec.rb
177
+ - spec/webhooks_examples_spec.rb