paypal-sdk-rest 1.1.3 → 1.2.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
  SHA1:
3
- metadata.gz: f5c7274698b9bb853894c15bc58b7396cef9607f
4
- data.tar.gz: f897393c936db98771b3b07e747ae33044867be1
3
+ metadata.gz: 38b4da25c343ab05d78dd621d36bb49078596118
4
+ data.tar.gz: 34cfe1f759ef25430f2473191ce6a6df937c56c4
5
5
  SHA512:
6
- metadata.gz: 8f14a3a24092aca8356609f67ee38a59a82e478746e0b058c779e21c94b9d7f3f8628a6a542a2fcc0783d664be66d0f8daf141384b7c3d906b3bb8a79f88e07b
7
- data.tar.gz: 6ade26596828a8216ad4c340c7e0b376ecef2e7412fa62dd70352c3902d358fa18309100b46ad2e0e9e63226a5d3564092075e3c9bc7e8bc8d4fd2ea53bb985d
6
+ metadata.gz: 8a2b39a7bf199f4f636a332b096862edd7172c0d94751f783a2627eaef95ad9b8b246879597a0bfdced3be0e8c0ffd4f21b846cc492629250deaa3bfc13c1481
7
+ data.tar.gz: e5000ed76b0d7d699f3977b56470129e6ebfeb91a3636cf85b29b8ea9045381d23965e1c1c88e47f2600fd164833bba01218693c5f3f061b132705fe0b4eb916
@@ -1,5 +1,6 @@
1
1
  require 'paypal-sdk-core'
2
2
  require 'uuidtools'
3
+ require 'multi_json'
3
4
 
4
5
  module PayPal::SDK
5
6
  module REST
@@ -1011,6 +1012,161 @@ module PayPal::SDK
1011
1012
  end
1012
1013
  end
1013
1014
 
