AdapterFeatureTest.php 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698
  1. <?php
  2. namespace Srmklive\PayPal\Tests\Feature;
  3. use Carbon\Carbon;
  4. use PHPUnit\Framework\Attributes\Test;
  5. use PHPUnit\Framework\TestCase;
  6. use Srmklive\PayPal\Services\PayPal as PayPalClient;
  7. use Srmklive\PayPal\Tests\MockClientClasses;
  8. use Srmklive\PayPal\Tests\MockRequestPayloads;
  9. use Srmklive\PayPal\Tests\MockResponsePayloads;
  10. class AdapterFeatureTest extends TestCase
  11. {
  12. use MockClientClasses;
  13. use MockRequestPayloads;
  14. use MockResponsePayloads;
  15. /** @var string */
  16. protected static string $access_token = '';
  17. /** @var string */
  18. protected static string $product_id = '';
  19. /** @var PayPalClient */
  20. protected PayPalClient $client;
  21. protected function setUp(): void
  22. {
  23. try {
  24. $this->client = new PayPalClient($this->getApiCredentials());
  25. } catch (\Exception $e) {
  26. }
  27. parent::setUp();
  28. }
  29. #[Test]
  30. public function it_returns_error_if_invalid_credentials_are_used_to_get_access_token(): void
  31. {
  32. $this->client = new PayPalClient($this->getMockCredentials());
  33. $response = $this->client->getAccessToken();
  34. $this->assertIsArray($response['error']);
  35. $this->assertArrayHasKey('error', $response);
  36. }
  37. #[Test]
  38. public function it_can_get_access_token(): void
  39. {
  40. $this->client->setClient(
  41. $this->mock_http_client(
  42. $this->mockAccessTokenResponse()
  43. )
  44. );
  45. $response = $this->client->getAccessToken();
  46. self::$access_token = $response['access_token'];
  47. $this->assertArrayHasKey('access_token', $response);
  48. $this->assertNotEmpty($response['access_token']);
  49. }
  50. #[Test]
  51. public function it_can_create_a_billing_plan(): void
  52. {
  53. $this->client->setAccessToken([
  54. 'access_token' => self::$access_token,
  55. 'token_type' => 'Bearer',
  56. ]);
  57. $this->client->setClient(
  58. $this->mock_http_client(
  59. $this->mockCreatePlansResponse()
  60. )
  61. );
  62. $expectedParams = $this->createPlanParams();
  63. try {
  64. $response = $this->client->setRequestHeader('PayPal-Request-Id', 'some-request-id')->createPlan($expectedParams);
  65. } catch (\Throwable $e) {
  66. }
  67. $this->assertNotEmpty($response);
  68. $this->assertArrayHasKey('id', $response);
  69. }
  70. #[Test]
  71. public function it_can_list_billing_plans(): void
  72. {
  73. $this->client->setAccessToken([
  74. 'access_token' => self::$access_token,
  75. 'token_type' => 'Bearer',
  76. ]);
  77. $this->client->setClient(
  78. $this->mock_http_client(
  79. $this->mockListPlansResponse()
  80. )
  81. );
  82. $response = $this->client->listPlans();
  83. $this->assertNotEmpty($response);
  84. $this->assertArrayHasKey('plans', $response);
  85. }
  86. #[Test]
  87. public function it_can_update_a_billing_plan(): void
  88. {
  89. $this->client->setAccessToken([
  90. 'access_token' => self::$access_token,
  91. 'token_type' => 'Bearer',
  92. ]);
  93. $this->client->setClient(
  94. $this->mock_http_client(false)
  95. );
  96. $expectedParams = $this->updatePlanParams();
  97. $response = $this->client->updatePlan('P-7GL4271244454362WXNWU5NQ', $expectedParams);
  98. $this->assertEmpty($response);
  99. }
  100. #[Test]
  101. public function it_can_show_details_for_a_billing_plan(): void
  102. {
  103. $this->client->setAccessToken([
  104. 'access_token' => self::$access_token,
  105. 'token_type' => 'Bearer',
  106. ]);
  107. $this->client->setClient(
  108. $this->mock_http_client(
  109. $this->mockGetPlansResponse()
  110. )
  111. );
  112. $response = $this->client->showPlanDetails('P-5ML4271244454362WXNWU5NQ');
  113. $this->assertNotEmpty($response);
  114. $this->assertArrayHasKey('id', $response);
  115. }
  116. #[Test]
  117. public function it_can_activate_a_billing_plan(): void
  118. {
  119. $this->client->setAccessToken([
  120. 'access_token' => self::$access_token,
  121. 'token_type' => 'Bearer',
  122. ]);
  123. $this->client->setClient(
  124. $this->mock_http_client(false)
  125. );
  126. $response = $this->client->activatePlan('P-7GL4271244454362WXNWU5NQ');
  127. $this->assertEmpty($response);
  128. }
  129. #[Test]
  130. public function it_can_deactivate_a_billing_plan(): void
  131. {
  132. $this->client->setAccessToken([
  133. 'access_token' => self::$access_token,
  134. 'token_type' => 'Bearer',
  135. ]);
  136. $this->client->setClient(
  137. $this->mock_http_client(false)
  138. );
  139. $response = $this->client->deactivatePlan('P-7GL4271244454362WXNWU5NQ');
  140. $this->assertEmpty($response);
  141. }
  142. #[Test]
  143. public function it_can_update_pricing_for_a_billing_plan(): void
  144. {
  145. $this->client->setAccessToken([
  146. 'access_token' => self::$access_token,
  147. 'token_type' => 'Bearer',
  148. ]);
  149. $this->client->setClient(
  150. $this->mock_http_client(false)
  151. );
  152. $expectedParams = $this->updatePlanPricingParams();
  153. $response = $this->client->updatePlanPricing('P-2UF78835G6983425GLSM44MA', $expectedParams);
  154. $this->assertEmpty($response);
  155. }
  156. #[Test]
  157. public function it_can_list_products(): void
  158. {
  159. $this->client->setAccessToken([
  160. 'access_token' => self::$access_token,
  161. 'token_type' => 'Bearer',
  162. ]);
  163. $this->client->setClient(
  164. $this->mock_http_client(
  165. $this->mockListCatalogProductsResponse()
  166. )
  167. );
  168. $response = $this->client->listProducts();
  169. $this->assertNotEmpty($response);
  170. $this->assertArrayHasKey('products', $response);
  171. }
  172. #[Test]
  173. public function it_can_create_a_product(): void
  174. {
  175. $this->client->setAccessToken([
  176. 'access_token' => self::$access_token,
  177. 'token_type' => 'Bearer',
  178. ]);
  179. $this->client->setClient(
  180. $this->mock_http_client(
  181. $this->mockCreateCatalogProductsResponse()
  182. )
  183. );
  184. $expectedParams = $this->createProductParams();
  185. $response = $this->client->setRequestHeader('PayPal-Request-Id', 'product-request-'.time())->createProduct($expectedParams);
  186. self::$product_id = $response['id'];
  187. $this->assertNotEmpty($response);
  188. $this->assertArrayHasKey('id', $response);
  189. }
  190. #[Test]
  191. public function it_can_update_a_product(): void
  192. {
  193. $this->client->setAccessToken([
  194. 'access_token' => self::$access_token,
  195. 'token_type' => 'Bearer',
  196. ]);
  197. $this->client->setClient(
  198. $this->mock_http_client(false)
  199. );
  200. $expectedParams = $this->updateProductParams();
  201. $response = $this->client->updateProduct(self::$product_id, $expectedParams);
  202. $this->assertEmpty($response);
  203. }
  204. #[Test]
  205. public function it_can_get_details_for_a_product(): void
  206. {
  207. $this->client->setAccessToken([
  208. 'access_token' => self::$access_token,
  209. 'token_type' => 'Bearer',
  210. ]);
  211. $this->client->setClient(
  212. $this->mock_http_client(
  213. $this->mockGetCatalogProductsResponse()
  214. )
  215. );
  216. $response = $this->client->showProductDetails(self::$product_id);
  217. $this->assertNotEmpty($response);
  218. $this->assertArrayHasKey('id', $response);
  219. }
  220. #[Test]
  221. public function it_can_acknowledge_item_is_returned_for_raised_dispute(): void
  222. {
  223. $this->client->setAccessToken([
  224. 'access_token' => self::$access_token,
  225. 'token_type' => 'Bearer',
  226. ]);
  227. $this->client->setClient(
  228. $this->mock_http_client(
  229. $this->mockAcceptDisputesClaimResponse()
  230. )
  231. );
  232. $response = $this->client->acknowledgeItemReturned(
  233. 'PP-D-4012',
  234. 'I have received the item back.',
  235. 'ITEM_RECEIVED'
  236. );
  237. $this->assertNotEmpty($response);
  238. $this->assertArrayHasKey('links', $response);
  239. }
  240. #[Test]
  241. public function it_can_list_disputes(): void
  242. {
  243. $this->client->setAccessToken([
  244. 'access_token' => self::$access_token,
  245. 'token_type' => 'Bearer',
  246. ]);
  247. $this->client->setClient(
  248. $this->mock_http_client(
  249. $this->mockListDisputesResponse()
  250. )
  251. );
  252. $response = $this->client->listDisputes();
  253. $this->assertNotEmpty($response);
  254. $this->assertArrayHasKey('items', $response);
  255. }
  256. #[Test]
  257. public function it_can_partially_update_a_dispute(): void
  258. {
  259. $this->client->setAccessToken([
  260. 'access_token' => self::$access_token,
  261. 'token_type' => 'Bearer',
  262. ]);
  263. $this->client->setClient(
  264. $this->mock_http_client(false)
  265. );
  266. $expectedParams = $this->updateDisputeParams();
  267. $response = $this->client->updateDispute('PP-D-27803', $expectedParams);
  268. $this->assertEmpty($response);
  269. }
  270. #[Test]
  271. public function it_can_get_details_for_a_dispute(): void
  272. {
  273. $this->client->setAccessToken([
  274. 'access_token' => self::$access_token,
  275. 'token_type' => 'Bearer',
  276. ]);
  277. $this->client->setClient(
  278. $this->mock_http_client(
  279. $this->mockGetDisputesResponse()
  280. )
  281. );
  282. $response = $this->client->showDisputeDetails('PP-D-4012');
  283. $this->assertNotEmpty($response);
  284. $this->assertArrayHasKey('dispute_id', $response);
  285. }
  286. #[Test]
  287. public function it_can_provide_evidence_for_a_dispute_claim(): void
  288. {
  289. $this->client->setAccessToken([
  290. 'access_token' => self::$access_token,
  291. 'token_type' => 'Bearer',
  292. ]);
  293. $this->client->setClient(
  294. $this->mock_http_client(
  295. $this->mockAcceptDisputesClaimResponse()
  296. )
  297. );
  298. $mockFiles = [
  299. __DIR__.'/../Mocks/samples/sample.jpg',
  300. __DIR__.'/../Mocks/samples/sample.png',
  301. __DIR__.'/../Mocks/samples/sample.pdf',
  302. ];
  303. $response = $this->client->provideDisputeEvidence(
  304. 'PP-D-27803',
  305. $mockFiles
  306. );
  307. $this->assertNotEmpty($response);
  308. $this->assertArrayHasKey('links', $response);
  309. $this->markTestIncomplete('Skipping the test');
  310. }
  311. #[Test]
  312. public function it_throws_exception_if_invalid_file_as_evidence_is_provided_for_a_dispute_claim(): void
  313. {
  314. $this->client->setAccessToken([
  315. 'access_token' => self::$access_token,
  316. 'token_type' => 'Bearer',
  317. ]);
  318. $this->client->setClient(
  319. $this->mock_http_client(
  320. $this->mockAcceptDisputesClaimResponse()
  321. )
  322. );
  323. $mockFiles = [
  324. __DIR__.'/../Mocks/samples/sample.txt',
  325. __DIR__.'/../Mocks/samples/sample.pdf',
  326. ];
  327. $this->expectException(\Exception::class);
  328. $this->markTestIncomplete('Skipping the test');
  329. $response = $this->client->provideDisputeEvidence(
  330. 'PP-D-27803',
  331. $mockFiles
  332. );
  333. }
  334. #[Test]
  335. public function it_throws_exception_if_file_size_as_evidence_exceeds_per_file_limit_for_a_dispute_claim(): void
  336. {
  337. $this->client->setAccessToken([
  338. 'access_token' => self::$access_token,
  339. 'token_type' => 'Bearer',
  340. ]);
  341. $this->client->setClient(
  342. $this->mock_http_client(
  343. $this->mockAcceptDisputesClaimResponse()
  344. )
  345. );
  346. $file = __DIR__.'/../Mocks/samples/sample2.pdf';
  347. $mockFiles = [$file];
  348. $this->expectException(\Exception::class);
  349. $this->markTestIncomplete('Skipping the test');
  350. $this->client->provideDisputeEvidence(
  351. 'PP-D-27803',
  352. $mockFiles
  353. );
  354. }
  355. #[Test]
  356. public function it_throws_exception_if_file_size_as_evidence_exceeds_overall_limit_for_a_dispute_claim(): void
  357. {
  358. $this->client->setAccessToken([
  359. 'access_token' => self::$access_token,
  360. 'token_type' => 'Bearer',
  361. ]);
  362. $this->client->setClient(
  363. $this->mock_http_client(
  364. $this->mockAcceptDisputesClaimResponse()
  365. )
  366. );
  367. $file = __DIR__.'/../Mocks/samples/sample2.pdf';
  368. $mockFiles = [$file, $file, $file, $file, $file];
  369. $this->expectException(\Exception::class);
  370. $this->markTestIncomplete('Skipping the test');
  371. $this->client->provideDisputeEvidence(
  372. 'PP-D-27803',
  373. $mockFiles
  374. );
  375. }
  376. #[Test]
  377. public function it_can_offer_to_resolve_dispute_claim(): void
  378. {
  379. $this->client->setAccessToken([
  380. 'access_token' => self::$access_token,
  381. 'token_type' => 'Bearer',
  382. ]);
  383. $this->client->setClient(
  384. $this->mock_http_client(
  385. $this->mockAcceptDisputesClaimResponse()
  386. )
  387. );
  388. $response = $this->client->makeOfferToResolveDispute(
  389. 'PP-D-27803',
  390. 'Offer refund with replacement item.',
  391. 5.99,
  392. 'REFUND_WITH_REPLACEMENT'
  393. );
  394. $this->assertNotEmpty($response);
  395. $this->assertArrayHasKey('links', $response);
  396. }
  397. #[Test]
  398. public function it_can_escalate_dispute_claim(): void
  399. {
  400. $this->client->setAccessToken([
  401. 'access_token' => self::$access_token,
  402. 'token_type' => 'Bearer',
  403. ]);
  404. $this->client->setClient(
  405. $this->mock_http_client(
  406. $this->mockAcceptDisputesClaimResponse()
  407. )
  408. );
  409. $response = $this->client->escalateDisputeToClaim(
  410. 'PP-D-27803',
  411. 'Escalating to PayPal claim for resolution.'
  412. );
  413. $this->assertNotEmpty($response);
  414. $this->assertArrayHasKey('links', $response);
  415. }
  416. #[Test]
  417. public function it_can_accept_dispute_claim(): void
  418. {
  419. $this->client->setAccessToken([
  420. 'access_token' => self::$access_token,
  421. 'token_type' => 'Bearer',
  422. ]);
  423. $this->client->setClient(
  424. $this->mock_http_client(
  425. $this->mockAcceptDisputesClaimResponse()
  426. )
  427. );
  428. $response = $this->client->acceptDisputeClaim(
  429. 'PP-D-27803',
  430. 'Full refund to the customer.'
  431. );
  432. $this->assertNotEmpty($response);
  433. $this->assertArrayHasKey('links', $response);
  434. }
  435. #[Test]
  436. public function it_can_accept_dispute_offer_resolution(): void
  437. {
  438. $this->client->setAccessToken([
  439. 'access_token' => self::$access_token,
  440. 'token_type' => 'Bearer',
  441. ]);
  442. $this->client->setClient(
  443. $this->mock_http_client(
  444. $this->mockAcceptDisputesClaimResponse()
  445. )
  446. );
  447. $response = $this->client->acceptDisputeOfferResolution(
  448. 'PP-D-4012',
  449. 'I am ok with the refund offered.'
  450. );
  451. $this->assertNotEmpty($response);
  452. $this->assertArrayHasKey('links', $response);
  453. }
  454. #[Test]
  455. public function it_can_update_dispute_status(): void
  456. {
  457. $this->client->setAccessToken([
  458. 'access_token' => self::$access_token,
  459. 'token_type' => 'Bearer',
  460. ]);
  461. $this->client->setClient(
  462. $this->mock_http_client(
  463. $this->mockAcceptDisputesClaimResponse()
  464. )
  465. );
  466. $response = $this->client->updateDisputeStatus(
  467. 'PP-D-4012',
  468. true
  469. );
  470. $this->assertNotEmpty($response);
  471. $this->assertArrayHasKey('links', $response);
  472. }
  473. #[Test]
  474. public function it_can_settle_dispute(): void
  475. {
  476. $this->client->setAccessToken([
  477. 'access_token' => self::$access_token,
  478. 'token_type' => 'Bearer',
  479. ]);
  480. $this->client->setClient(
  481. $this->mock_http_client(
  482. $this->mockAcceptDisputesClaimResponse()
  483. )
  484. );
  485. $response = $this->client->settleDispute(
  486. 'PP-D-4012',
  487. true
  488. );
  489. $this->assertNotEmpty($response);
  490. $this->assertArrayHasKey('links', $response);
  491. }
  492. #[Test]
  493. public function it_can_decline_dispute_offer_resolution(): void
  494. {
  495. $this->client->setAccessToken([
  496. 'access_token' => self::$access_token,
  497. 'token_type' => 'Bearer',
  498. ]);
  499. $this->client->setClient(
  500. $this->mock_http_client(
  501. $this->mockAcceptDisputesClaimResponse()
  502. )
  503. );
  504. $response = $this->client->declineDisputeOfferResolution(
  505. 'PP-D-4012',
  506. 'I am not ok with the refund offered.'
  507. );
  508. $this->assertNotEmpty($response);
  509. $this->assertArrayHasKey('links', $response);
  510. }
  511. #[Test]
  512. public function it_can_generate_unique_invoice_number(): void
  513. {
  514. $this->client->setAccessToken([
  515. 'access_token' => self::$access_token,
  516. 'token_type' => 'Bearer',
  517. ]);
  518. $this->client->setClient(
  519. $this->mock_http_client(
  520. $this->mockGenerateInvoiceNumberResponse()
  521. )
  522. );
  523. $response = $this->client->generateInvoiceNumber();
  524. $this->assertNotEmpty($response);
  525. $this->assertArrayHasKey('invoice_number', $response);
  526. }
  527. #[Test]
  528. public function it_can_create_a_draft_invoice(): void
  529. {
  530. $this->client->setAccessToken([
  531. 'access_token' => self::$access_token,
  532. 'token_type' => 'Bearer',
  533. ]);
  534. $this->client->setClient(
  535. $this->mock_http_client(
  536. $this->mockCreateInvoicesResponse()
  537. )
  538. );
  539. $expectedParams = $this->createInvoiceParams();
  540. $response = $this->client->createInvoice($expectedParams);
  541. $this->assertNotEmpty($response);
  542. $this->assertArrayHasKey('id', $response);
  543. }
  544. #[Test]
  545. public function it_can_list_invoices(): void
  546. {
  547. $this->client->setAccessToken([
  548. 'access_token' => self::$access_token,
  549. 'token_type' => 'Bearer',
  550. ]);
  551. $this->client->setClient(
  552. $this->mock_http_client(
  553. $this->mockListInvoicesResponse()
  554. )
  555. );
  556. $response = $this->client->listInvoices();
  557. $this->assertArrayHasKey('total_pages', $response);
  558. $this->assertArrayHasKey('total_items', $response);
  559. }
  560. #[Test]
  561. public function it_can_delete_an_invoice(): void
  562. {
  563. $this->client->setAccessToken([
  564. 'access_token' => self::$access_token,
  565. 'token_type' => 'Bearer',
  566. ]);
  567. $this->client->setClient(
  568. $this->mock_http_client(false)
  569. );
  570. $response = $this->client->deleteInvoice('INV2-Z56S-5LLA-Q52L-CPZ5');
  571. $this->assertEmpty($response);
  572. }
  573. #[Test]
  574. public function it_can_update_an_invoice(): void
  575. {
  576. $this->client->setAccessToken([
  577. 'access_token' => self::$access_token,
  578. 'token_type' => 'Bearer',
  579. ]);
  580. $this->client->setClient(
  581. $this->mock_http_client(
  582. $this->mockUpdateInvoicesResponse()
  583. )
  584. );
  585. $expectedParams = $this->updateInvoiceParams();
  586. $response = $this->client->updateInvoice('INV2-Z56S-5LLA-Q52L-CPZ5', $expectedParams);
  587. $this->assertNotEmpty($response);
  588. $this->assertArrayHasKey('id', $response);
  589. }
  590. #[Test]
  591. public function it_can_show_details_for_an_invoice(): void
  592. {
  593. $this->client->setAccessToken([
  594. 'access_token' => self::$access_token,
  595. 'token_type' => 'Bearer',
  596. ]);
  597. $this->client->setClient(
  598. $this->mock_http_client(
  599. $this->mockGetInvoicesResponse()
  600. )
  601. );
  602. $response = $this->client->showInvoiceDetails('INV2-Z56S-5LLA-Q52L-CPZ5');
  603. $this->assertNotEmpty($response);
  604. $this->assertArrayHasKey('id', $response);
  605. }
  606. #[Test]
  607. public function it_can_cancel_an_invoice(): void
  608. {
  609. $this->client->setAccessToken([
  610. 'access_token' => self::$access_token,
  611. 'token_type' => 'Bearer',
  612. ]);
  613. $this->client->setClient(
  614. $this->mock_http_client(false)
  615. );
  616. $expectedParams = $this->cancelInvoiceParams();
  617. $response = $this->client->cancelInvoice(
  618. 'INV2-Z56S-5LLA-Q52L-CPZ5',
  619. 'Payment due for the invoice #ABC-123',
  620. 'Please pay before the due date to avoid incurring late payment charges which will be adjusted in the next bill generated.',
  621. true,
  622. true,
  623. [
  624. 'customer-a@example.com',
  625. 'customer@example.com',
  626. ]
  627. );
  628. $this->assertEmpty($response);
  629. }
  630. #[Test]
  631. public function it_can_generate_qr_code_for_invoice(): void
  632. {
  633. $this->client->setAccessToken([
  634. 'access_token' => self::$access_token,
  635. 'token_type' => 'Bearer',
  636. ]);
  637. $this->client->setClient(
  638. $this->mock_http_client(
  639. $this->mockGenerateInvoiceQRCodeResponse()
  640. )
  641. );
  642. $response = $this->client->generateQRCodeInvoice('INV2-Z56S-5LLA-Q52L-CPZ5');
  643. $this->assertNotEmpty($response);
  644. }
  645. #[Test]
  646. public function it_can_register_payment_for_invoice(): void
  647. {
  648. $this->client->setAccessToken([
  649. 'access_token' => self::$access_token,
  650. 'token_type' => 'Bearer',
  651. ]);
  652. $this->client->setClient(
  653. $this->mock_http_client(
  654. $this->mockInvoiceRegisterPaymentResponse()
  655. )
  656. );
  657. $response = $this->client->registerPaymentInvoice('INV2-Z56S-5LLA-Q52L-CPZ5', '2018-05-01', 'BANK_TRANSFER', 10.00);
  658. $this->assertNotEmpty($response);
  659. $this->assertArrayHasKey('payment_id', $response);
  660. }
  661. #[Test]
  662. public function it_can_delete_payment_for_invoice(): void
  663. {
  664. $this->client->setAccessToken([
  665. 'access_token' => self::$access_token,
  666. 'token_type' => 'Bearer',
  667. ]);
  668. $this->client->setClient(
  669. $this->mock_http_client(false)
  670. );
  671. $response = $this->client->deleteExternalPaymentInvoice('INV2-Z56S-5LLA-Q52L-CPZ5', 'EXTR-86F38350LX4353815');
  672. $this->assertEmpty($response);
  673. }
  674. #[Test]
  675. public function it_can_refund_payment_for_invoice(): void
  676. {
  677. $this->client->setAccessToken([
  678. 'access_token' => self::$access_token,
  679. 'token_type' => 'Bearer',
  680. ]);
  681. $this->client->setClient(
  682. $this->mock_http_client(
  683. $this->mockInvoiceRefundPaymentResponse()
  684. )
  685. );
  686. $response = $this->client->refundInvoice('INV2-Z56S-5LLA-Q52L-CPZ5', '2018-05-01', 'BANK_TRANSFER', 5.00);
  687. $this->assertNotEmpty($response);
  688. $this->assertArrayHasKey('refund_id', $response);
  689. }
  690. #[Test]
  691. public function it_can_delete_refund_for_invoice(): void
  692. {
  693. $this->client->setAccessToken([
  694. 'access_token' => self::$access_token,
  695. 'token_type' => 'Bearer',
  696. ]);
  697. $this->client->setClient(
  698. $this->mock_http_client(false)
  699. );
  700. $response = $this->client->deleteRefundInvoice('INV2-Z56S-5LLA-Q52L-CPZ5', 'EXTR-2LG703375E477444T');
  701. $this->assertEmpty($response);
  702. }
  703. #[Test]
  704. public function it_can_send_an_invoice(): void
  705. {
  706. $this->client->setAccessToken([
  707. 'access_token' => self::$access_token,
  708. 'token_type' => 'Bearer',
  709. ]);
  710. $this->client->setClient(
  711. $this->mock_http_client(false)
  712. );
  713. $response = $this->client->sendInvoice(
  714. 'INV2-Z56S-5LLA-Q52L-CPZ5',
  715. 'Payment due for the invoice #ABC-123',
  716. 'Please pay before the due date to avoid incurring late payment charges which will be adjusted in the next bill generated.',
  717. true,
  718. true,
  719. [
  720. 'customer-a@example.com',
  721. 'customer@example.com',
  722. ]
  723. );
  724. $this->assertEmpty($response);
  725. }
  726. #[Test]
  727. public function it_can_send_reminder_for_an_invoice(): void
  728. {
  729. $this->client->setAccessToken([
  730. 'access_token' => self::$access_token,
  731. 'token_type' => 'Bearer',
  732. ]);
  733. $this->client->setClient(
  734. $this->mock_http_client(false)
  735. );
  736. $response = $this->client->sendInvoiceReminder(
  737. 'INV2-Z56S-5LLA-Q52L-CPZ5',
  738. 'Reminder: Payment due for the invoice #ABC-123',
  739. 'Please pay before the due date to avoid incurring late payment charges which will be adjusted in the next bill generated.',
  740. true,
  741. true,
  742. [
  743. 'customer-a@example.com',
  744. 'customer@example.com',
  745. ]
  746. );
  747. $this->assertEmpty($response);
  748. }
  749. #[Test]
  750. public function it_can_create_invoice_template(): void
  751. {
  752. $this->client->setAccessToken([
  753. 'access_token' => self::$access_token,
  754. 'token_type' => 'Bearer',
  755. ]);
  756. $this->client->setClient(
  757. $this->mock_http_client(
  758. $this->mockCreateInvoiceTemplateResponse()
  759. )
  760. );
  761. $expectedParams = $this->mockCreateInvoiceTemplateParams();
  762. $response = $this->client->createInvoiceTemplate($expectedParams);
  763. $this->assertNotEmpty($response);
  764. $this->assertArrayHasKey('id', $response);
  765. }
  766. #[Test]
  767. public function it_can_list_invoice_templates(): void
  768. {
  769. $this->client->setAccessToken([
  770. 'access_token' => self::$access_token,
  771. 'token_type' => 'Bearer',
  772. ]);
  773. $this->client->setClient(
  774. $this->mock_http_client(
  775. $this->mockListInvoiceTemplateResponse()
  776. )
  777. );
  778. $response = $this->client->listInvoiceTemplates();
  779. $this->assertNotEmpty($response);
  780. $this->assertArrayHasKey('templates', $response);
  781. }
  782. #[Test]
  783. public function it_can_delete_an_invoice_template(): void
  784. {
  785. $this->client->setAccessToken([
  786. 'access_token' => self::$access_token,
  787. 'token_type' => 'Bearer',
  788. ]);
  789. $this->client->setClient(
  790. $this->mock_http_client(false)
  791. );
  792. $response = $this->client->deleteInvoiceTemplate('TEMP-19V05281TU309413B');
  793. $this->assertEmpty($response);
  794. }
  795. #[Test]
  796. public function it_can_update_an_invoice_template(): void
  797. {
  798. $this->client->setAccessToken([
  799. 'access_token' => self::$access_token,
  800. 'token_type' => 'Bearer',
  801. ]);
  802. $this->client->setClient(
  803. $this->mock_http_client(
  804. $this->mockUpdateInvoiceTemplateResponse()
  805. )
  806. );
  807. $expectedParams = $this->mockUpdateInvoiceTemplateParams();
  808. $response = $this->client->updateInvoiceTemplate('TEMP-19V05281TU309413B', $expectedParams);
  809. $this->assertNotEmpty($response);
  810. $this->assertArrayHasKey('id', $response);
  811. }
  812. #[Test]
  813. public function it_can_get_details_for_an_invoice_template(): void
  814. {
  815. $this->client->setAccessToken([
  816. 'access_token' => self::$access_token,
  817. 'token_type' => 'Bearer',
  818. ]);
  819. $this->client->setClient(
  820. $this->mock_http_client(
  821. $this->mockGetInvoiceTemplateResponse()
  822. )
  823. );
  824. $response = $this->client->showInvoiceTemplateDetails('TEMP-19V05281TU309413B');
  825. $this->assertNotEmpty($response);
  826. $this->assertArrayHasKey('id', $response);
  827. }
  828. #[Test]
  829. public function it_can_search_invoices(): void
  830. {
  831. $this->client->setAccessToken([
  832. 'access_token' => self::$access_token,
  833. 'token_type' => 'Bearer',
  834. ]);
  835. $this->client->setClient(
  836. $this->mock_http_client(
  837. $this->mockSearchInvoicesResponse()
  838. )
  839. );
  840. $response = $this->client->searchInvoices();
  841. $this->assertArrayHasKey('total_pages', $response);
  842. $this->assertArrayHasKey('total_items', $response);
  843. }
  844. #[Test]
  845. public function it_can_search_invoices_with_custom_filters(): void
  846. {
  847. $this->client->setAccessToken([
  848. 'access_token' => self::$access_token,
  849. 'token_type' => 'Bearer',
  850. ]);
  851. $this->client->setClient(
  852. $this->mock_http_client(
  853. $this->mockSearchInvoicesResponse()
  854. )
  855. );
  856. $response = $this->client
  857. ->addInvoiceFilterByRecipientEmail('bill-me@example.com')
  858. ->addInvoiceFilterByRecipientFirstName('John')
  859. ->addInvoiceFilterByRecipientLastName('Doe')
  860. ->addInvoiceFilterByRecipientBusinessName('Acme Inc.')
  861. ->addInvoiceFilterByInvoiceNumber('#123')
  862. ->addInvoiceFilterByInvoiceStatus(['PAID', 'MARKED_AS_PAID'])
  863. ->addInvoiceFilterByReferenceorMemo('deal-ref')
  864. ->addInvoiceFilterByCurrencyCode('USD')
  865. ->addInvoiceFilterByAmountRange(30, 50)
  866. ->addInvoiceFilterByDateRange('2018-06-01', '2018-06-21', 'invoice_date')
  867. ->addInvoiceFilterByArchivedStatus(false)
  868. ->addInvoiceFilterByFields(['items', 'payments', 'refunds'])
  869. ->searchInvoices();
  870. $this->assertArrayHasKey('total_pages', $response);
  871. $this->assertArrayHasKey('total_items', $response);
  872. $this->assertArrayHasKey('items', $response);
  873. }
  874. #[Test]
  875. public function it_throws_exception_on_search_invoices_with_invalid_status(): void
  876. {
  877. $this->client->setAccessToken([
  878. 'access_token' => self::$access_token,
  879. 'token_type' => 'Bearer',
  880. ]);
  881. $this->client->setClient(
  882. $this->mock_http_client(
  883. $this->mockSearchInvoicesResponse()
  884. )
  885. );
  886. $this->expectException(\Exception::class);
  887. $response = $this->client
  888. ->addInvoiceFilterByInvoiceStatus(['DECLINED'])
  889. ->searchInvoices();
  890. }
  891. #[Test]
  892. public function it_throws_exception_on_search_invoices_with_invalid_amount_ranges(): void
  893. {
  894. $this->client->setAccessToken([
  895. 'access_token' => self::$access_token,
  896. 'token_type' => 'Bearer',
  897. ]);
  898. $this->client->setClient(
  899. $this->mock_http_client(
  900. $this->mockSearchInvoicesResponse()
  901. )
  902. );
  903. $filters = $this->invoiceSearchParams();
  904. $this->expectException(\Exception::class);
  905. $response = $this->client
  906. ->addInvoiceFilterByAmountRange(50, 30)
  907. ->searchInvoices();
  908. }
  909. #[Test]
  910. public function it_throws_exception_on_search_invoices_with_invalid_date_ranges(): void
  911. {
  912. $this->client->setAccessToken([
  913. 'access_token' => self::$access_token,
  914. 'token_type' => 'Bearer',
  915. ]);
  916. $this->client->setClient(
  917. $this->mock_http_client(
  918. $this->mockSearchInvoicesResponse()
  919. )
  920. );
  921. $filters = $this->invoiceSearchParams();
  922. $this->expectException(\Exception::class);
  923. $response = $this->client
  924. ->addInvoiceFilterByDateRange('2018-07-01', '2018-06-21', 'invoice_date')
  925. ->searchInvoices();
  926. }
  927. #[Test]
  928. public function it_throws_exception_on_search_invoices_with_invalid_date_range_type(): void
  929. {
  930. $this->client->setAccessToken([
  931. 'access_token' => self::$access_token,
  932. 'token_type' => 'Bearer',
  933. ]);
  934. $this->client->setClient(
  935. $this->mock_http_client(
  936. $this->mockSearchInvoicesResponse()
  937. )
  938. );
  939. $filters = $this->invoiceSearchParams();
  940. $this->expectException(\Exception::class);
  941. $response = $this->client
  942. ->addInvoiceFilterByDateRange('2018-06-01', '2018-06-21', 'declined_date')
  943. ->searchInvoices();
  944. }
  945. #[Test]
  946. public function it_can_get_user_profile_details(): void
  947. {
  948. $this->client->setAccessToken([
  949. 'access_token' => self::$access_token,
  950. 'token_type' => 'Bearer',
  951. ]);
  952. $this->client->setClient(
  953. $this->mock_http_client(
  954. $this->mockShowProfileInfoResponse()
  955. )
  956. );
  957. $response = $this->client->showProfileInfo();
  958. $this->assertArrayHasKey('address', $response);
  959. }
  960. #[Test]
  961. public function it_can_get_list_users(): void
  962. {
  963. $this->client->setAccessToken([
  964. 'access_token' => self::$access_token,
  965. 'token_type' => 'Bearer',
  966. ]);
  967. $this->client->setClient(
  968. $this->mock_http_client(
  969. $this->mocklistUsersResponse()
  970. )
  971. );
  972. $response = $this->client->listUsers();
  973. $this->assertArrayHasKey('Resources', $response);
  974. }
  975. #[Test]
  976. public function it_can_get_user_details()
  977. {
  978. $this->client->setAccessToken([
  979. 'access_token' => self::$access_token,
  980. 'token_type' => 'Bearer',
  981. ]);
  982. $this->client->setClient(
  983. $this->mock_http_client(
  984. $this->mocklistUserResponse()
  985. )
  986. );
  987. $user_id = '7XRNGHV24HQL4';
  988. $response = $this->client->showUserDetails($user_id);
  989. $this->assertArrayHasKey('userName', $response);
  990. }
  991. #[Test]
  992. public function it_can_deleta_a_user(): void
  993. {
  994. $this->client->setAccessToken([
  995. 'access_token' => self::$access_token,
  996. 'token_type' => 'Bearer',
  997. ]);
  998. $this->client->setClient(
  999. $this->mock_http_client(false)
  1000. );
  1001. $user_id = '7XRNGHV24HQL4';
  1002. $response = $this->client->deleteUser($user_id);
  1003. $this->assertEmpty($response);
  1004. }
  1005. #[Test]
  1006. public function it_can_create_merchant_applications(): void
  1007. {
  1008. $this->client->setAccessToken([
  1009. 'access_token' => self::$access_token,
  1010. 'token_type' => 'Bearer',
  1011. ]);
  1012. $this->client->setClient(
  1013. $this->mock_http_client(
  1014. $this->mockCreateMerchantApplicationResponse()
  1015. )
  1016. );
  1017. $response = $this->client->createMerchantApplication(
  1018. 'AGGREGATOR',
  1019. [
  1020. 'https://example.com/callback',
  1021. 'https://example.com/callback2',
  1022. ],
  1023. [
  1024. 'facilitator@example.com',
  1025. 'merchant@example.com',
  1026. ],
  1027. 'WDJJHEBZ4X2LY',
  1028. 'some-open-id'
  1029. );
  1030. $this->assertArrayHasKey('client_name', $response);
  1031. $this->assertArrayHasKey('contacts', $response);
  1032. $this->assertArrayHasKey('redirect_uris', $response);
  1033. }
  1034. #[Test]
  1035. public function it_can_set_account_properties(): void
  1036. {
  1037. $this->client->setAccessToken([
  1038. 'access_token' => self::$access_token,
  1039. 'token_type' => 'Bearer',
  1040. ]);
  1041. $this->client->setClient(
  1042. $this->mock_http_client('')
  1043. );
  1044. $response = $this->client->setAccountProperties($this->mockSetAccountPropertiesParams());
  1045. $this->assertEmpty($response);
  1046. }
  1047. #[Test]
  1048. public function it_can_disable_account_properties(): void
  1049. {
  1050. $this->client->setAccessToken([
  1051. 'access_token' => self::$access_token,
  1052. 'token_type' => 'Bearer',
  1053. ]);
  1054. $this->client->setClient(
  1055. $this->mock_http_client(
  1056. $this->mockUpdateOrdersResponse()
  1057. )
  1058. );
  1059. $response = $this->client->disableAccountProperties();
  1060. $this->assertEmpty($response);
  1061. }
  1062. #[Test]
  1063. public function it_can_get_client_token(): void
  1064. {
  1065. $this->client->setAccessToken([
  1066. 'access_token' => self::$access_token,
  1067. 'token_type' => 'Bearer',
  1068. ]);
  1069. $this->client->setClient(
  1070. $this->mock_http_client(
  1071. $this->mockGetClientTokenResponse()
  1072. )
  1073. );
  1074. $response = $this->client->getClientToken();
  1075. $this->assertArrayHasKey('client_token', $response);
  1076. }
  1077. #[Test]
  1078. public function it_can_create_orders(): void
  1079. {
  1080. $this->client->setAccessToken([
  1081. 'access_token' => self::$access_token,
  1082. 'token_type' => 'Bearer',
  1083. ]);
  1084. $this->client->setClient(
  1085. $this->mock_http_client(
  1086. $this->mockCreateOrdersResponse()
  1087. )
  1088. );
  1089. $filters = $this->createOrderParams();
  1090. $response = $this->client->createOrder($filters);
  1091. $this->assertArrayHasKey('status', $response);
  1092. $this->assertArrayHasKey('id', $response);
  1093. $this->assertArrayHasKey('links', $response);
  1094. }
  1095. #[Test]
  1096. public function it_can_update_orders(): void
  1097. {
  1098. $this->client->setAccessToken([
  1099. 'access_token' => self::$access_token,
  1100. 'token_type' => 'Bearer',
  1101. ]);
  1102. $this->client->setClient(
  1103. $this->mock_http_client(
  1104. $this->mockUpdateOrdersResponse()
  1105. )
  1106. );
  1107. $order_id = '5O190127TN364715T';
  1108. $filters = $this->updateOrderParams();
  1109. $response = $this->client->updateOrder($order_id, $filters);
  1110. $this->assertNotEmpty($response);
  1111. }
  1112. #[Test]
  1113. public function it_can_get_order_details(): void
  1114. {
  1115. $this->client->setAccessToken([
  1116. 'access_token' => self::$access_token,
  1117. 'token_type' => 'Bearer',
  1118. ]);
  1119. $this->client->setClient(
  1120. $this->mock_http_client(
  1121. $this->mockOrderDetailsResponse()
  1122. )
  1123. );
  1124. $order_id = '5O190127TN364715T';
  1125. $response = $this->client->showOrderDetails($order_id);
  1126. $this->assertArrayHasKey('status', $response);
  1127. $this->assertArrayHasKey('id', $response);
  1128. $this->assertArrayHasKey('intent', $response);
  1129. $this->assertArrayHasKey('payment_source', $response);
  1130. $this->assertArrayHasKey('purchase_units', $response);
  1131. $this->assertArrayHasKey('create_time', $response);
  1132. $this->assertArrayHasKey('links', $response);
  1133. }
  1134. #[Test]
  1135. public function it_can_authorize_payment_for_an_order(): void
  1136. {
  1137. $this->client->setAccessToken([
  1138. 'access_token' => self::$access_token,
  1139. 'token_type' => 'Bearer',
  1140. ]);
  1141. $this->client->setClient(
  1142. $this->mock_http_client(
  1143. $this->mockOrderPaymentAuthorizedResponse()
  1144. )
  1145. );
  1146. $order_id = '5O190127TN364715T';
  1147. $response = $this->client->authorizePaymentOrder($order_id);
  1148. $this->assertArrayHasKey('status', $response);
  1149. $this->assertArrayHasKey('id', $response);
  1150. $this->assertArrayHasKey('payer', $response);
  1151. $this->assertArrayHasKey('purchase_units', $response);
  1152. $this->assertArrayHasKey('links', $response);
  1153. }
  1154. #[Test]
  1155. public function it_can_create_partner_referral(): void
  1156. {
  1157. $this->client->setAccessToken([
  1158. 'access_token' => self::$access_token,
  1159. 'token_type' => 'Bearer',
  1160. ]);
  1161. $this->client->setClient(
  1162. $this->mock_http_client(
  1163. $this->mockCreatePartnerReferralsResponse()
  1164. )
  1165. );
  1166. $expectedParams = $this->mockCreatePartnerReferralParams();
  1167. $response = $this->client->createPartnerReferral($expectedParams);
  1168. $this->assertArrayHasKey('links', $response);
  1169. }
  1170. #[Test]
  1171. public function it_can_get_referral_details(): void
  1172. {
  1173. $this->client->setAccessToken([
  1174. 'access_token' => self::$access_token,
  1175. 'token_type' => 'Bearer',
  1176. ]);
  1177. $this->client->setClient(
  1178. $this->mock_http_client(
  1179. $this->mockShowReferralDataResponse()
  1180. )
  1181. );
  1182. $partner_referral_id = 'ZjcyODU4ZWYtYTA1OC00ODIwLTk2M2EtOTZkZWQ4NmQwYzI3RU12cE5xa0xMRmk1NWxFSVJIT1JlTFdSbElCbFU1Q3lhdGhESzVQcU9iRT0=';
  1183. $response = $this->client->showReferralData($partner_referral_id);
  1184. $this->assertArrayHasKey('partner_referral_id', $response);
  1185. $this->assertArrayHasKey('referral_data', $response);
  1186. }
  1187. #[Test]
  1188. public function it_can_list_seller_tracking_information(): void
  1189. {
  1190. $this->client->setAccessToken([
  1191. 'access_token' => self::$access_token,
  1192. 'token_type' => 'Bearer',
  1193. ]);
  1194. $this->client->setClient(
  1195. $this->mock_http_client(
  1196. $this->mockListSellerTrackingInformationResponse()
  1197. )
  1198. );
  1199. $partner_id = 'U6E69K99P3G88';
  1200. $tracking_id = 'merchantref1';
  1201. $response = $this->client->listSellerTrackingInformation($partner_id, $tracking_id);
  1202. $this->assertArrayHasKey('merchant_id', $response);
  1203. $this->assertArrayHasKey('tracking_id', $response);
  1204. }
  1205. #[Test]
  1206. public function it_can_show_seller_status(): void
  1207. {
  1208. $this->client->setAccessToken([
  1209. 'access_token' => self::$access_token,
  1210. 'token_type' => 'Bearer',
  1211. ]);
  1212. $this->client->setClient(
  1213. $this->mock_http_client(
  1214. $this->mockShowSellerStatusResponse()
  1215. )
  1216. );
  1217. $partner_id = 'U6E69K99P3G88';
  1218. $merchant_id = '8LQLM2ML4ZTYU';
  1219. $response = $this->client->showSellerStatus($partner_id, $merchant_id);
  1220. $this->assertArrayHasKey('merchant_id', $response);
  1221. }
  1222. #[Test]
  1223. public function it_can_list_merchant_credentials(): void
  1224. {
  1225. $this->client->setAccessToken([
  1226. 'access_token' => self::$access_token,
  1227. 'token_type' => 'Bearer',
  1228. ]);
  1229. $this->client->setClient(
  1230. $this->mock_http_client(
  1231. $this->mockListMerchantCredentialsResponse()
  1232. )
  1233. );
  1234. $partner_id = 'U6E69K99P3G88';
  1235. $response = $this->client->listMerchantCredentials($partner_id);
  1236. $this->assertArrayHasKey('client_id', $response);
  1237. $this->assertArrayHasKey('payer_id', $response);
  1238. }
  1239. #[Test]
  1240. public function it_can_list_web_experience_profiles(): void
  1241. {
  1242. $this->client->setAccessToken([
  1243. 'access_token' => self::$access_token,
  1244. 'token_type' => 'Bearer',
  1245. ]);
  1246. $this->client->setClient(
  1247. $this->mock_http_client(
  1248. $this->mockListWebProfilesResponse()
  1249. )
  1250. );
  1251. $response = $this->client->listWebExperienceProfiles();
  1252. $this->assertNotEmpty($response);
  1253. $this->assertArrayHasKey('id', collect($response)->first());
  1254. }
  1255. #[Test]
  1256. public function it_can_create_web_experience_profile(): void
  1257. {
  1258. $this->client->setAccessToken([
  1259. 'access_token' => self::$access_token,
  1260. 'token_type' => 'Bearer',
  1261. ]);
  1262. $this->client->setClient(
  1263. $this->mock_http_client(
  1264. $this->mockWebProfileResponse()
  1265. )
  1266. );
  1267. $expectedParams = $this->mockCreateWebProfileParams();
  1268. $response = $this->client->setRequestHeader('PayPal-Request-Id', 'some-request-id')->createWebExperienceProfile($expectedParams);
  1269. $this->assertNotEmpty($response);
  1270. $this->assertArrayHasKey('name', $response);
  1271. }
  1272. #[Test]
  1273. public function it_can_delete_web_experience_profile(): void
  1274. {
  1275. $expectedResponse = '';
  1276. $this->client->setAccessToken([
  1277. 'access_token' => self::$access_token,
  1278. 'token_type' => 'Bearer',
  1279. ]);
  1280. $this->client->setClient(
  1281. $this->mock_http_client($expectedResponse)
  1282. );
  1283. $expectedParams = 'XP-A88A-LYLW-8Y3X-E5ER';
  1284. $response = $this->client->deleteWebExperienceProfile($expectedParams);
  1285. $this->assertEmpty($response);
  1286. }
  1287. #[Test]
  1288. public function it_can_partially_update_web_experience_profile(): void
  1289. {
  1290. $expectedResponse = '';
  1291. $expectedParams = $this->partiallyUpdateWebProfileParams();
  1292. $this->client->setAccessToken([
  1293. 'access_token' => self::$access_token,
  1294. 'token_type' => 'Bearer',
  1295. ]);
  1296. $this->client->setClient(
  1297. $this->mock_http_client($expectedResponse)
  1298. );
  1299. $response = $this->client->patchWebExperienceProfile('XP-A88A-LYLW-8Y3X-E5ER', $expectedParams);
  1300. $this->assertEmpty($response);
  1301. }
  1302. #[Test]
  1303. public function it_can_fully_update_web_experience_profile(): void
  1304. {
  1305. $expectedResponse = '';
  1306. $expectedParams = $this->updateWebProfileParams();
  1307. $this->client->setAccessToken([
  1308. 'access_token' => self::$access_token,
  1309. 'token_type' => 'Bearer',
  1310. ]);
  1311. $this->client->setClient(
  1312. $this->mock_http_client($expectedResponse)
  1313. );
  1314. $response = $this->client->updateWebExperienceProfile('XP-A88A-LYLW-8Y3X-E5ER', $expectedParams);
  1315. $this->assertEmpty($response);
  1316. }
  1317. #[Test]
  1318. public function it_can_get_web_experience_profile_details(): void
  1319. {
  1320. $expectedResponse = $this->mockWebProfileResponse();
  1321. $expectedParams = 'XP-A88A-LYLW-8Y3X-E5ER';
  1322. $this->client->setAccessToken([
  1323. 'access_token' => self::$access_token,
  1324. 'token_type' => 'Bearer',
  1325. ]);
  1326. $this->client->setClient(
  1327. $this->mock_http_client($expectedResponse)
  1328. );
  1329. $response = $this->client->showWebExperienceProfileDetails($expectedParams);
  1330. $this->assertNotEmpty($response);
  1331. $this->assertArrayHasKey('name', $response);
  1332. }
  1333. #[Test]
  1334. public function it_can_capture_payment_for_an_order(): void
  1335. {
  1336. $this->client->setAccessToken([
  1337. 'access_token' => self::$access_token,
  1338. 'token_type' => 'Bearer',
  1339. ]);
  1340. $this->client->setClient(
  1341. $this->mock_http_client(
  1342. $this->mockOrderPaymentCapturedResponse()
  1343. )
  1344. );
  1345. $order_id = '5O190127TN364715T';
  1346. $response = $this->client->capturePaymentOrder($order_id);
  1347. $this->assertArrayHasKey('status', $response);
  1348. $this->assertArrayHasKey('id', $response);
  1349. $this->assertArrayHasKey('payer', $response);
  1350. $this->assertArrayHasKey('purchase_units', $response);
  1351. $this->assertArrayHasKey('links', $response);
  1352. }
  1353. #[Test]
  1354. public function it_can_show_details_for_an_authorized_payment(): void
  1355. {
  1356. $this->client->setAccessToken([
  1357. 'access_token' => self::$access_token,
  1358. 'token_type' => 'Bearer',
  1359. ]);
  1360. $this->client->setClient(
  1361. $this->mock_http_client(
  1362. $this->mockGetAuthorizedPaymentDetailsResponse()
  1363. )
  1364. );
  1365. $response = $this->client->showAuthorizedPaymentDetails('0VF52814937998046');
  1366. $this->assertNotEmpty($response);
  1367. $this->assertArrayHasKey('id', $response);
  1368. }
  1369. #[Test]
  1370. public function it_can_capture_an_authorized_payment(): void
  1371. {
  1372. $this->client->setAccessToken([
  1373. 'access_token' => self::$access_token,
  1374. 'token_type' => 'Bearer',
  1375. ]);
  1376. $this->client->setClient(
  1377. $this->mock_http_client(
  1378. $this->mockCaptureAuthorizedPaymentResponse()
  1379. )
  1380. );
  1381. $response = $this->client->captureAuthorizedPayment(
  1382. '0VF52814937998046',
  1383. 'INVOICE-123',
  1384. 10.99,
  1385. 'Payment is due'
  1386. );
  1387. $this->assertNotEmpty($response);
  1388. $this->assertArrayHasKey('id', $response);
  1389. }
  1390. #[Test]
  1391. public function it_can_reauthorize_an_authorized_payment(): void
  1392. {
  1393. $this->client->setAccessToken([
  1394. 'access_token' => self::$access_token,
  1395. 'token_type' => 'Bearer',
  1396. ]);
  1397. $this->client->setClient(
  1398. $this->mock_http_client(
  1399. $this->mockReAuthorizeAuthorizedPaymentResponse()
  1400. )
  1401. );
  1402. $response = $this->client->reAuthorizeAuthorizedPayment('0VF52814937998046', 10.99);
  1403. $this->assertNotEmpty($response);
  1404. $this->assertArrayHasKey('id', $response);
  1405. }
  1406. #[Test]
  1407. public function it_can_void_an_authorized_payment(): void
  1408. {
  1409. $this->client->setAccessToken([
  1410. 'access_token' => self::$access_token,
  1411. 'token_type' => 'Bearer',
  1412. ]);
  1413. $this->client->setClient(
  1414. $this->mock_http_client(false)
  1415. );
  1416. $response = $this->client->voidAuthorizedPayment('0VF52814937998046');
  1417. $this->assertEmpty($response);
  1418. }
  1419. #[Test]
  1420. public function it_can_show_details_for_a_captured_payment(): void
  1421. {
  1422. $this->client->setAccessToken([
  1423. 'access_token' => self::$access_token,
  1424. 'token_type' => 'Bearer',
  1425. ]);
  1426. $this->client->setClient(
  1427. $this->mock_http_client(
  1428. $this->mockGetCapturedPaymentDetailsResponse()
  1429. )
  1430. );
  1431. $response = $this->client->showCapturedPaymentDetails('2GG279541U471931P');
  1432. $this->assertNotEmpty($response);
  1433. $this->assertArrayHasKey('id', $response);
  1434. }
  1435. #[Test]
  1436. public function it_can_refund_a_captured_payment(): void
  1437. {
  1438. $this->client->setAccessToken([
  1439. 'access_token' => self::$access_token,
  1440. 'token_type' => 'Bearer',
  1441. ]);
  1442. $this->client->setClient(
  1443. $this->mock_http_client(
  1444. $this->mockRefundCapturedPaymentResponse()
  1445. )
  1446. );
  1447. $response = $this->client->refundCapturedPayment(
  1448. '2GG279541U471931P',
  1449. 'INVOICE-123',
  1450. 10.99,
  1451. 'Defective product'
  1452. );
  1453. $this->assertNotEmpty($response);
  1454. $this->assertArrayHasKey('id', $response);
  1455. }
  1456. #[Test]
  1457. public function it_can_show_details_for_a_refund(): void
  1458. {
  1459. $this->client->setAccessToken([
  1460. 'access_token' => self::$access_token,
  1461. 'token_type' => 'Bearer',
  1462. ]);
  1463. $this->client->setClient(
  1464. $this->mock_http_client(
  1465. $this->mockGetRefundDetailsResponse()
  1466. )
  1467. );
  1468. $response = $this->client->showRefundDetails('1JU08902781691411');
  1469. $this->assertNotEmpty($response);
  1470. $this->assertArrayHasKey('id', $response);
  1471. }
  1472. #[Test]
  1473. public function it_can_create_batch_payout(): void
  1474. {
  1475. $expectedResponse = $this->mockCreateBatchPayoutResponse();
  1476. $expectedParams = $this->mockCreateBatchPayoutParams();
  1477. $this->client->setAccessToken([
  1478. 'access_token' => self::$access_token,
  1479. 'token_type' => 'Bearer',
  1480. ]);
  1481. $this->client->setClient(
  1482. $this->mock_http_client($expectedResponse)
  1483. );
  1484. $response = $this->client->createBatchPayout($expectedParams);
  1485. $this->assertNotEmpty($response);
  1486. $this->assertArrayHasKey('batch_header', $response);
  1487. }
  1488. #[Test]
  1489. public function it_can_show_batch_payout_details(): void
  1490. {
  1491. $expectedResponse = $this->showBatchPayoutResponse();
  1492. $expectedParams = 'FYXMPQTX4JC9N';
  1493. $this->client->setAccessToken([
  1494. 'access_token' => self::$access_token,
  1495. 'token_type' => 'Bearer',
  1496. ]);
  1497. $this->client->setClient(
  1498. $this->mock_http_client($expectedResponse)
  1499. );
  1500. $response = $this->client->showBatchPayoutDetails($expectedParams);
  1501. $this->assertNotEmpty($response);
  1502. $this->assertArrayHasKey('batch_header', $response);
  1503. $this->assertArrayHasKey('items', $response);
  1504. }
  1505. #[Test]
  1506. public function it_can_show_batch_payout_item_details(): void
  1507. {
  1508. $expectedResponse = $this->showBatchPayoutItemResponse();
  1509. $expectedParams = '8AELMXH8UB2P8';
  1510. $this->client->setAccessToken([
  1511. 'access_token' => self::$access_token,
  1512. 'token_type' => 'Bearer',
  1513. ]);
  1514. $this->client->setClient(
  1515. $this->mock_http_client($expectedResponse)
  1516. );
  1517. $response = $this->client->showPayoutItemDetails($expectedParams);
  1518. $this->assertNotEmpty($response);
  1519. $this->assertArrayHasKey('payout_item_id', $response);
  1520. $this->assertArrayHasKey('payout_batch_id', $response);
  1521. $this->assertArrayHasKey('payout_item', $response);
  1522. }
  1523. #[Test]
  1524. public function it_can_cancel_unclaimed_batch_payout_item(): void
  1525. {
  1526. $expectedResponse = $this->mockCancelUnclaimedBatchItemResponse();
  1527. $expectedParams = '8AELMXH8UB2P8';
  1528. $this->client->setAccessToken([
  1529. 'access_token' => self::$access_token,
  1530. 'token_type' => 'Bearer',
  1531. ]);
  1532. $this->client->setClient(
  1533. $this->mock_http_client($expectedResponse)
  1534. );
  1535. $response = $this->client->cancelUnclaimedPayoutItem($expectedParams);
  1536. $this->assertNotEmpty($response);
  1537. $this->assertArrayHasKey('payout_item_id', $response);
  1538. $this->assertArrayHasKey('payout_batch_id', $response);
  1539. $this->assertArrayHasKey('payout_item', $response);
  1540. }
  1541. #[Test]
  1542. public function it_can_create_referenced_batch_payout(): void
  1543. {
  1544. $expectedResponse = $this->mockCreateReferencedBatchPayoutResponse();
  1545. $expectedParams = $this->mockCreateReferencedBatchPayoutParams();
  1546. $this->client->setAccessToken([
  1547. 'access_token' => self::$access_token,
  1548. 'token_type' => 'Bearer',
  1549. ]);
  1550. $this->client->setClient(
  1551. $this->mock_http_client($expectedResponse)
  1552. );
  1553. $response = $this->client->setRequestHeaders([
  1554. 'PayPal-Request-Id' => 'some-request-id',
  1555. 'PayPal-Partner-Attribution-Id' => 'some-attribution-id',
  1556. ])->createReferencedBatchPayout($expectedParams);
  1557. $this->assertNotEmpty($response);
  1558. $this->assertArrayHasKey('links', $response);
  1559. }
  1560. #[Test]
  1561. public function it_can_list_items_referenced_in_batch_payout(): void
  1562. {
  1563. $expectedResponse = $this->mockShowReferencedBatchPayoutResponse();
  1564. $expectedParams = 'KHbwO28lWlXwi2IlToJ2IYNG4juFv6kpbFx4J9oQ5Hb24RSp96Dk5FudVHd6v4E=';
  1565. $this->client->setAccessToken([
  1566. 'access_token' => self::$access_token,
  1567. 'token_type' => 'Bearer',
  1568. ]);
  1569. $this->client->setClient(
  1570. $this->mock_http_client($expectedResponse)
  1571. );
  1572. $response = $this->client->listItemsReferencedInBatchPayout($expectedParams);
  1573. $this->assertNotEmpty($response);
  1574. $this->assertArrayHasKey('links', $response);
  1575. }
  1576. #[Test]
  1577. public function it_can_create_referenced_batch_payout_item(): void
  1578. {
  1579. $expectedResponse = $this->mockCreateReferencedBatchPayoutItemResponse();
  1580. $expectedParams = $this->mockCreateReferencedBatchPayoutItemParams();
  1581. $this->client->setAccessToken([
  1582. 'access_token' => self::$access_token,
  1583. 'token_type' => 'Bearer',
  1584. ]);
  1585. $this->client->setClient(
  1586. $this->mock_http_client($expectedResponse)
  1587. );
  1588. $response = $this->client->setRequestHeaders([
  1589. 'PayPal-Request-Id' => 'some-request-id',
  1590. 'PayPal-Partner-Attribution-Id' => 'some-attribution-id',
  1591. ])->createReferencedBatchPayoutItem($expectedParams);
  1592. $this->assertNotEmpty($response);
  1593. $this->assertArrayHasKey('links', $response);
  1594. }
  1595. #[Test]
  1596. public function it_can_show_referenced_payout_item_details(): void
  1597. {
  1598. $expectedResponse = $this->mockShowReferencedBatchPayoutItemResponse();
  1599. $expectedParams = 'CDZEC5MJ8R5HY';
  1600. $this->client->setAccessToken([
  1601. 'access_token' => self::$access_token,
  1602. 'token_type' => 'Bearer',
  1603. ]);
  1604. $this->client->setClient(
  1605. $this->mock_http_client($expectedResponse)
  1606. );
  1607. $response = $this->client->setRequestHeader('PayPal-Partner-Attribution-Id', 'some-attribution-id')
  1608. ->showReferencedPayoutItemDetails($expectedParams);
  1609. $this->assertNotEmpty($response);
  1610. $this->assertArrayHasKey('item_id', $response);
  1611. $this->assertArrayHasKey('reference_id', $response);
  1612. }
  1613. #[Test]
  1614. public function it_can_list_transactions(): void
  1615. {
  1616. $this->client->setAccessToken([
  1617. 'access_token' => self::$access_token,
  1618. 'token_type' => 'Bearer',
  1619. ]);
  1620. $this->client->setClient(
  1621. $this->mock_http_client(
  1622. $this->mockListTransactionsResponse()
  1623. )
  1624. );
  1625. $filters = [
  1626. 'start_date' => Carbon::now()->toIso8601String(),
  1627. 'end_date' => Carbon::now()->subDays(30)->toIso8601String(),
  1628. ];
  1629. $response = $this->client->listTransactions($filters);
  1630. $this->assertArrayHasKey('transaction_details', $response);
  1631. $this->assertGreaterThan(0, sizeof($response['transaction_details']));
  1632. }
  1633. #[Test]
  1634. public function it_can_list_account_balances(): void
  1635. {
  1636. $this->client->setAccessToken([
  1637. 'access_token' => self::$access_token,
  1638. 'token_type' => 'Bearer',
  1639. ]);
  1640. $this->client->setClient(
  1641. $this->mock_http_client(
  1642. $this->mockListBalancesResponse()
  1643. )
  1644. );
  1645. $date = Carbon::now()->subDays(30)->toIso8601String();
  1646. $response = $this->client->listBalances($date);
  1647. $this->assertNotEmpty($response);
  1648. }
  1649. #[Test]
  1650. public function it_can_list_account_balances_for_a_different_currency(): void
  1651. {
  1652. $this->client->setAccessToken([
  1653. 'access_token' => self::$access_token,
  1654. 'token_type' => 'Bearer',
  1655. ]);
  1656. $this->client->setClient(
  1657. $this->mock_http_client(
  1658. $this->mockListBalancesResponse()
  1659. )
  1660. );
  1661. $date = Carbon::now()->subDays(30)->toIso8601String();
  1662. $response = $this->client->listBalances($date, 'EUR');
  1663. $this->assertNotEmpty($response);
  1664. }
  1665. #[Test]
  1666. public function it_can_create_a_subscription(): void
  1667. {
  1668. $this->client->setAccessToken([
  1669. 'access_token' => self::$access_token,
  1670. 'token_type' => 'Bearer',
  1671. ]);
  1672. $this->client->setClient(
  1673. $this->mock_http_client(
  1674. $this->mockCreateSubscriptionResponse()
  1675. )
  1676. );
  1677. $expectedParams = $this->mockCreateSubscriptionParams();
  1678. $response = $this->client->createSubscription($expectedParams);
  1679. $this->assertNotEmpty($response);
  1680. $this->assertArrayHasKey('id', $response);
  1681. }
  1682. #[Test]
  1683. public function it_can_update_a_subscription(): void
  1684. {
  1685. $this->client->setAccessToken([
  1686. 'access_token' => self::$access_token,
  1687. 'token_type' => 'Bearer',
  1688. ]);
  1689. $this->client->setClient(
  1690. $this->mock_http_client(false)
  1691. );
  1692. $expectedParams = $this->mockUpdateSubscriptionParams();
  1693. $response = $this->client->updateSubscription('I-BW452GLLEP1G', $expectedParams);
  1694. $this->assertEmpty($response);
  1695. }
  1696. #[Test]
  1697. public function it_can_show_details_for_a_subscription(): void
  1698. {
  1699. $this->client->setAccessToken([
  1700. 'access_token' => self::$access_token,
  1701. 'token_type' => 'Bearer',
  1702. ]);
  1703. $this->client->setClient(
  1704. $this->mock_http_client(
  1705. $this->mockGetSubscriptionDetailsResponse()
  1706. )
  1707. );
  1708. $response = $this->client->showSubscriptionDetails('I-BW452GLLEP1G');
  1709. $this->assertNotEmpty($response);
  1710. $this->assertArrayHasKey('id', $response);
  1711. }
  1712. #[Test]
  1713. public function it_can_activate_a_subscription(): void
  1714. {
  1715. $this->client->setAccessToken([
  1716. 'access_token' => self::$access_token,
  1717. 'token_type' => 'Bearer',
  1718. ]);
  1719. $this->client->setClient(
  1720. $this->mock_http_client(false)
  1721. );
  1722. $response = $this->client->activateSubscription('I-BW452GLLEP1G', 'Reactivating the subscription');
  1723. $this->assertEmpty($response);
  1724. }
  1725. #[Test]
  1726. public function it_can_cancel_a_subscription(): void
  1727. {
  1728. $this->client->setAccessToken([
  1729. 'access_token' => self::$access_token,
  1730. 'token_type' => 'Bearer',
  1731. ]);
  1732. $this->client->setClient(
  1733. $this->mock_http_client(false)
  1734. );
  1735. $response = $this->client->cancelSubscription('I-BW452GLLEP1G', 'Not satisfied with the service');
  1736. $this->assertEmpty($response);
  1737. }
  1738. #[Test]
  1739. public function it_can_suspend_a_subscription()
  1740. {
  1741. $this->client->setAccessToken([
  1742. 'access_token' => self::$access_token,
  1743. 'token_type' => 'Bearer',
  1744. ]);
  1745. $this->client->setClient(
  1746. $this->mock_http_client(false)
  1747. );
  1748. $response = $this->client->suspendSubscription('I-BW452GLLEP1G', 'Item out of stock');
  1749. $this->assertEmpty($response);
  1750. }
  1751. #[Test]
  1752. public function it_can_capture_payment_for_a_subscription(): void
  1753. {
  1754. $this->client->setAccessToken([
  1755. 'access_token' => self::$access_token,
  1756. 'token_type' => 'Bearer',
  1757. ]);
  1758. $this->client->setClient(
  1759. $this->mock_http_client(false)
  1760. );
  1761. $response = $this->client->captureSubscriptionPayment('I-BW452GLLEP1G', 'Charging as the balance reached the limit', 100);
  1762. $this->assertEmpty($response);
  1763. }
  1764. #[Test]
  1765. public function it_can_update_quantity_or_product_for_a_subscription(): void
  1766. {
  1767. $this->client->setAccessToken([
  1768. 'access_token' => self::$access_token,
  1769. 'token_type' => 'Bearer',
  1770. ]);
  1771. $this->client->setClient(
  1772. $this->mock_http_client(
  1773. $this->mockUpdateSubscriptionItemsResponse()
  1774. )
  1775. );
  1776. $expectedParams = $this->mockUpdateSubscriptionItemsParams();
  1777. $response = $this->client->reviseSubscription('I-BW452GLLEP1G', $expectedParams);
  1778. $this->assertNotEmpty($response);
  1779. $this->assertArrayHasKey('plan_id', $response);
  1780. }
  1781. #[Test]
  1782. public function it_can_list_transactions_for_a_subscription(): void
  1783. {
  1784. $this->client->setAccessToken([
  1785. 'access_token' => self::$access_token,
  1786. 'token_type' => 'Bearer',
  1787. ]);
  1788. $this->client->setClient(
  1789. $this->mock_http_client(
  1790. $this->mockListSubscriptionTransactionsResponse()
  1791. )
  1792. );
  1793. $response = $this->client->listSubscriptionTransactions('I-BW452GLLEP1G', '2018-01-21T07:50:20.940Z', '2018-08-22T07:50:20.940Z');
  1794. $this->assertNotEmpty($response);
  1795. $this->assertEquals($response, $this->mockListSubscriptionTransactionsResponse());
  1796. }
  1797. #[Test]
  1798. public function it_can_list_tracking_details(): void
  1799. {
  1800. $this->client->setAccessToken([
  1801. 'access_token' => self::$access_token,
  1802. 'token_type' => 'Bearer',
  1803. ]);
  1804. $this->client->setClient(
  1805. $this->mock_http_client(
  1806. $this->mockGetTrackingDetailsResponse()
  1807. )
  1808. );
  1809. $response = $this->client->listTrackingDetails('8MC585209K746392H-443844607820');
  1810. $this->assertNotEmpty($response);
  1811. $this->assertEquals($response, $this->mockGetTrackingDetailsResponse());
  1812. $this->assertArrayHasKey('transaction_id', $response);
  1813. $this->assertArrayHasKey('tracking_number', $response);
  1814. }
  1815. #[Test]
  1816. public function it_can_get_tracking_details_for_tracking_id(): void
  1817. {
  1818. $this->client->setAccessToken([
  1819. 'access_token' => self::$access_token,
  1820. 'token_type' => 'Bearer',
  1821. ]);
  1822. $this->client->setClient(
  1823. $this->mock_http_client(
  1824. $this->mockGetTrackingDetailsResponse()
  1825. )
  1826. );
  1827. $response = $this->client->showTrackingDetails('8MC585209K746392H-443844607820');
  1828. $this->assertNotEmpty($response);
  1829. $this->assertEquals($response, $this->mockGetTrackingDetailsResponse());
  1830. $this->assertArrayHasKey('tracking_number', $response);
  1831. }
  1832. #[Test]
  1833. public function it_can_update_tracking_details_for_tracking_id(): void
  1834. {
  1835. $this->client->setAccessToken([
  1836. 'access_token' => self::$access_token,
  1837. 'token_type' => 'Bearer',
  1838. ]);
  1839. $this->client->setClient(
  1840. $this->mock_http_client(false)
  1841. );
  1842. $response = $this->client->updateTrackingDetails(
  1843. '8MC585209K746392H-443844607820',
  1844. $this->mockUpdateTrackingDetailsParams()
  1845. );
  1846. $this->assertEmpty($response);
  1847. }
  1848. #[Test]
  1849. public function it_can_create_tracking_in_batches(): void
  1850. {
  1851. $this->client->setAccessToken([
  1852. 'access_token' => self::$access_token,
  1853. 'token_type' => 'Bearer',
  1854. ]);
  1855. $this->client->setClient(
  1856. $this->mock_http_client(
  1857. $this->mockCreateTrackinginBatchesResponse()
  1858. )
  1859. );
  1860. $expectedParams = $this->mockCreateTrackinginBatchesParams();
  1861. $response = $this->client->addBatchTracking($expectedParams);
  1862. $this->assertNotEmpty($response);
  1863. $this->assertArrayHasKey('tracker_identifiers', $response);
  1864. }
  1865. #[Test]
  1866. public function it_can_create_single_tracking_for_single_transaction(): void
  1867. {
  1868. $this->client->setAccessToken([
  1869. 'access_token' => self::$access_token,
  1870. 'token_type' => 'Bearer',
  1871. ]);
  1872. $this->client->setClient(
  1873. $this->mock_http_client(
  1874. $this->mockCreateTrackinginBatchesResponse()
  1875. )
  1876. );
  1877. $expectedParams = $this->mockCreateTrackinginBatchesParams();
  1878. $response = $this->client->addTracking($expectedParams);
  1879. $this->assertNotEmpty($response);
  1880. $this->assertArrayHasKey('tracker_identifiers', $response);
  1881. }
  1882. #[Test]
  1883. public function it_can_list_web_hooks_event_types(): void
  1884. {
  1885. $this->client->setAccessToken([
  1886. 'access_token' => self::$access_token,
  1887. 'token_type' => 'Bearer',
  1888. ]);
  1889. $this->client->setClient(
  1890. $this->mock_http_client(
  1891. $this->mockListWebHookEventsTypesResponse()
  1892. )
  1893. );
  1894. $response = $this->client->listEventTypes();
  1895. $this->assertNotEmpty($response);
  1896. $this->assertArrayHasKey('event_types', $response);
  1897. }
  1898. #[Test]
  1899. public function it_can_list_web_hooks_events(): void
  1900. {
  1901. $this->client->setAccessToken([
  1902. 'access_token' => self::$access_token,
  1903. 'token_type' => 'Bearer',
  1904. ]);
  1905. $this->client->setClient(
  1906. $this->mock_http_client(
  1907. $this->mockWebHookEventsListResponse()
  1908. )
  1909. );
  1910. $response = $this->client->listEvents();
  1911. $this->assertNotEmpty($response);
  1912. $this->assertArrayHasKey('events', $response);
  1913. }
  1914. #[Test]
  1915. public function it_can_show_details_for_a_web_hooks_event(): void
  1916. {
  1917. $this->client->setAccessToken([
  1918. 'access_token' => self::$access_token,
  1919. 'token_type' => 'Bearer',
  1920. ]);
  1921. $this->client->setClient(
  1922. $this->mock_http_client(
  1923. $this->mockGetWebHookEventResponse()
  1924. )
  1925. );
  1926. $response = $this->client->showEventDetails('8PT597110X687430LKGECATA');
  1927. $this->assertNotEmpty($response);
  1928. $this->assertArrayHasKey('id', $response);
  1929. }
  1930. #[Test]
  1931. public function it_can_resend_notification_for_a_web_hooks_event(): void
  1932. {
  1933. $this->client->setAccessToken([
  1934. 'access_token' => self::$access_token,
  1935. 'token_type' => 'Bearer',
  1936. ]);
  1937. $this->client->setClient(
  1938. $this->mock_http_client(
  1939. $this->mockResendWebHookEventNotificationResponse()
  1940. )
  1941. );
  1942. $expectedParams = ['12334456'];
  1943. $response = $this->client->resendEventNotification('8PT597110X687430LKGECATA', $expectedParams);
  1944. $this->assertNotEmpty($response);
  1945. $this->assertArrayHasKey('id', $response);
  1946. }
  1947. #[Test]
  1948. public function it_can_create_a_web_hook(): void
  1949. {
  1950. $this->client->setAccessToken([
  1951. 'access_token' => self::$access_token,
  1952. 'token_type' => 'Bearer',
  1953. ]);
  1954. $this->client->setClient(
  1955. $this->mock_http_client(
  1956. $this->mockCreateWebHookResponse()
  1957. )
  1958. );
  1959. $response = $this->client->createWebHook(
  1960. 'https://example.com/example_webhook',
  1961. ['PAYMENT.AUTHORIZATION.CREATED', 'PAYMENT.AUTHORIZATION.VOIDED']
  1962. );
  1963. $this->assertNotEmpty($response);
  1964. $this->assertArrayHasKey('event_types', $response);
  1965. }
  1966. #[Test]
  1967. public function it_can_list_web_hooks(): void
  1968. {
  1969. $this->client->setAccessToken([
  1970. 'access_token' => self::$access_token,
  1971. 'token_type' => 'Bearer',
  1972. ]);
  1973. $this->client->setClient(
  1974. $this->mock_http_client(
  1975. $this->mockListWebHookResponse()
  1976. )
  1977. );
  1978. $response = $this->client->listWebHooks();
  1979. $this->assertNotEmpty($response);
  1980. $this->assertArrayHasKey('webhooks', $response);
  1981. }
  1982. #[Test]
  1983. public function it_can_delete_a_web_hook(): void
  1984. {
  1985. $this->client->setAccessToken([
  1986. 'access_token' => self::$access_token,
  1987. 'token_type' => 'Bearer',
  1988. ]);
  1989. $this->client->setClient(
  1990. $this->mock_http_client(false)
  1991. );
  1992. $response = $this->client->deleteWebHook('5GP028458E2496506');
  1993. $this->assertEmpty($response);
  1994. }
  1995. #[Test]
  1996. public function it_can_update_a_web_hook(): void
  1997. {
  1998. $this->client->setAccessToken([
  1999. 'access_token' => self::$access_token,
  2000. 'token_type' => 'Bearer',
  2001. ]);
  2002. $this->client->setClient(
  2003. $this->mock_http_client(
  2004. $this->mockUpdateWebHookResponse()
  2005. )
  2006. );
  2007. $expectedParams = $this->mockUpdateWebHookParams();
  2008. $response = $this->client->updateWebHook('0EH40505U7160970P', $expectedParams);
  2009. $this->assertNotEmpty($response);
  2010. $this->assertArrayHasKey('event_types', $response);
  2011. }
  2012. #[Test]
  2013. public function it_can_show_details_for_a_web_hook(): void
  2014. {
  2015. $this->client->setAccessToken([
  2016. 'access_token' => self::$access_token,
  2017. 'token_type' => 'Bearer',
  2018. ]);
  2019. $this->client->setClient(
  2020. $this->mock_http_client(
  2021. $this->mockGetWebHookResponse()
  2022. )
  2023. );
  2024. $response = $this->client->showWebHookDetails('0EH40505U7160970P');
  2025. $this->assertNotEmpty($response);
  2026. $this->assertArrayHasKey('event_types', $response);
  2027. }
  2028. #[Test]
  2029. public function it_can_list_events_for_web_hooks(): void
  2030. {
  2031. $this->client->setAccessToken([
  2032. 'access_token' => self::$access_token,
  2033. 'token_type' => 'Bearer',
  2034. ]);
  2035. $this->client->setClient(
  2036. $this->mock_http_client(
  2037. $this->mockListWebHookEventsResponse()
  2038. )
  2039. );
  2040. $response = $this->client->listWebHookEvents('0EH40505U7160970P');
  2041. $this->assertNotEmpty($response);
  2042. $this->assertArrayHasKey('event_types', $response);
  2043. }
  2044. #[Test]
  2045. public function it_can_verify_web_hook_signature(): void
  2046. {
  2047. $this->client->setAccessToken([
  2048. 'access_token' => self::$access_token,
  2049. 'token_type' => 'Bearer',
  2050. ]);
  2051. $this->client->setClient(
  2052. $this->mock_http_client(
  2053. $this->mockVerifyWebHookSignatureResponse()
  2054. )
  2055. );
  2056. $expectedParams = $this->mockVerifyWebHookSignatureParams();
  2057. $response = $this->client->verifyWebHook($expectedParams);
  2058. $this->assertNotEmpty($response);
  2059. $this->assertArrayHasKey('verification_status', $response);
  2060. }
  2061. #[Test]
  2062. public function it_can_list_payment_methods_source_tokens(): void
  2063. {
  2064. $this->client->setAccessToken([
  2065. 'access_token' => self::$access_token,
  2066. 'token_type' => 'Bearer',
  2067. ]);
  2068. $this->client->setClient(
  2069. $this->mock_http_client(
  2070. $this->mockListPaymentMethodsTokensResponse()
  2071. )
  2072. );
  2073. $response = $this->client->setCustomerSource('customer_4029352050')
  2074. ->listPaymentSourceTokens();
  2075. $this->assertNotEmpty($response);
  2076. $this->assertArrayHasKey('payment_tokens', $response);
  2077. }
  2078. #[Test]
  2079. public function it_can_show_details_for_payment_method_source_token(): void
  2080. {
  2081. $this->client->setAccessToken([
  2082. 'access_token' => self::$access_token,
  2083. 'token_type' => 'Bearer',
  2084. ]);
  2085. $this->client->setClient(
  2086. $this->mock_http_client(
  2087. $this->mockCreatePaymentMethodsTokenResponse()
  2088. )
  2089. );
  2090. $response = $this->client->showPaymentSourceTokenDetails('8kk8451t');
  2091. $this->assertNotEmpty($response);
  2092. $this->assertArrayHasKey('id', $response);
  2093. $this->assertArrayHasKey('customer', $response);
  2094. $this->assertArrayHasKey('payment_source', $response);
  2095. }
  2096. #[Test]
  2097. public function it_can_delete_a_payment_method_source_token(): void
  2098. {
  2099. $this->client->setAccessToken([
  2100. 'access_token' => self::$access_token,
  2101. 'token_type' => 'Bearer',
  2102. ]);
  2103. $this->client->setClient(
  2104. $this->mock_http_client(false)
  2105. );
  2106. $response = $this->client->deletePaymentSourceToken('8kk8451t');
  2107. $this->assertEmpty($response);
  2108. }
  2109. #[Test]
  2110. public function it_can_show_details_for_payment_setup_token(): void
  2111. {
  2112. $this->client->setAccessToken([
  2113. 'access_token' => self::$access_token,
  2114. 'token_type' => 'Bearer',
  2115. ]);
  2116. $this->client->setClient(
  2117. $this->mock_http_client(
  2118. $this->mockListPaymentSetupTokenResponse()
  2119. )
  2120. );
  2121. $response = $this->client->showPaymentSetupTokenDetails('5C991763VB2781612');
  2122. $this->assertNotEmpty($response);
  2123. $this->assertArrayHasKey('id', $response);
  2124. $this->assertArrayHasKey('customer', $response);
  2125. $this->assertArrayHasKey('payment_source', $response);
  2126. }
  2127. }