WebHooks.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. <?php
  2. namespace Srmklive\PayPal\Tests\Mocks\Responses;
  3. use GuzzleHttp\Utils;
  4. trait WebHooks
  5. {
  6. /**
  7. * @return array
  8. */
  9. private function mockCreateWebHookResponse(): array
  10. {
  11. return Utils::jsonDecode('{
  12. "id": "0EH40505U7160970P",
  13. "url": "https://example.com/example_webhook",
  14. "event_types": [
  15. {
  16. "name": "PAYMENT.AUTHORIZATION.CREATED",
  17. "description": "A payment authorization was created."
  18. },
  19. {
  20. "name": "PAYMENT.AUTHORIZATION.VOIDED",
  21. "description": "A payment authorization was voided."
  22. }
  23. ],
  24. "links": [
  25. {
  26. "href": "https://api.paypal.com/v1/notifications/webhooks/0EH40505U7160970P",
  27. "rel": "self",
  28. "method": "GET"
  29. },
  30. {
  31. "href": "https://api.paypal.com/v1/notifications/webhooks/0EH40505U7160970P",
  32. "rel": "update",
  33. "method": "PATCH"
  34. },
  35. {
  36. "href": "https://api.paypal.com/v1/notifications/webhooks/0EH40505U7160970P",
  37. "rel": "delete",
  38. "method": "DELETE"
  39. }
  40. ]
  41. }', true);
  42. }
  43. /**
  44. * @return array
  45. */
  46. private function mockListWebHookResponse(): array
  47. {
  48. return Utils::jsonDecode('{
  49. "webhooks": [
  50. {
  51. "id": "40Y916089Y8324740",
  52. "url": "https://example.com/example_webhook",
  53. "event_types": [
  54. {
  55. "name": "PAYMENT.AUTHORIZATION.CREATED",
  56. "description": "A payment authorization was created."
  57. },
  58. {
  59. "name": "PAYMENT.AUTHORIZATION.VOIDED",
  60. "description": "A payment authorization was voided."
  61. }
  62. ],
  63. "links": [
  64. {
  65. "href": "https://api.paypal.com/v1/notifications/webhooks/40Y916089Y8324740",
  66. "rel": "self",
  67. "method": "GET"
  68. },
  69. {
  70. "href": "https://api.paypal.com/v1/notifications/webhooks/40Y916089Y8324740",
  71. "rel": "update",
  72. "method": "PATCH"
  73. },
  74. {
  75. "href": "https://api.paypal.com/v1/notifications/webhooks/40Y916089Y8324740",
  76. "rel": "delete",
  77. "method": "DELETE"
  78. }
  79. ]
  80. },
  81. {
  82. "id": "0EH40505U7160970P",
  83. "url": "https://example.com/another_example_webhook",
  84. "event_types": [
  85. {
  86. "name": "PAYMENT.AUTHORIZATION.CREATED",
  87. "description": "A payment authorization was created."
  88. },
  89. {
  90. "name": "PAYMENT.AUTHORIZATION.VOIDED",
  91. "description": "A payment authorization was voided."
  92. }
  93. ],
  94. "links": [
  95. {
  96. "href": "https://api.paypal.com/v1/notifications/webhooks/0EH40505U7160970P",
  97. "rel": "self",
  98. "method": "GET"
  99. },
  100. {
  101. "href": "https://api.paypal.com/v1/notifications/webhooks/0EH40505U7160970P",
  102. "rel": "update",
  103. "method": "PATCH"
  104. },
  105. {
  106. "href": "https://api.paypal.com/v1/notifications/webhooks/0EH40505U7160970P",
  107. "rel": "delete",
  108. "method": "DELETE"
  109. }
  110. ]
  111. }
  112. ]
  113. }', true);
  114. }
  115. /**
  116. * @return array
  117. */
  118. private function mockUpdateWebHookResponse(): array
  119. {
  120. return Utils::jsonDecode('{
  121. "id": "0EH40505U7160970P",
  122. "url": "https://example.com/example_webhook_2",
  123. "event_types": [
  124. {
  125. "name": "PAYMENT.SALE.REFUNDED",
  126. "description": "A sale payment was refunded."
  127. }
  128. ],
  129. "links": [
  130. {
  131. "href": "https://api.paypal.com/v1/notifications/webhooks/0EH40505U7160970P",
  132. "rel": "self",
  133. "method": "GET"
  134. },
  135. {
  136. "href": "https://api.paypal.com/v1/notifications/webhooks/0EH40505U7160970P",
  137. "rel": "update",
  138. "method": "PATCH"
  139. },
  140. {
  141. "href": "https://api.paypal.com/v1/notifications/webhooks/0EH40505U7160970P",
  142. "rel": "delete",
  143. "method": "DELETE"
  144. }
  145. ]
  146. }', true);
  147. }
  148. /**
  149. * @return array
  150. */
  151. private function mockGetWebHookResponse(): array
  152. {
  153. return Utils::jsonDecode('{
  154. "id": "0EH40505U7160970P",
  155. "url": "https://example.com/example_webhook",
  156. "event_types": [
  157. {
  158. "name": "PAYMENT.AUTHORIZATION.CREATED",
  159. "description": "A payment authorization was created.",
  160. "status": "ENABLED"
  161. },
  162. {
  163. "name": "PAYMENT.AUTHORIZATION.VOIDED",
  164. "description": "A payment authorization was voided.",
  165. "status": "ENABLED"
  166. }
  167. ],
  168. "links": [
  169. {
  170. "href": "https://api.paypal.com/v1/notifications/webhooks/0EH40505U7160970P",
  171. "rel": "self",
  172. "method": "GET"
  173. },
  174. {
  175. "href": "https://api.paypal.com/v1/notifications/webhooks/0EH40505U7160970P",
  176. "rel": "update",
  177. "method": "PATCH"
  178. },
  179. {
  180. "href": "https://api.paypal.com/v1/notifications/webhooks/0EH40505U7160970P",
  181. "rel": "delete",
  182. "method": "DELETE"
  183. }
  184. ]
  185. }', true);
  186. }
  187. /**
  188. * @return array
  189. */
  190. private function mockListWebHookEventsResponse(): array
  191. {
  192. return Utils::jsonDecode('{
  193. "event_types": [
  194. {
  195. "name": "PAYMENT.AUTHORIZATION.CREATED",
  196. "description": "A payment authorization was created.",
  197. "status": "ENABLED"
  198. },
  199. {
  200. "name": "PAYMENT.AUTHORIZATION.VOIDED",
  201. "description": "A payment authorization was voided.",
  202. "status": "ENABLED"
  203. },
  204. {
  205. "name": "RISK.DISPUTE.CREATED",
  206. "description": "A dispute was filed against a transaction.",
  207. "status": "DEPRECATED"
  208. }
  209. ]
  210. }', true);
  211. }
  212. /**
  213. * @return array
  214. */
  215. private function mockListWebHookEventsTypesResponse(): array
  216. {
  217. return Utils::jsonDecode('{
  218. "event_types": [
  219. {
  220. "name": "PAYMENT.AUTHORIZATION.CREATED",
  221. "description": "A payment authorization was created.",
  222. "status": "ENABLED",
  223. "service": "amqpaymentwebhookd",
  224. "owner": "Webhooks",
  225. "contact": "livesupport@example.com"
  226. },
  227. {
  228. "name": "PAYMENT.AUTHORIZATION.VOIDED",
  229. "description": "A payment authorization was voided.",
  230. "status": "ENABLED",
  231. "service": "amqpaymentwebhookd",
  232. "owner": "Webhooks",
  233. "contact": "livesupport@example.com"
  234. },
  235. {
  236. "name": "PAYMENT.CAPTURE.COMPLETED",
  237. "description": "A capture payment was completed.",
  238. "status": "ENABLED",
  239. "service": "amqpaymentwebhookd",
  240. "owner": "Webhooks",
  241. "contact": "livesupport@example.com"
  242. }
  243. ]
  244. }', true);
  245. }
  246. /**
  247. * @return array
  248. */
  249. private function mockWebHookEventsListResponse(): array
  250. {
  251. return Utils::jsonDecode('{
  252. "events": [
  253. {
  254. "id": "8PT597110X687430LKGECATA",
  255. "create_time": "2013-06-25T21:41:28Z",
  256. "resource_type": "authorization",
  257. "event_version": "1.0",
  258. "event_type": "PAYMENT.AUTHORIZATION.CREATED",
  259. "summary": "A payment authorization was created",
  260. "resource_version": "1.0",
  261. "resource": {
  262. "id": "2DC87612EK520411B",
  263. "create_time": "2013-06-25T21:39:15Z",
  264. "update_time": "2013-06-25T21:39:17Z",
  265. "state": "authorized",
  266. "amount": {
  267. "total": "7.47",
  268. "currency": "USD",
  269. "details": {
  270. "subtotal": "7.47"
  271. }
  272. },
  273. "parent_payment": "PAY-36246664YD343335CKHFA4AY",
  274. "valid_until": "2013-07-24T21:39:15Z",
  275. "links": [
  276. {
  277. "href": "https://api.paypal.com/v1/payments/authorization/2DC87612EK520411B",
  278. "rel": "self",
  279. "method": "GET"
  280. },
  281. {
  282. "href": "https://api.paypal.com/v1/payments/authorization/2DC87612EK520411B/capture",
  283. "rel": "capture",
  284. "method": "POST"
  285. },
  286. {
  287. "href": "https://api.paypal.com/v1/payments/authorization/2DC87612EK520411B/void",
  288. "rel": "void",
  289. "method": "POST"
  290. },
  291. {
  292. "href": "https://api.paypal.com/v1/payments/payment/PAY-36246664YD343335CKHFA4AY",
  293. "rel": "parent_payment",
  294. "method": "GET"
  295. }
  296. ]
  297. },
  298. "links": [
  299. {
  300. "href": "https://api.paypal.com/v1/notfications/webhooks-events/8PT597110X687430LKGECATA",
  301. "rel": "self",
  302. "method": "GET"
  303. },
  304. {
  305. "href": "https://api.paypal.com/v1/notfications/webhooks-events/8PT597110X687430LKGECATA/resend",
  306. "rel": "resend",
  307. "method": "POST"
  308. }
  309. ]
  310. },
  311. {
  312. "id": "HTSPGS710X687430LKGECATA",
  313. "create_time": "2013-06-25T21:41:28Z",
  314. "resource_type": "authorization",
  315. "event_version": "1.0",
  316. "event_type": "PAYMENT.AUTHORIZATION.CREATED",
  317. "summary": "A payment authorization was created",
  318. "resource_version": "1.0",
  319. "resource": {
  320. "id": "HATH7S72EK520411B",
  321. "create_time": "2013-06-25T21:39:15Z",
  322. "update_time": "2013-06-25T21:39:17Z",
  323. "state": "authorized",
  324. "amount": {
  325. "total": "7.47",
  326. "currency": "USD",
  327. "details": {
  328. "subtotal": "7.47"
  329. }
  330. },
  331. "parent_payment": "PAY-ALDSFJ64YD343335CKHFA4AY",
  332. "valid_until": "2013-07-24T21:39:15Z",
  333. "links": [
  334. {
  335. "href": "https://api.paypal.com/v1/payments/authorization/HATH7S72EK520411B",
  336. "rel": "self",
  337. "method": "GET"
  338. },
  339. {
  340. "href": "https://api.paypal.com/v1/payments/authorization/HATH7S72EK520411B/capture",
  341. "rel": "capture",
  342. "method": "POST"
  343. },
  344. {
  345. "href": "https://api.paypal.com/v1/payments/authorization/HATH7S72EK520411B/void",
  346. "rel": "void",
  347. "method": "POST"
  348. },
  349. {
  350. "href": "https://api.paypal.com/v1/payments/payment/PAY-HATH7S72EK520411B",
  351. "rel": "parent_payment",
  352. "method": "GET"
  353. }
  354. ]
  355. },
  356. "links": [
  357. {
  358. "href": "https://api.paypal.com/v1/notfications/webhooks-events/HTSPGS710X687430LKGECATA",
  359. "rel": "self",
  360. "method": "GET"
  361. },
  362. {
  363. "href": "https://api.paypal.com/v1/notfications/webhooks-events/HTSPGS710X687430LKGECATA/resend",
  364. "rel": "resend",
  365. "method": "POST"
  366. }
  367. ]
  368. }
  369. ],
  370. "count": 2,
  371. "links": [
  372. {
  373. "href": "https://api.paypal.com/v1/notifications/webhooks-events/?start_time=2014-08-04T12:46:47-07:00&amp;end_time=2014-09-18T12:46:47-07:00&amp;page_size=2&amp;move_to=next&amp;index_time=2014-09-17T23:07:35Z&amp;index_id=3",
  374. "rel": "next",
  375. "method": "GET"
  376. },
  377. {
  378. "href": "https://api.paypal.com/v1/notifications/webhooks-events/?start_time=2014-08-04T12:46:47-07:00&amp;end_time=2014-09-18T12:46:47-07:00&amp;page_size=2&amp;move_to=previous&amp;index_time=2014-09-17T23:07:35Z&amp;index_id=0",
  379. "rel": "previous",
  380. "method": "GET"
  381. }
  382. ]
  383. }', true);
  384. }
  385. /**
  386. * @return array
  387. */
  388. private function mockGetWebHookEventResponse(): array
  389. {
  390. return Utils::jsonDecode('{
  391. "id": "8PT597110X687430LKGECATA",
  392. "create_time": "2013-06-25T21:41:28Z",
  393. "resource_type": "authorization",
  394. "event_version": "1.0",
  395. "event_type": "PAYMENT.AUTHORIZATION.CREATED",
  396. "summary": "A payment authorization was created",
  397. "resource_version": "1.0",
  398. "resource": {
  399. "id": "2DC87612EK520411B",
  400. "create_time": "2013-06-25T21:39:15Z",
  401. "update_time": "2013-06-25T21:39:17Z",
  402. "state": "authorized",
  403. "amount": {
  404. "total": "7.47",
  405. "currency": "USD",
  406. "details": {
  407. "subtotal": "7.47"
  408. }
  409. },
  410. "parent_payment": "PAY-36246664YD343335CKHFA4AY",
  411. "valid_until": "2013-07-24T21:39:15Z",
  412. "links": [
  413. {
  414. "href": "https://api.paypal.com/v1/payments/authorization/2DC87612EK520411B",
  415. "rel": "self",
  416. "method": "GET"
  417. },
  418. {
  419. "href": "https://api.paypal.com/v1/payments/authorization/2DC87612EK520411B/capture",
  420. "rel": "capture",
  421. "method": "POST"
  422. },
  423. {
  424. "href": "https://api.paypal.com/v1/payments/authorization/2DC87612EK520411B/void",
  425. "rel": "void",
  426. "method": "POST"
  427. },
  428. {
  429. "href": "https://api.paypal.com/v1/payments/payment/PAY-36246664YD343335CKHFA4AY",
  430. "rel": "parent_payment",
  431. "method": "GET"
  432. }
  433. ]
  434. },
  435. "links": [
  436. {
  437. "href": "https://api.paypal.com/v1/notfications/webhooks-events/8PT597110X687430LKGECATA",
  438. "rel": "self",
  439. "method": "GET"
  440. },
  441. {
  442. "href": "https://api.paypal.com/v1/notfications/webhooks-events/8PT597110X687430LKGECATA/resend",
  443. "rel": "resend",
  444. "method": "POST"
  445. }
  446. ]
  447. }', true);
  448. }
  449. /**
  450. * @return array
  451. */
  452. private function mockResendWebHookEventNotificationResponse(): array
  453. {
  454. return Utils::jsonDecode('{
  455. "id": "8PT597110X687430LKGECATA",
  456. "create_time": "2013-06-25T21:41:28Z",
  457. "resource_type": "authorization",
  458. "event_version": "1.0",
  459. "event_type": "PAYMENT.AUTHORIZATION.CREATED",
  460. "summary": "A payment authorization was created",
  461. "resource_version": "1.0",
  462. "resource": {
  463. "id": "2DC87612EK520411B",
  464. "create_time": "2013-06-25T21:39:15Z",
  465. "update_time": "2013-06-25T21:39:17Z",
  466. "state": "authorized",
  467. "amount": {
  468. "total": "7.47",
  469. "currency": "USD",
  470. "details": {
  471. "subtotal": "7.47"
  472. }
  473. },
  474. "parent_payment": "PAY-36246664YD343335CKHFA4AY",
  475. "valid_until": "2013-07-24T21:39:15Z",
  476. "links": [
  477. {
  478. "href": "https://api.paypal.com/v1/payments/authorization/2DC87612EK520411B",
  479. "rel": "self",
  480. "method": "GET"
  481. },
  482. {
  483. "href": "https://api.paypal.com/v1/payments/authorization/2DC87612EK520411B/capture",
  484. "rel": "capture",
  485. "method": "POST"
  486. },
  487. {
  488. "href": "https://api.paypal.com/v1/payments/authorization/2DC87612EK520411B/void",
  489. "rel": "void",
  490. "method": "POST"
  491. },
  492. {
  493. "href": "https://api.paypal.com/v1/payments/payment/PAY-36246664YD343335CKHFA4AY",
  494. "rel": "parent_payment",
  495. "method": "GET"
  496. }
  497. ]
  498. },
  499. "links": [
  500. {
  501. "href": "https://api.paypal.com/v1/notfications/webhooks-events/8PT597110X687430LKGECATA",
  502. "rel": "self",
  503. "method": "GET"
  504. },
  505. {
  506. "href": "https://api.paypal.com/v1/notfications/webhooks-events/8PT597110X687430LKGECATA/resend",
  507. "rel": "resend",
  508. "method": "POST"
  509. }
  510. ]
  511. }', true);
  512. }
  513. /**
  514. * @return array
  515. */
  516. private function mockVerifyWebHookSignatureResponse(): array
  517. {
  518. return Utils::jsonDecode('{
  519. "verification_status": "SUCCESS"
  520. }', true);
  521. }
  522. }