1015
+ class WebhooksEventType < Base
1016
+
1017
+ def self.load_members
1018
+ array_of :event_types, EventType
1019
+ end
1020
+
1021
+ include RequestDataType
1022
+
1023
+ class << self
1024
+ def all(options = {})
1025
+ path = "v1/notifications/webhooks-event-types"
1026
+ EventTypeList.new(api.get(path, options))
1027
+ end
1028
+ end
1029
+ end
1030
+
1031
+ class EventTypeList < Base
1032
+ def self.load_members
1033
+ array_of :event_types, EventType
1034
+ end
1035
+ end
1036
+
1037
+ class WebhookList < Base
1038
+ def self.load_members
1039
+ array_of :webhooks, Webhook
1040
+ end
1041
+ end
1042
+
1043
+ class EventType < Base
1044
+ def self.load_members
1045
+ object_of :name, String
1046
+ object_of :description, String
1047
+ end
1048
+ end
1049
+
1050
+ class WebhookEventList < Base
1051
+ def self.load_members
1052
+ object_of :count, Integer
1053
+ array_of :events, WebhookEvent
1054
+ array_of :links, Links
1055
+ end
1056
+ end
1057
+
1058
+ class WebhookEvent < Base
1059
+ def self.load_members
1060
+ object_of :id, String
1061
+ object_of :create_time, String
1062
+ object_of :resource_type, String
1063
+ object_of :event_type, String
1064
+ object_of :summary, String
1065
+ object_of :resource, Hash
1066
+ array_of :links, Links
1067
+ end
1068
+
1069
+ def resend()
1070
+ path = "v1/notifications/webhooks-events/#{self.id}/resend"
1071
+ WebhookEvent.new(api.post(path))
1072
+ end
1073
+
1074
+ def get_resource()
1075
+ webhook_resource_type = self.resource_type
1076
+ resource_class = self.class.get_resource_class(webhook_resource_type)
1077
+ if resource_class
1078
+ return Object::const_get(resource_class).new(self.resource)
1079
+ else
1080
+ return self.resource
1081
+ end
1082
+ end
1083
+
1084
+ include RequestDataType
1085
+
1086
+ class << self
1087
+
1088
+ def get_resource_class(name)
1089
+ class_array = PayPal::SDK::REST.constants.select {|c| Class === PayPal::SDK::REST.const_get(c)}
1090
+ class_array.each do |classname|
1091
+ if (classname.to_s.downcase == name.downcase)
1092
+ return classname
1093
+ end
1094
+ end
1095
+ end
1096
+
1097
+ def search(page_size, start_time, end_time)
1098
+ path = "v1/notifications/webhooks-events"
1099
+ options = { :page_size => page_size, :start_time => start_time, :end_time => end_time }
1100
+ WebhookEventList.new(api.get(path, options))
1101
+ end
1102
+
1103
+ def get(webhook_event_id)
1104
+ raise ArgumentError.new("webhook_event_id required") if webhook_event_id.to_s.strip.empty?
1105
+ path = "v1/notifications/webhooks-events/#{webhook_event_id}"
1106
+ WebhookEvent.new(api.get(path))
1107
+ end
1108
+ end
1109
+ end
1110
+
1111
+ class Webhook < Base
1112
+
1113
+ def self.load_members
1114
+ object_of :id, String
1115
+ object_of :url, String
1116
+ array_of :event_types, EventType
1117
+ array_of :links, Links
1118
+ end
1119
+
1120
+ include RequestDataType
1121
+
1122
+ def create()
1123
+ path = "v1/notifications/webhooks"
1124
+ response = api.post(path, self.to_hash, http_header)
1125
+ self.merge!(response)
1126
+ Webhook.new(response)
1127
+ end
1128
+
1129
+ def update(patch)
1130
+ patch = Patch.new(patch) unless patch.is_a? Patch
1131
+ patch_request = Array.new(1, patch.to_hash)
1132
+ path = "v1/notifications/webhooks/#{self.id}"
1133
+ response = api.patch(path, patch_request, http_header)
1134
+ self.merge!(response)
1135
+ success?
1136
+ end
1137
+
1138
+ def delete()
1139
+ path = "v1/notifications/webhooks/#{self.id}"
1140
+ response = api.delete(path, {})
1141
+ self.merge!(response)
1142
+ success?
1143
+ end
1144
+
1145
+ class << self
1146
+ def get(webhook_id)
1147
+ raise ArgumentError.new("webhook_id required") if webhook_id.to_s.strip.empty?
1148
+ path = "v1/notifications/webhooks/#{webhook_id}"
1149
+ Webhook.new(api.get(path))
1150
+ end
1151
+ def get_event_types(webhook_id)
1152
+ raise ArgumentError.new("webhook_id required") if webhook_id.to_s.strip.empty?
1153
+ path = "v1/notifications/webhooks/#{webhook_id}/event-types"
1154
+ EventTypeList.new(api.get(path))
1155
+ end
1156
+ def all(options={})
1157
+ path = "v1/notifications/webhooks"
1158
+ WebhookList.new(api.get(path))
1159
+ end
1160
+
1161
+ def simulate_event(webhook_id, url, event_type)
1162
+ path = "v1/notifications/simulate-event"
1163
+ options = { :webhook_id => webhook_id, :url => url, :event_type => event_type }
1164
+ response = api.post(path, options)
1165
+ WebhookEvent.new(response)
1166
+ end
1167
+ end
1168
+ end
1169
+
1014
1170
  class Payout < Base
1015
1171
 
1016
1172
  def self.load_members
@@ -1531,7 +1687,6 @@ module PayPal::SDK
1531
1687
 
1532
1688
  def execute()
1533
1689
  path = "v1/payments/billing-agreements/#{self.token}/agreement-execute"
1534
- puts path
1535
1690
  response = api.post(path, {}, http_header)
1536
1691
  self.merge!(response)
1537
1692
  success?
@@ -1,7 +1,7 @@
1
1
  module PayPal
2
2
  module SDK
3
3
  module REST
4
- VERSION = "1.1.3"
4
+ VERSION = "1.2.0"
5
5
  end
6
6
  end
7
7
  end
@@ -2,40 +2,38 @@ opening connection to api.sandbox.paypal.com:443...
2
2
  opened
3
3
  starting SSL for api.sandbox.paypal.com:443...
4
4
  SSL established
5
- <- "GET /v1/payments/payment/PAY-1234 HTTP/1.1\r\nX-Paypal-Sandbox-Email-Address: Platform.sdk.seller@gmail.com\r\nAuthorization: Bearer A015ZyrqDqUwads.muwOVYUAKx74DlwGYa04fIfu0xHAbW4\r\nContent-Type: application/json\r\nUser-Agent: PayPalSDK/rest-sdk-ruby 1.1.3 (paypal-sdk-core 1.1.3; ruby 2.1.2p95-x86_64-darwin13.0)\r\nAccept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3\r\nAccept: */*\r\nHost: api.sandbox.paypal.com\r\n\r\n"
5
+ <- "GET /v1/payments/payment/PAY-1234 HTTP/1.1\r\nX-Paypal-Sandbox-Email-Address: Platform.sdk.seller@gmail.com\r\nAuthorization: Bearer A015p9UmS9bbjBKvXFguSGxuZxGMlvD8iJdSLcI6dBVCi2c\r\nContent-Type: application/json\r\nUser-Agent: PayPalSDK/rest-sdk-ruby 1.1.2 (paypal-sdk-core 1.1.2; ruby 2.1.2p95-x86_64-darwin13.0)\r\nAccept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3\r\nAccept: */*\r\nHost: api.sandbox.paypal.com\r\n\r\n"
6
6
  -> "HTTP/1.1 404 Not Found\r\n"
7
7
  -> "Server: Apache-Coyote/1.1\r\n"
8
- -> "PROXY_SERVER_INFO: host=slcsbplatformapiserv3001.slc.paypal.com;threadId=7182\r\n"
9
- -> "Paypal-Debug-Id: e632ea9d7d8f6\r\n"
10
- -> "SERVER_INFO: paymentsplatformserv:v1.payments.payment&CalThreadId=6491&TopLevelTxnStartTime=14c948cca8d&Host=slcsbpaymentsplatformserv3001.slc.paypal.com&pid=10160\r\n"
8
+ -> "PROXY_SERVER_INFO: host=slcsbplatformapiserv3002.slc.paypal.com;threadId=6008\r\n"
9
+ -> "Paypal-Debug-Id: c8f86460d1f6d\r\n"
11
10
  -> "Content-Language: *\r\n"
12
- -> "Date: Tue, 07 Apr 2015 15:43:16 GMT\r\n"
11
+ -> "Date: Tue, 05 May 2015 14:30:04 GMT\r\n"
13
12
  -> "Content-Type: application/json\r\n"
14
13
  -> "Content-Length: 207\r\n"
15
14
  -> "\r\n"
16
15
  reading 207 bytes...
17
- -> "{\"name\":\"INVALID_RESOURCE_ID\",\"message\":\"The requested resource ID was not found\",\"information_link\":\"https://developer.paypal.com/webapps/developer/docs/api/#INVALID_RESOURCE_ID\",\"debug_id\":\"e632ea9d7d8f6\"}"
16
+ -> "{\"name\":\"INVALID_RESOURCE_ID\",\"message\":\"The requested resource ID was not found\",\"information_link\":\"https://developer.paypal.com/webapps/developer/docs/api/#INVALID_RESOURCE_ID\",\"debug_id\":\"c8f86460d1f6d\"}"
18
17
  read 207 bytes
19
18
  Conn keep-alive
20
19
  opening connection to api.sandbox.paypal.com:443...
21
20
  opened
22
21
  starting SSL for api.sandbox.paypal.com:443...
23
22
  SSL established
24
- <- "POST /v1/payments/payment HTTP/1.1\r\nX-Paypal-Sandbox-Email-Address: Platform.sdk.seller@gmail.com\r\nAuthorization: Bearer A015ZyrqDqUwads.muwOVYUAKx74DlwGYa04fIfu0xHAbW4\r\nContent-Type: application/json\r\nUser-Agent: PayPalSDK/rest-sdk-ruby 1.1.3 (paypal-sdk-core 1.1.3; ruby 2.1.2p95-x86_64-darwin13.0)\r\nAccept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3\r\nAccept: */*\r\nHost: api.sandbox.paypal.com\r\nContent-Length: 2\r\n\r\n"
23
+ <- "POST /v1/payments/payment HTTP/1.1\r\nX-Paypal-Sandbox-Email-Address: Platform.sdk.seller@gmail.com\r\nAuthorization: Bearer A015p9UmS9bbjBKvXFguSGxuZxGMlvD8iJdSLcI6dBVCi2c\r\nContent-Type: application/json\r\nUser-Agent: PayPalSDK/rest-sdk-ruby 1.1.2 (paypal-sdk-core 1.1.2; ruby 2.1.2p95-x86_64-darwin13.0)\r\nAccept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3\r\nAccept: */*\r\nHost: api.sandbox.paypal.com\r\nContent-Length: 2\r\n\r\n"
25
24
  <- "{}"
26
25
  -> "HTTP/1.1 400 Bad Request\r\n"
27
26
  -> "Server: Apache-Coyote/1.1\r\n"
28
- -> "PROXY_SERVER_INFO: host=slcsbplatformapiserv3002.slc.paypal.com;threadId=2269\r\n"
29
- -> "Paypal-Debug-Id: 383fe0c9634bd\r\n"
30
- -> "SERVER_INFO: paymentsplatformserv:v1.payments.payment&CalThreadId=468&TopLevelTxnStartTime=14c948cccca&Host=slcsbpaymentsplatformserv3002.slc.paypal.com&pid=22334\r\n"
27
+ -> "PROXY_SERVER_INFO: host=slcsbplatformapiserv3002.slc.paypal.com;threadId=5913\r\n"
28
+ -> "Paypal-Debug-Id: 3be36c95d1d44\r\n"
31
29
  -> "Content-Language: *\r\n"
32
- -> "Date: Tue, 07 Apr 2015 15:43:17 GMT\r\n"
30
+ -> "Date: Tue, 05 May 2015 14:30:05 GMT\r\n"
33
31
  -> "Connection: close\r\n"
34
32
  -> "Content-Type: application/json\r\n"
35
33
  -> "Content-Length: 306\r\n"
36
34
  -> "Connection: close\r\n"
37
35
  -> "\r\n"
38
36
  reading 306 bytes...
39
- -> "{\"name\":\"VALIDATION_ERROR\",\"details\":[{\"field\":\"intent\",\"issue\":\"Required field missing\"},{\"field\":\"payer\",\"issue\":\"Required field missing\"}],\"message\":\"Invalid request - see details\",\"information_link\":\"https://developer.paypal.com/webapps/developer/docs/api/#VALIDATION_ERROR\",\"debug_id\":\"383fe0c9634bd\"}"
37
+ -> "{\"name\":\"VALIDATION_ERROR\",\"details\":[{\"field\":\"payer\",\"issue\":\"Required field missing\"},{\"field\":\"intent\",\"issue\":\"Required field missing\"}],\"message\":\"Invalid request - see details\",\"information_link\":\"https://developer.paypal.com/webapps/developer/docs/api/#VALIDATION_ERROR\",\"debug_id\":\"3be36c95d1d44\"}"
40
38
  read 306 bytes
41
39
  Conn close
@@ -0,0 +1,42 @@
1
+ require "spec_helper"
2
+ require "securerandom"
3
+
4
+ describe "Webhooks", :integration => true 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
+ it "create webhook" do
19
+ $webhook = PayPal::SDK::REST::Webhook.new(webhookAttributes)
20
+ expect($webhook.create).to be_truthy
21
+ end
22
+
23
+ it "get webhook" do
24
+ $result = PayPal::SDK::REST::Webhook.get($webhook.id)
25
+ expect($result).to be_a PayPal::SDK::REST::Webhook
26
+ expect($result.id).to eql $webhook.id
27
+ end
28
+
29
+ it "get all webhooks" do
30
+ $webhooks_list = PayPal::SDK::REST::Webhook.all()
31
+ expect($webhooks_list.webhooks.length).not_to be_nil
32
+ end
33
+
34
+ it "get subscribed webhook event types" do
35
+ $webhook_event_types = PayPal::SDK::REST::Webhook.get_event_types($webhook.id)
36
+ expect($webhook_event_types.event_types.length).to eql $webhook.event_types.length
37
+ end
38
+
39
+ it "delete webhook" do
40
+ expect($webhook.delete).to be_truthy
41
+ end
42
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paypal-sdk-rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - PayPal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-07 00:00:00.000000000 Z
11
+ date: 2015-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coveralls
@@ -139,6 +139,7 @@ files:
139
139
  - spec/subscription_examples_spec.rb
140
140
  - spec/support/sample_data.rb
141
141
  - spec/web_profile_examples_spec.rb
142
+ - spec/webhooks_examples_spec.rb
142
143
  homepage: https://developer.paypal.com
143
144
  licenses:
144
145
  - PayPal SDK License
@@ -183,3 +184,4 @@ test_files:
183
184
  - spec/subscription_examples_spec.rb
184
185
  - spec/support/sample_data.rb
185
186
  - spec/web_profile_examples_spec.rb
187
+ - spec/webhooks_examples_spec.rb