JFIFxxC      C  " }!1AQa"q2#BR$3br %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz w!1AQaq"2B #3Rbrpaypal/composer.json000064400000002566150364341100010562 0ustar00{ "name": "srmklive/paypal", "type": "library", "description": "Laravel plugin For Processing Payments Through Paypal Express Checkout. Can Be Used Independently With Other Applications.", "keywords": [ "http", "rest", "web service", "paypal", "laravel paypal" ], "license": "MIT", "authors": [ { "name": "Raza Mehdi", "email": "srmk@outlook.com" } ], "autoload": { "psr-4": { "Srmklive\\PayPal\\": "src/" } }, "autoload-dev": { "psr-4": { "Srmklive\\PayPal\\Tests\\": "tests/" } }, "require": { "php": ">=7.2|^8.0", "ext-curl": "*", "guzzlehttp/guzzle": "~7.0", "illuminate/support": "~6.0|~7.0|~8.0|~9.0|^10.0", "nesbot/carbon": "~2.0" }, "require-dev": { "phpstan/phpstan": "^1.10", "phpunit/phpunit": "^8.0|^9.0|^10.0", "symfony/var-dumper": "~5.0" }, "config": { "sort-packages": true }, "extra": { "laravel": { "providers": [ "Srmklive\\PayPal\\Providers\\PayPalServiceProvider" ], "aliases": { "PayPal": "Srmklive\\PayPal\\Facades\\PayPal" } } }, "minimum-stability": "dev", "prefer-stable": true } paypal/phpunit.xml.dist.php8000064400000002265150364341100012065 0ustar00 src/ src/PayPalFacadeAccessor.php src/Traits/PayPalVerifyIPN.php src/Services/Str.php src/Facades/ src/Providers/ tests paypal/tests/MockRequestPayloads.php000064400000001442150364341100013642 0ustar00mockCreateReferencedBatchPayoutResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/payments/referenced-payouts'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', 'PayPal-Request-Id' => 'some-request-id', 'PayPal-Partner-Attribution-Id' => 'some-attribution-id', ], 'json' => $this->mockCreateReferencedBatchPayoutParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_list_items_referenced_in_batch_payout() { $expectedResponse = $this->mockShowReferencedBatchPayoutResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/payments/referenced-payouts/KHbwO28lWlXwi2IlToJ2IYNG4juFv6kpbFx4J9oQ5Hb24RSp96Dk5FudVHd6v4E='; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_create_referenced_batch_payout_item() { $expectedResponse = $this->mockCreateReferencedBatchPayoutItemResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/payments/referenced-payouts-items'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', 'PayPal-Request-Id' => 'some-request-id', 'PayPal-Partner-Attribution-Id' => 'some-attribution-id', ], 'json' => $this->mockCreateReferencedBatchPayoutItemParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_show_referenced_payout_item_details() { $expectedResponse = $this->mockShowReferencedBatchPayoutItemResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/payments/referenced-payouts-items/CDZEC5MJ8R5HY'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', 'PayPal-Request-Id' => 'some-request-id', 'PayPal-Partner-Attribution-Id' => 'some-attribution-id', ], 'json' => $this->mockCreateReferencedBatchPayoutItemParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true)); } } paypal/tests/Unit/Client/PartnerReferralsTest.php000064400000004064150364341100016164 0ustar00mockCreatePartnerReferralsResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/customer/partner-referrals'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], 'json' => $this->mockCreatePartnerReferralParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_get_referral_details() { $expectedResponse = $this->mockShowReferralDataResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/customer/partner-referrals/ZjcyODU4ZWYtYTA1OC00ODIwLTk2M2EtOTZkZWQ4NmQwYzI3RU12cE5xa0xMRmk1NWxFSVJIT1JlTFdSbElCbFU1Q3lhdGhESzVQcU9iRT0='; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true)); } } paypal/tests/Unit/Client/PaymentCapturesTest.php000064400000003770150364341100016032 0ustar00mockGetCapturedPaymentDetailsResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/payments/captures/2GG279541U471931P'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_refund_a_captured_payment() { $expectedResponse = $this->mockRefundCapturedPaymentResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/payments/captures/2GG279541U471931P/refund'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], 'json' => $this->mockRefundCapturedPaymentParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true)); } } paypal/tests/Unit/Client/WebHooksTest.php000064400000011742150364341100014425 0ustar00mockCreateWebHookResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/notifications/webhooks'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], 'json' => $this->mockCreateWebHookParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_list_web_hooks() { $expectedResponse = $this->mockListWebHookResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/notifications/webhooks'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_delete_a_web_hook() { $expectedResponse = ''; $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/notifications/webhooks/5GP028458E2496506'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'delete'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->delete($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_update_a_web_hook() { $expectedResponse = $this->mockUpdateWebHookResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/notifications/webhooks/0EH40505U7160970P'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], 'json' => $this->mockUpdateWebHookParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'patch'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->patch($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_show_details_for_a_web_hook() { $expectedResponse = $this->mockGetWebHookResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/notifications/webhooks/0EH40505U7160970P'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_list_web_hooks_events() { $expectedResponse = $this->mockListWebHookEventsResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/notifications/webhooks/0EH40505U7160970P'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true)); } } paypal/tests/Unit/Client/DisputeActionsTest.php000064400000005671150364341100015646 0ustar00mockAcceptDisputesClaimResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/customer/disputes/PP-D-27803/accept-claim'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], 'json' => $this->acceptDisputeClaimParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_accept_dispute_offer_resolution() { $expectedResponse = $this->mockAcceptDisputesOfferResolutionResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/customer/disputes/PP-000-000-651-454/accept-offer'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], 'json' => $this->acceptDisputeResolutionParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_acknowledge_item_is_returned_for_raised_dispute() { $expectedResponse = $this->mockAcknowledgeItemReturnedResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/customer/disputes/PP-000-000-651-454/acknowledge-return-item'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], 'json' => $this->acknowledgeItemReturnedParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true)); } } paypal/tests/Unit/Client/WebHooksEventsTest.php000064400000007111150364341100015605 0ustar00mockListWebHookEventsTypesResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/notifications/webhooks-event-types'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_list_web_hooks_events() { $expectedResponse = $this->mockWebHookEventsListResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/notifications/webhooks-events'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_show_details_for_a_web_hooks_event() { $expectedResponse = $this->mockGetWebHookEventResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/notifications/webhooks-events/8PT597110X687430LKGECATA'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_resend_notification_for_a_web_hooks_event() { $expectedResponse = $this->mockResendWebHookEventNotificationResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/notifications/webhooks-events/8PT597110X687430LKGECATA/resend'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], 'json' => $this->mockResendWebHookEventNotificationParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true)); } } paypal/tests/Unit/Client/InvoicesTest.php000064400000026751150364341100014471 0ustar00mockGenerateInvoiceNumberResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/generate-next-invoice-number'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_create_a_draft_invoice() { $expectedResponse = $this->mockCreateInvoicesResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/invoices'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], 'json' => $this->createInvoiceParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_list_current_invoices() { $expectedResponse = $this->mockListInvoicesResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/invoices?total_required=true'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_delete_an_invoice() { $expectedResponse = ''; $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/invoices/INV2-Z56S-5LLA-Q52L-CPZ5'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'delete'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->delete($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_update_an_invoice() { $expectedResponse = $this->mockUpdateInvoicesResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/invoices/INV2-Z56S-5LLA-Q52L-CPZ5'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], 'json' => $this->updateInvoiceParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'put'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->put($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_show_details_for_an_invoice() { $expectedResponse = $this->mockGetInvoicesResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/invoices/INV2-Z56S-5LLA-Q52L-CPZ5'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_cancel_an_invoice() { $expectedResponse = ''; $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/invoices/INV2-Z56S-5LLA-Q52L-CPZ5/cancel'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], 'json' => $this->cancelInvoiceParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_generate_qr_code_for_invoice() { $expectedResponse = $this->mockGenerateInvoiceNumberResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/invoices/INV2-Z56S-5LLA-Q52L-CPZ5/generate-qr-code'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], 'json' => $this->generateQRCodeInvoiceParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_register_payment_for_invoice() { $expectedResponse = $this->mockInvoiceRegisterPaymentResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/invoices/INV2-Z56S-5LLA-Q52L-CPZ5/payments'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], 'json' => $this->registerInvoicePaymentParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_delete_payment_for_invoice() { $expectedResponse = ''; $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/invoices/INV2-Z56S-5LLA-Q52L-CPZ5/payments/EXTR-86F38350LX4353815'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'delete'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->delete($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_refund_payment_for_invoice() { $expectedResponse = $this->mockInvoiceRefundPaymentResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/invoices/INV2-Z56S-5LLA-Q52L-CPZ5/refunds'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], 'json' => $this->refundInvoicePaymentParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_delete_refund_for_invoice() { $expectedResponse = ''; $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/invoices/INV2-333R-YUQL-YNNN-D7WF/refunds/EXTR-2LG703375E477444T'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'delete'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->delete($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_send_an_invoice() { $expectedResponse = ''; $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/invoices/INV2-EHNV-LJ5S-A7DZ-V6NJ/send'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], 'json' => $this->sendInvoiceParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_send_reminder_for_an_invoice() { $expectedResponse = ''; $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/invoices/INV2-Z56S-5LLA-Q52L-CPZ5/remind'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], 'json' => $this->sendInvoiceReminderParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true)); } } paypal/tests/Unit/Client/PaymentRefundsTest.php000064400000002074150364341100015646 0ustar00mockGetRefundDetailsResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/payments/refunds/1JU08902781691411'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true)); } } paypal/tests/Unit/Client/PaymentAuthorizationsTest.php000064400000007216150364341100017266 0ustar00mockGetAuthorizedPaymentDetailsResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/payments/authorizations/0VF52814937998046'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_capture_an_authorized_payment() { $expectedResponse = $this->mockCaptureAuthorizedPaymentResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/payments/authorizations/0VF52814937998046/capture'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], 'json' => $this->mockCaptureAuthorizedPaymentParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_reauthorize_an_authorized_payment() { $expectedResponse = $this->mockReAuthorizeAuthorizedPaymentResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/payments/authorizations/0VF52814937998046/reauthorize'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], 'json' => $this->mockReAuthorizeAuthorizedPaymentParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_void_an_authorized_payment() { $expectedResponse = ''; $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/payments/authorizations/0VF52814937998046/void'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true)); } } paypal/tests/Unit/Client/PaymentExperienceWebProfilesTest.php000064400000012316150364341100020471 0ustar00mockListWebProfilesResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/payment-experience/web-profiles'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_create_web_experience_profile() { $expectedResponse = $this->mockWebProfileResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/payment-experience/web-profiles'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', 'PayPal-Request-Id' => 'some-request-id', ], 'json' => $this->mockCreateWebProfileParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_delete_web_experience_profile() { $expectedResponse = ''; $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/payment-experience/web-profiles/XP-A88A-LYLW-8Y3X-E5ER'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'delete'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->delete($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_partially_update_web_experience_profile() { $expectedResponse = ''; $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/payment-experience/web-profiles/XP-A88A-LYLW-8Y3X-E5ER'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], 'json' => $this->partiallyUpdateWebProfileParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'patch'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->patch($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_fully_update_web_experience_profile() { $expectedResponse = ''; $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/payment-experience/web-profiles/XP-A88A-LYLW-8Y3X-E5ER'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], 'json' => $this->updateWebProfileParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'patch'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->patch($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_get_web_experience_profile_details() { $expectedResponse = $this->mockWebProfileResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/payment-experience/web-profiles/XP-A88A-LYLW-8Y3X-E5ER'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true)); } } paypal/tests/Unit/Client/SubscriptionsTest.php000064400000017270150364341100015555 0ustar00mockCreateSubscriptionResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/subscriptions'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], 'json' => $this->mockCreateSubscriptionParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_update_a_subscription() { $expectedResponse = ''; $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/subscriptions/I-BW452GLLEP1G'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], 'json' => $this->mockUpdateSubscriptionParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'patch'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->patch($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_show_details_for_a_subscription() { $expectedResponse = $this->mockGetSubscriptionDetailsResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/subscriptions/I-BW452GLLEP1G'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_activate_a_subscription() { $expectedResponse = ''; $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/subscriptions/I-BW452GLLEP1G/activate'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], 'json' => $this->mockActivateSubscriptionParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_cancel_a_subscription() { $expectedResponse = ''; $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/subscriptions/I-BW452GLLEP1G/cancel'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], 'json' => $this->mockCancelSubscriptionParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_suspend_a_subscription() { $expectedResponse = ''; $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/subscriptions/I-BW452GLLEP1G/suspend'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], 'json' => $this->mockSuspendSubscriptionParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_capture_payment_for_a_subscription() { $expectedResponse = ''; $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/subscriptions/I-BW452GLLEP1G/capture'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], 'json' => $this->mockCaptureSubscriptionPaymentParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_update_quantity_or_product_for_a_subscription() { $expectedResponse = $this->mockUpdateSubscriptionItemsResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/subscriptions/I-BW452GLLEP1G/revise'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], 'json' => $this->mockUpdateSubscriptionItemsParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_list_transactions_for_a_subscription() { $expectedResponse = $this->mockListSubscriptionTransactionsResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/subscriptions/I-BW452GLLEP1G/transactions?start_time=2018-01-21T07:50:20.940Z&end_time=2018-08-21T07:50:20.940Z'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true)); } } paypal/tests/Unit/Client/PayoutsTest.php000064400000006741150364341100014353 0ustar00mockCreateBatchPayoutResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/payments/payouts'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], 'json' => $this->mockCreateBatchPayoutParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_show_batch_payout_details() { $expectedResponse = $this->showBatchPayoutResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/payments/payouts/FYXMPQTX4JC9N'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_show_batch_payout_item_details() { $expectedResponse = $this->showBatchPayoutItemResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/payments/payouts-item/8AELMXH8UB2P8'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_cancel_unclaimed_batch_payout_item() { $expectedResponse = $this->mockCancelUnclaimedBatchItemResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/payments/payouts-item/8AELMXH8UB2P8/cancel'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true)); } } paypal/tests/Unit/Client/ReportingTest.php000064400000004110150364341100014644 0ustar00mockListTransactionsResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/reporting/transactions?start_date=2014-07-01T00:00:00-0700&end_date=2014-07-30T23:59:59-0700&transaction_id=5TY05013RG002845M&fields=all&page_size=100&page=1'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get'); $mockResponse = $mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(); $this->assertArrayHasKey('transaction_details', Utils::jsonDecode($mockResponse, true)); } /** @test */ public function it_can_list_balances() { $expectedResponse = $this->mockListBalancesResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/reporting/balances?currency_code=USD&as_of_time=2016-10-15T06:07:00-0700'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true)); } } paypal/tests/Unit/Client/OrdersTest.php000064400000002223150364341100014134 0ustar00mockCreateOrdersResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/checkout/orders'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], 'json' => $this->createOrderParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true)); } } paypal/tests/Unit/Client/TrackersTest.php000064400000005457150364341100014470 0ustar00mockGetTrackingDetailsResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/shipping/trackers/8MC585209K746392H-443844607820'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_update_tracking_details_for_tracking_id() { $expectedResponse = ''; $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/shipping/trackers/8MC585209K746392H-443844607820'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], 'json' => $this->mockUpdateTrackingDetailsParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'put'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->put($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_create_tracking_in_batches() { $expectedResponse = $this->mockCreateTrackinginBatchesResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/shipping/trackers-batch'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], 'json' => $this->mockCreateTrackinginBatchesParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true)); } } paypal/tests/Unit/Client/CatalogProductsTest.php000064400000006771150364341100016010 0ustar00mockCreateCatalogProductsResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/catalogs/products'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], 'json' => $this->createProductParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_list_products() { $expectedResponse = $this->mockListCatalogProductsResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/catalogs/products?page=1&page_size=2&total_required=true'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_update_a_product() { $expectedResponse = ''; $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/catalogs/products/72255d4849af8ed6e0df1173'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], 'json' => $this->updateProductParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'patch'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->patch($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_get_details_for_a_product() { $expectedResponse = $this->mockGetCatalogProductsResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/catalogs/products/72255d4849af8ed6e0df1173'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true)); } } paypal/tests/Unit/Client/DisputesTest.php000064400000005176150364341100014510 0ustar00mockListDisputesResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/customer/disputes/'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_partially_update_a_dispute() { $expectedResponse = ''; $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/customer/disputes/PP-D-27803'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], 'json' => $this->updateDisputeParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'patch'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->patch($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_get_details_for_a_dispute() { $expectedResponse = $this->mockGetDisputesResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/customer/disputes/PP-D-4012'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true)); } } paypal/tests/Unit/Client/WebHooksVerificationTest.php000064400000002327150364341100016767 0ustar00mockVerifyWebHookSignatureResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/notifications/webhooks-event-types'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], 'json' => $this->mockVerifyWebHookSignatureParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true)); } } paypal/tests/Unit/Client/InvoicesSearchTest.php000064400000002320150364341100015601 0ustar00mockSearchInvoicesResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/search-invoices?page=1&page_size=1&total_required=true'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], 'json' => $this->invoiceSearchParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true)); } } paypal/tests/Unit/Client/IdentityTest.php000064400000002204150364341100014466 0ustar00mockShowProfileInfoResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true)); } } paypal/tests/Unit/Client/InvoicesTemplatesTest.php000064400000010460150364341100016336 0ustar00mockCreateInvoiceTemplateResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/templates'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], 'json' => $this->mockCreateInvoiceTemplateParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_list_invoice_templates() { $expectedResponse = $this->mockListInvoiceTemplateResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/templates'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_delete_an_invoice_template() { $expectedResponse = ''; $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/templates/TEMP-19V05281TU309413B'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'delete'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->delete($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_update_an_invoice_template() { $expectedResponse = $this->mockUpdateInvoiceTemplateResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/templates/TEMP-19V05281TU309413B'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], 'json' => $this->mockUpdateInvoiceTemplateParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'put'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->put($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_get_details_for_an_invoice_template() { $expectedResponse = $this->mockGetInvoiceTemplateResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v2/invoicing/templates/TEMP-19V05281TU309413B'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true)); } } paypal/tests/Unit/Client/BillingPlansTest.php000064400000013471150364341100015263 0ustar00mockCreatePlansResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/plans'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], 'json' => $this->createPlanParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_list_billing_plans() { $expectedResponse = $this->mockListPlansResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/plans?product_id=PROD-XXCD1234QWER65782&page_size=2&page=1&total_required=true'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_update_a_billing_plan() { $expectedResponse = ''; $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/plans/P-7GL4271244454362WXNWU5NQ'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], 'json' => $this->updatePlanParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'patch'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->patch($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_show_details_for_a_billing_plan() { $expectedResponse = $this->mockGetPlansResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/plans/P-5ML4271244454362WXNWU5NQ'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'get'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->get($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_activate_a_billing_plan() { $expectedResponse = ''; $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/plans/P-7GL4271244454362WXNWU5NQ/activate'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_deactivate_a_billing_plan() { $expectedResponse = ''; $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/plans/P-7GL4271244454362WXNWU5NQ/deactivate'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true)); } /** @test */ public function it_can_update_pricing_for_a_billing_plan() { $expectedResponse = ''; $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/billing/plans/P-2UF78835G6983425GLSM44MA/update-pricing-schemes'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', 'Authorization' => 'Bearer some-token', ], 'json' => $this->updatePlanPricingParams(), ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams, 'post'); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true)); } } paypal/tests/Unit/AdapterTest.php000064400000005253150364341100013046 0ustar00getMockCredentials()); $this->assertInstanceOf(PayPalClient::class, $client); } /** @test */ public function it_throws_exception_if_invalid_credentials_are_provided() { $this->expectException(\RuntimeException::class); $client = new PayPalClient(); } /** @test */ public function it_throws_exception_if_invalid_mode_is_provided() { $this->expectException(\RuntimeException::class); // $this->expectErrorMessage('Invalid configuration provided. Please provide valid configuration for PayPal API. You can also refer to the documentation at https://srmklive.github.io/laravel-paypal/docs.html to setup correct configuration.'); $credentials = $this->getMockCredentials(); $credentials['mode'] = ''; $client = new PayPalClient($credentials); } /** @test */ public function it_throws_exception_if_empty_credentials_are_provided() { $this->expectException(\RuntimeException::class); // $this->expectErrorMessage('Invalid configuration provided. Please provide valid configuration for PayPal API. You can also refer to the documentation at https://srmklive.github.io/laravel-paypal/docs.html to setup correct configuration.'); $credentials = $this->getMockCredentials(); $credentials['sandbox'] = []; $client = new PayPalClient($credentials); } /** @test */ public function it_throws_exception_if_credentials_items_are_not_provided() { $item = 'client_id'; $this->expectException(\RuntimeException::class); // $this->expectErrorMessage("{$item} missing from the provided configuration. Please add your application {$item}."); $credentials = $this->getMockCredentials(); $credentials['sandbox'][$item] = ''; $client = new PayPalClient($credentials); } /** @test */ public function it_can_get_access_token() { $expectedResponse = $this->mockAccessTokenResponse(); $expectedMethod = 'getAccessToken'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, false); $mockClient->setApiCredentials($this->getMockCredentials()); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}()); } } paypal/tests/Unit/Adapter/ReferencedPayoutsTest.php000064400000006564150364341100016503 0ustar00mockCreateReferencedBatchPayoutResponse(); $expectedParams = $this->mockCreateReferencedBatchPayoutParams(); $expectedMethod = 'createReferencedBatchPayout'; $additionalMethod = 'setRequestHeaders'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true, $additionalMethod); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $mockClient->{$additionalMethod}([ 'PayPal-Request-Id' => 'some-request-id', 'PayPal-Partner-Attribution-Id' => 'some-attribution-id', ]); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}($expectedParams)); } /** @test */ public function it_can_list_items_referenced_in_batch_payout() { $expectedResponse = $this->mockShowReferencedBatchPayoutResponse(); $expectedParams = 'KHbwO28lWlXwi2IlToJ2IYNG4juFv6kpbFx4J9oQ5Hb24RSp96Dk5FudVHd6v4E='; $expectedMethod = 'listItemsReferencedInBatchPayout'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}($expectedParams)); } /** @test */ public function it_can_create_referenced_batch_payout_item() { $expectedResponse = $this->mockCreateReferencedBatchPayoutItemResponse(); $expectedParams = $this->mockCreateReferencedBatchPayoutItemParams(); $expectedMethod = 'createReferencedBatchPayoutItem'; $additionalMethod = 'setRequestHeaders'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true, $additionalMethod); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $mockClient->{$additionalMethod}([ 'PayPal-Request-Id' => 'some-request-id', 'PayPal-Partner-Attribution-Id' => 'some-attribution-id', ]); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}($expectedParams)); } /** @test */ public function it_can_show_referenced_payout_item_details() { $expectedResponse = $this->mockShowReferencedBatchPayoutItemResponse(); $expectedParams = 'CDZEC5MJ8R5HY'; $expectedMethod = 'showReferencedPayoutItemDetails'; $additionalMethod = 'setRequestHeader'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true, $additionalMethod); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $mockClient->{$additionalMethod}('PayPal-Partner-Attribution-Id', 'some-attribution-id'); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}($expectedParams)); } } paypal/tests/Unit/Adapter/PartnerReferralsTest.php000064400000003023150364341100016320 0ustar00mockCreatePartnerReferralsResponse(); $expectedParams = $this->mockCreatePartnerReferralParams(); $expectedMethod = 'createPartnerReferral'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}($expectedParams)); } /** @test */ public function it_can_get_referral_details() { $expectedResponse = $this->mockShowReferralDataResponse(); $expectedParams = 'ZjcyODU4ZWYtYTA1OC00ODIwLTk2M2EtOTZkZWQ4NmQwYzI3RU12cE5xa0xMRmk1NWxFSVJIT1JlTFdSbElCbFU1Q3lhdGhESzVQcU9iRT0='; $expectedMethod = 'showReferralData'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}($expectedParams)); } } paypal/tests/Unit/Adapter/PaymentCapturesTest.php000064400000002606150364341100016171 0ustar00mockGetCapturedPaymentDetailsResponse(); $expectedMethod = 'showCapturedPaymentDetails'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('2GG279541U471931P')); } /** @test */ public function it_can_refund_a_captured_payment() { $expectedResponse = $this->mockRefundCapturedPaymentResponse(); $expectedMethod = 'refundCapturedPayment'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}( '2GG279541U471931P', 'INVOICE-123', 10.99, 'Defective product' )); } } paypal/tests/Unit/Adapter/WebHooksTest.php000064400000006513150364341100014567 0ustar00mockCreateWebHookResponse(); $expectedMethod = 'createWebHook'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}( 'https://example.com/example_webhook', ['PAYMENT.AUTHORIZATION.CREATED', 'PAYMENT.AUTHORIZATION.VOIDED'] )); } /** @test */ public function it_can_list_web_hooks() { $expectedResponse = $this->mockListWebHookResponse(); $expectedMethod = 'listWebHooks'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}()); } /** @test */ public function it_can_delete_a_web_hook() { $expectedResponse = ''; $expectedMethod = 'deleteWebHook'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('5GP028458E2496506')); } /** @test */ public function it_can_update_a_web_hook() { $expectedResponse = $this->mockUpdateWebHookResponse(); $expectedParams = $this->mockUpdateWebHookParams(); $expectedMethod = 'updateWebHook'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('0EH40505U7160970P', $expectedParams)); } /** @test */ public function it_can_show_details_for_a_web_hook() { $expectedResponse = $this->mockGetWebHookResponse(); $expectedMethod = 'showWebHookDetails'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('0EH40505U7160970P')); } /** @test */ public function it_can_list_web_hooks_events() { $expectedResponse = $this->mockListWebHookEventsResponse(); $expectedMethod = 'listWebHookEvents'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('0EH40505U7160970P')); } } paypal/tests/Unit/Adapter/DisputeActionsTest.php000064400000003635150364341100016006 0ustar00mockAcceptDisputesClaimResponse(); $expectedMethod = 'acceptDisputeClaim'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('PP-D-27803', 'Full refund to the customer.')); } /** @test */ public function it_can_accept_dispute_offer_resolution() { $expectedResponse = $this->mockAcceptDisputesOfferResolutionResponse(); $expectedMethod = 'acceptDisputeOfferResolution'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('PP-000-000-651-454', 'I am ok with the refund offered.')); } /** @test */ public function it_can_acknowledge_item_is_returned_for_raised_dispute() { $expectedResponse = $this->mockAcknowledgeItemReturnedResponse(); $expectedMethod = 'acknowledgeItemReturned'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('PP-000-000-651-454', 'I have received the item back.', 'ITEM_RECEIVED')); } } paypal/tests/Unit/Adapter/WebHooksEventsTest.php000064400000004442150364341100015753 0ustar00mockListWebHookEventsTypesResponse(); $expectedMethod = 'listEventTypes'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}()); } /** @test */ public function it_can_list_web_hooks_events() { $expectedResponse = $this->mockWebHookEventsListResponse(); $expectedMethod = 'listEvents'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}()); } /** @test */ public function it_can_show_details_for_a_web_hooks_event() { $expectedResponse = $this->mockGetWebHookEventResponse(); $expectedMethod = 'showEventDetails'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('8PT597110X687430LKGECATA')); } /** @test */ public function it_can_resend_notification_for_a_web_hooks_event() { $expectedResponse = $this->mockResendWebHookEventNotificationResponse(); $expectedParams = ['12334456']; $expectedMethod = 'resendEventNotification'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('8PT597110X687430LKGECATA', $expectedParams)); } } paypal/tests/Unit/Adapter/InvoicesTest.php000064400000020525150364341100014624 0ustar00mockGenerateInvoiceNumberResponse(); $expectedMethod = 'generateInvoiceNumber'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}()); } /** @test */ public function it_can_create_a_draft_invoice() { $expectedResponse = $this->mockCreateInvoicesResponse(); $expectedParams = $this->createInvoiceParams(); $expectedMethod = 'createInvoice'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}($expectedParams)); } /** @test */ public function it_can_list_current_invoices() { $expectedResponse = $this->mockListInvoicesResponse(); $expectedMethod = 'listInvoices'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}()); } /** @test */ public function it_can_delete_an_invoice() { $expectedResponse = ''; $expectedMethod = 'deleteInvoice'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('INV2-Z56S-5LLA-Q52L-CPZ5')); } /** @test */ public function it_can_update_an_invoice() { $expectedResponse = $this->mockUpdateInvoicesResponse(); $expectedParams = $this->updateInvoiceParams(); $expectedMethod = 'updateInvoice'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('INV2-Z56S-5LLA-Q52L-CPZ5', $expectedParams)); } /** @test */ public function it_can_show_details_for_an_invoice() { $expectedResponse = $this->mockGetInvoicesResponse(); $expectedMethod = 'showInvoiceDetails'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('INV2-Z56S-5LLA-Q52L-CPZ5')); } /** @test */ public function it_can_cancel_an_invoice() { $expectedResponse = ''; $expectedParams = $this->cancelInvoiceParams(); $expectedMethod = 'cancelInvoice'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}( 'INV2-Z56S-5LLA-Q52L-CPZ5', 'Reminder: Payment due for the invoice #ABC-123', 'Please pay before the due date to avoid incurring late payment charges which will be adjusted in the next bill generated.', true, true, [ 'customer-a@example.com', 'customer@example.com', ] )); } /** @test */ public function it_can_generate_qr_code_for_invoice() { $expectedResponse = $this->mockGenerateInvoiceQRCodeResponse(); $expectedMethod = 'generateQRCodeInvoice'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('INV2-Z56S-5LLA-Q52L-CPZ5', 400, 400)); } /** @test */ public function it_can_register_payment_for_invoice() { $expectedResponse = $this->mockInvoiceRegisterPaymentResponse(); $expectedMethod = 'registerPaymentInvoice'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('INV2-Z56S-5LLA-Q52L-CPZ5', '2018-05-01', 'BANK_TRANSFER', 10.00)); } /** @test */ public function it_can_delete_payment_for_invoice() { $expectedResponse = ''; $expectedMethod = 'deleteExternalPaymentInvoice'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('INV2-Z56S-5LLA-Q52L-CPZ5', 'EXTR-86F38350LX4353815')); } /** @test */ public function it_can_refund_payment_for_invoice() { $expectedResponse = $this->mockInvoiceRefundPaymentResponse(); $expectedMethod = 'refundInvoice'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('INV2-Z56S-5LLA-Q52L-CPZ5', '2018-05-01', 'BANK_TRANSFER', 5.00)); } /** @test */ public function it_can_delete_refund_for_invoice() { $expectedResponse = ''; $expectedMethod = 'deleteRefundInvoice'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('INV2-Z56S-5LLA-Q52L-CPZ5', 'EXTR-2LG703375E477444T')); } /** @test */ public function it_can_send_an_invoice() { $expectedResponse = ''; $expectedMethod = 'sendInvoice'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}( 'INV2-Z56S-5LLA-Q52L-CPZ5', 'Reminder: Payment due for the invoice #ABC-123', 'Please pay before the due date to avoid incurring late payment charges which will be adjusted in the next bill generated.', true, true, [ 'customer-a@example.com', 'customer@example.com', ] )); } /** @test */ public function it_can_send_reminder_for_an_invoice() { $expectedResponse = ''; $expectedMethod = 'sendInvoiceReminder'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}( 'INV2-Z56S-5LLA-Q52L-CPZ5', 'Reminder: Payment due for the invoice #ABC-123', 'Please pay before the due date to avoid incurring late payment charges which will be adjusted in the next bill generated.', true, true, [ 'customer-a@example.com', 'customer@example.com', ] )); } } paypal/tests/Unit/Adapter/PaymentRefundsTest.php000064400000001413150364341100016004 0ustar00mockGetRefundDetailsResponse(); $expectedMethod = 'showRefundDetails'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('1JU08902781691411')); } } paypal/tests/Unit/Adapter/PaymentAuthorizationsTest.php000064400000004602150364341100017424 0ustar00mockGetAuthorizedPaymentDetailsResponse(); $expectedMethod = 'showAuthorizedPaymentDetails'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('0VF52814937998046')); } /** @test */ public function it_can_capture_an_authorized_payment() { $expectedResponse = $this->mockCaptureAuthorizedPaymentResponse(); $expectedMethod = 'captureAuthorizedPayment'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}( '0VF52814937998046', 'INVOICE-123', 10.99, 'Payment is due' )); } /** @test */ public function it_can_reauthorize_an_authorized_payment() { $expectedResponse = $this->mockReAuthorizeAuthorizedPaymentResponse(); $expectedMethod = 'reAuthorizeAuthorizedPayment'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('0VF52814937998046', 10.99)); } /** @test */ public function it_can_void_an_authorized_payment() { $expectedResponse = ''; $expectedMethod = 'voidAuthorizedPayment'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('0VF52814937998046')); } } paypal/tests/Unit/Adapter/PaymentExperienceWebProfilesTest.php000064400000007321150364341100020633 0ustar00mockListWebProfilesResponse(); $expectedMethod = 'listWebExperienceProfiles'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}()); } /** @test */ public function it_can_create_web_experience_profile() { $expectedResponse = $this->mockWebProfileResponse(); $expectedParams = $this->mockCreateWebProfileParams(); $expectedMethod = 'createWebExperienceProfile'; $additionalMethod = 'setRequestHeader'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true, $additionalMethod); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $mockClient->{$additionalMethod}('PayPal-Request-Id', 'some-request-id'); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}($expectedParams)); } /** @test */ public function it_can_delete_web_experience_profile() { $expectedResponse = ''; $expectedParams = 'XP-A88A-LYLW-8Y3X-E5ER'; $expectedMethod = 'deleteWebExperienceProfile'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}($expectedParams)); } /** @test */ public function it_can_partially_update_web_experience_profile() { $expectedResponse = ''; $expectedParams = $this->partiallyUpdateWebProfileParams(); $expectedMethod = 'patchWebExperienceProfile'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('XP-A88A-LYLW-8Y3X-E5ER', $expectedParams)); } /** @test */ public function it_can_fully_update_web_experience_profile() { $expectedResponse = ''; $expectedParams = $this->updateWebProfileParams(); $expectedMethod = 'updateWebExperienceProfile'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('XP-A88A-LYLW-8Y3X-E5ER', $expectedParams)); } /** @test */ public function it_can_get_web_experience_profile_details() { $expectedResponse = $this->mockWebProfileResponse(); $expectedParams = 'XP-A88A-LYLW-8Y3X-E5ER'; $expectedMethod = 'showWebExperienceProfileDetails'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}($expectedParams)); } } paypal/tests/Unit/Adapter/SubscriptionsTest.php000064400000012025150364341100015710 0ustar00mockCreateSubscriptionResponse(); $expectedParams = $this->mockCreateSubscriptionParams(); $expectedMethod = 'createSubscription'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}($expectedParams)); } /** @test */ public function it_can_update_a_subscription() { $expectedResponse = ''; $expectedParams = $this->mockUpdateSubscriptionParams(); $expectedMethod = 'updateSubscription'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('I-BW452GLLEP1G', $expectedParams)); } /** @test */ public function it_can_show_details_for_a_subscription() { $expectedResponse = $this->mockGetSubscriptionDetailsResponse(); $expectedMethod = 'showSubscriptionDetails'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('I-BW452GLLEP1G')); } /** @test */ public function it_can_activate_a_subscription() { $expectedResponse = ''; $expectedMethod = 'activateSubscription'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('I-BW452GLLEP1G', 'Reactivating the subscription')); } /** @test */ public function it_can_cancel_a_subscription() { $expectedResponse = ''; $expectedMethod = 'cancelSubscription'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('I-BW452GLLEP1G', 'Not satisfied with the service')); } /** @test */ public function it_can_suspend_a_subscription() { $expectedResponse = ''; $expectedMethod = 'suspendSubscription'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('I-BW452GLLEP1G', 'Item out of stock')); } /** @test */ public function it_can_capture_payment_for_a_subscription() { $expectedResponse = ''; $expectedMethod = 'captureSubscriptionPayment'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('I-BW452GLLEP1G', 'Charging as the balance reached the limit', 100)); } /** @test */ public function it_can_update_quantity_or_product_for_a_subscription() { $expectedResponse = $this->mockUpdateSubscriptionItemsResponse(); $expectedParams = $this->mockUpdateSubscriptionItemsParams(); $expectedMethod = 'reviseSubscription'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('I-BW452GLLEP1G', $expectedParams)); } /** @test */ public function it_can_list_transactions_for_a_subscription() { $expectedResponse = $this->mockListSubscriptionTransactionsResponse(); $expectedMethod = 'listSubscriptionTransactions'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('I-BW452GLLEP1G', '2018-01-21T07:50:20.940Z', '2018-08-22T07:50:20.940Z')); } } paypal/tests/Unit/Adapter/PayoutsTest.php000064400000004761150364341100014515 0ustar00mockCreateBatchPayoutResponse(); $expectedParams = $this->mockCreateBatchPayoutParams(); $expectedMethod = 'createBatchPayout'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}($expectedParams)); } /** @test */ public function it_can_show_batch_payout_details() { $expectedResponse = $this->showBatchPayoutResponse(); $expectedParams = 'FYXMPQTX4JC9N'; $expectedMethod = 'showBatchPayoutDetails'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}($expectedParams)); } /** @test */ public function it_can_show_batch_payout_item_details() { $expectedResponse = $this->showBatchPayoutItemResponse(); $expectedParams = '8AELMXH8UB2P8'; $expectedMethod = 'showPayoutItemDetails'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}($expectedParams)); } /** @test */ public function it_can_cancel_unclaimed_batch_payout_item() { $expectedResponse = $this->mockCancelUnclaimedBatchItemResponse(); $expectedParams = '8AELMXH8UB2P8'; $expectedMethod = 'cancelUnclaimedPayoutItem'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}($expectedParams)); } } paypal/tests/Unit/Adapter/ReportingTest.php000064400000002627150364341100015021 0ustar00mockListTransactionsResponse(); $expectedMethod = 'listTransactions'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $filters = [ 'start_date' => Carbon::now()->toIso8601String(), 'end_date' => Carbon::now()->subDays(30)->toIso8601String(), ]; $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}($filters)); } /** @test */ public function it_can_list_balances() { $expectedResponse = $this->mockListBalancesResponse(); $expectedMethod = 'listBalances'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('2016-10-15T06:07:00-0700')); } } paypal/tests/Unit/Adapter/OrdersTest.php000064400000002563150364341100014305 0ustar00mockCreateOrdersResponse(); $expectedParams = $this->createOrderParams(); $expectedMethod = 'createOrder'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}($expectedParams)); } /** @test */ public function it_can_update_an_order() { $expectedResponse = ''; $expectedParams = $this->updateOrderParams(); $expectedMethod = 'updateOrder'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('5O190127TN364715T', $expectedParams)); } } paypal/tests/Unit/Adapter/TrackersTest.php000064400000004075150364341100014625 0ustar00mockGetTrackingDetailsResponse(); $expectedParams = '8MC585209K746392H-443844607820'; $expectedMethod = 'showTrackingDetails'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}($expectedParams)); } /** @test */ public function it_can_update_tracking_details_for_tracking_id() { $expectedResponse = ''; $expectedData = $this->mockUpdateTrackingDetailsParams(); $expectedParams = '8MC585209K746392H-443844607820'; $expectedMethod = 'updateTrackingDetails'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}($expectedParams, $expectedData)); } /** @test */ public function it_can_create_tracking_in_batches() { $expectedResponse = $this->mockCreateTrackinginBatchesResponse(); $expectedParams = $this->mockCreateTrackinginBatchesParams(); $expectedMethod = 'addBatchTracking'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}($expectedParams)); } } paypal/tests/Unit/Adapter/CatalogProductsTest.php000064400000004764150364341100016152 0ustar00mockCreateCatalogProductsResponse(); $expectedParams = $this->createProductParams(); $expectedMethod = 'createProduct'; $additionalMethod = 'setRequestHeader'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true, $additionalMethod); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $mockClient->{$additionalMethod}('PayPal-Request-Id', 'some-request-id'); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}($expectedParams)); } /** @test */ public function it_can_list_products() { $expectedResponse = $this->mockListCatalogProductsResponse(); $expectedMethod = 'listProducts'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}()); } /** @test */ public function it_can_update_a_product() { $expectedResponse = ''; $expectedParams = $this->updateProductParams(); $expectedMethod = 'updateProduct'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('72255d4849af8ed6e0df1173', $expectedParams)); } /** @test */ public function it_can_get_details_for_a_product() { $expectedResponse = $this->mockGetCatalogProductsResponse(); $expectedMethod = 'showProductDetails'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('72255d4849af8ed6e0df1173')); } } paypal/tests/Unit/Adapter/DisputesTest.php000064400000003432150364341100014643 0ustar00mockListDisputesResponse(); $expectedMethod = 'listDisputes'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}()); } /** @test */ public function it_can_partially_update_a_dispute() { $expectedResponse = ''; $expectedParams = $this->updateDisputeParams(); $expectedMethod = 'updateDispute'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('PP-D-27803', $expectedParams)); } /** @test */ public function it_can_get_details_for_a_dispute() { $expectedResponse = $this->mockGetDisputesResponse(); $expectedMethod = 'showDisputeDetails'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('PP-D-4012')); } } paypal/tests/Unit/Adapter/WebHooksVerificationTest.php000064400000001641150364341100017127 0ustar00mockVerifyWebHookSignatureResponse(); $expectedParams = $this->mockVerifyWebHookSignatureParams(); $expectedMethod = 'verifyWebHook'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}($expectedParams)); } } paypal/tests/Unit/Adapter/InvoicesSearchTest.php000064400000002731150364341100015751 0ustar00mockSearchInvoicesResponse(); $expectedMethod = 'searchInvoices'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}(1, 1, true)); } /** @test */ public function it_can_search_invoices_with_custom_filters() { $expectedResponse = $this->mockSearchInvoicesResponse(); $expectedMethod = 'searchInvoices'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->addInvoiceFilterByRecipientEmail('bill-me@example.com') ->addInvoiceFilterByCurrencyCode('USD') ->addInvoiceFilterByAmountRange(30, 50) ->{$expectedMethod}(1, 1, true)); } } paypal/tests/Unit/Adapter/IdentityTest.php000064400000001472150364341100014636 0ustar00mockShowProfileInfoResponse(); $expectedMethod = 'showProfileInfo'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}()); } } paypal/tests/Unit/Adapter/InvoicesTemplatesTest.php000064400000005670150364341100016507 0ustar00mockCreateInvoiceTemplateResponse(); $expectedParams = $this->mockCreateInvoiceTemplateParams(); $expectedMethod = 'createInvoiceTemplate'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}($expectedParams)); } /** @test */ public function it_can_list_invoice_templates() { $expectedResponse = $this->mockListInvoiceTemplateResponse(); $expectedMethod = 'listInvoiceTemplates'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}()); } /** @test */ public function it_can_delete_an_invoice_template() { $expectedResponse = ''; $expectedMethod = 'deleteInvoiceTemplate'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('TEMP-19V05281TU309413B')); } /** @test */ public function it_can_update_an_invoice_template() { $expectedResponse = $this->mockUpdateInvoiceTemplateResponse(); $expectedParams = $this->mockUpdateInvoiceTemplateParams(); $expectedMethod = 'updateInvoiceTemplate'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('TEMP-19V05281TU309413B', $expectedParams)); } /** @test */ public function it_can_get_details_for_an_invoice_template() { $expectedResponse = $this->mockGetInvoiceTemplateResponse(); $expectedMethod = 'showInvoiceTemplateDetails'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('TEMP-19V05281TU309413B')); } } paypal/tests/Unit/Adapter/BillingPlansTest.php000064400000007705150364341100015430 0ustar00mockCreatePlansResponse(); $expectedParams = $this->createPlanParams(); $expectedMethod = 'createPlan'; $additionalMethod = 'setRequestHeader'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true, $additionalMethod); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $mockClient->{$additionalMethod}('PayPal-Request-Id', 'some-request-id'); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}($expectedParams, 'some-request-id')); } /** @test */ public function it_can_list_billing_plans() { $expectedResponse = $this->mockListPlansResponse(); $expectedMethod = 'listPlans'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}(1, 2, true)); } /** @test */ public function it_can_update_a_billing_plan() { $expectedResponse = ''; $expectedParams = $this->updatePlanParams(); $expectedMethod = 'updatePlan'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('P-7GL4271244454362WXNWU5NQ', $expectedParams)); } /** @test */ public function it_can_show_details_for_a_billing_plan() { $expectedResponse = $this->mockGetPlansResponse(); $expectedMethod = 'showPlanDetails'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('P-7GL4271244454362WXNWU5NQ')); } /** @test */ public function it_can_activate_a_billing_plan() { $expectedResponse = ''; $expectedMethod = 'activatePlan'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('P-7GL4271244454362WXNWU5NQ')); } /** @test */ public function it_can_deactivate_a_billing_plan() { $expectedResponse = ''; $expectedMethod = 'deactivatePlan'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('P-7GL4271244454362WXNWU5NQ')); } /** @test */ public function it_can_update_pricing_for_a_billing_plan() { $expectedResponse = ''; $expectedParams = $this->updatePlanPricingParams(); $expectedMethod = 'updatePlanPricing'; $mockClient = $this->mock_client($expectedResponse, $expectedMethod, true); $mockClient->setApiCredentials($this->getMockCredentials()); $mockClient->getAccessToken(); $this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}('P-2UF78835G6983425GLSM44MA', $expectedParams)); } } paypal/tests/Unit/ClientTest.php000064400000002346150364341100012704 0ustar00assertInstanceOf(HttpClient::class, $client); } /** @test */ public function it_can_get_access_token() { $expectedResponse = $this->mockAccessTokenResponse(); $expectedEndpoint = 'https://api-m.sandbox.paypal.com/v1/oauth2/token?grant_type=client_credentials'; $expectedParams = [ 'headers' => [ 'Accept' => 'application/json', 'Accept-Language' => 'en_US', ], 'auth' => ['username', 'password'], ]; $mockHttpClient = $this->mock_http_request(Utils::jsonEncode($expectedResponse), $expectedEndpoint, $expectedParams); $this->assertEquals($expectedResponse, Utils::jsonDecode($mockHttpClient->post($expectedEndpoint, $expectedParams)->getBody(), true)); } } paypal/tests/MockResponsePayloads.php000064400000002432150364341100014010 0ustar00 'some_scope', 'access_token' => 'some_access_token', 'token_type' => 'Bearer', 'app_id' => 'APP-80W284485P519543T', 'expires_in' => 32400, 'nonce' => 'some_nonce', ]; } } paypal/tests/MockClientClasses.php000064400000010024150364341100013245 0ustar00 $handler]); } private function mock_http_request($expectedResponse, $expectedEndpoint, $expectedParams, $expectedMethod = 'post') { $set_method_name = 'setMethods'; if (strpos(phpversion(), '8.1') !== false || strpos(phpversion(), '8.2') !== false) { $set_method_name = 'onlyMethods'; } $mockResponse = $this->getMockBuilder(ResponseInterface::class) ->getMock(); $mockResponse->expects($this->exactly(1)) ->method('getBody') ->willReturn(new HttpStream(fopen('data://text/plain,'.$expectedResponse, 'r'))); $mockHttpClient = $this->getMockBuilder(HttpClient::class) ->{$set_method_name}([$expectedMethod]) ->getMock(); $mockHttpClient->expects($this->once()) ->method($expectedMethod) ->with($expectedEndpoint, $expectedParams) ->willReturn($mockResponse); return $mockHttpClient; } private function mock_client($expectedResponse, $expectedMethod, $token = false, $additionalMethod = null) { $set_method_name = 'setMethods'; if (strpos(phpversion(), '8.1') !== false || strpos(phpversion(), '8.2') !== false) { $set_method_name = 'onlyMethods'; } $methods = [$expectedMethod, 'setApiCredentials']; $methods[] = ($token) ? 'getAccessToken' : ''; $methods[] = isset($additionalMethod) ? $additionalMethod : ''; $mockClient = $this->getMockBuilder(PayPalClient::class) ->{$set_method_name}(array_filter($methods)) ->getMock(); if ($token) { $mockClient->expects($this->exactly(1)) ->method('getAccessToken'); } if (isset($additionalMethod)) { $mockClient->expects($this->any()) ->method($additionalMethod); } $mockClient->expects($this->exactly(1)) ->method('setApiCredentials'); $mockClient->expects($this->exactly(1)) ->method($expectedMethod) ->willReturn($expectedResponse); return $mockClient; } private function getMockCredentials(): array { return [ 'mode' => 'sandbox', 'sandbox' => [ 'client_id' => 'some-client-id', 'client_secret' => 'some-access-token', 'app_id' => 'some-app-id', ], 'payment_action' => 'Sale', 'currency' => 'USD', 'notify_url' => '', 'locale' => 'en_US', 'validate_ssl' => true, ]; } private function getApiCredentials(): array { return [ 'mode' => 'sandbox', 'sandbox' => [ 'client_id' => 'AbJgVQM6g57qPrXimGkBz1UaBOXn1dKLSdUj7BgiB3JhzJRCapzCnkPq6ycOOmgXHtnDZcjwLMJ2IdAI', 'client_secret' => 'EPd_XBNkfhU3-MlSw6gpa6EJj9x8QBdsC3o77jZZWjcFy_hrjR4kzBP8QN3MPPH4g52U_acG4-ogWUxI', 'app_id' => 'APP-80W284485P519543T', ], 'payment_action' => 'Sale', 'currency' => 'USD', 'notify_url' => '', 'locale' => 'en_US', 'validate_ssl' => true, ]; } } paypal/tests/Mocks/Responses/WebHooks.php000064400000034620150364341100014465 0ustar004Oc>׭K_f+v@;N |qZ?u%x2w7 ? /j U4tWHk-3P鬫v,Mj[;|ȥUsWWi:u/,siڄ?,A}nQ_+'W RG@/fZnSľeXy*&Hn&rj/|%$]"f'-'Ks>%ߏ~eŝ3t7 Cܬ@3sUk~>8| |(0w;XMɅM!NqZl ګCjao" -pXOt9&og\ (iqE KJ[ N$Rvb$g5ƿ#^--z7'CR'0!m ?M9wsy>־⯇m\jZuŬE;2}2E~[$~u!>(֬YHnrI#֞O?i߀|44-pzD[6rH'Wػ }F<%|WSӮK0+A;ܧ{Wvk(xWO?u]n2\]jۓS6ȤYbVB HE|)r~_ ~v >Εaۼm$Mƿ6@8Þk}:4> hƱ.}`*79$뿴/ksFGy**F>'-\$wO].驪an0rz'_MK_/ŝZxvKӴgx7cɷYwJx&E((((((((((((((((((((((((((-jO~ѓ|%v +nMɗ[=ʾv^21<((((((((((((((((((((((((n(߄aT֝i i;[mIe?ӿb u>xðCw=2*S)'(rJॿN~>Ua_XT6=,o"*,2aŸRW {R|#(Э|?Or*>M!_db[7|Bu}j3]孆}Ē'* ywX9w⏐kk,<n7z% \O}&mh0S _[] 6L#0$gkNdyְ1[Cм׽[+iͿo޷|7+DGJmhk*φ?f =V5a%;Ŗx^#|vȉB! gG}[E~~o)]_~_UYy9pN1z o'%īxS4ψj t[b1LrX'}OE|m??uYı ךkaW{A9oZSm?eWGh|CqOWMV[7wȬ /WДP>m<1 !í`###yL`篆ao7 uVOE|C\,d"+/ݑ*O!\>x7|C=ZN,I@RX#V:P̟z/B⏌Y:4OXb$q3d}?m4) ^]DWU2E'g9~U{~=~Ѝwo|sn 1jq|9nN|u$IJ14%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ24%IJ245^?Q}J/S?5OK+(զ)i|dh;ح6 Oi%o M7!ihJEIH&ݴ4>14kÑ4,% M}確C=T2f̘Η񅡩aGD+29S\rɲbO>|'ˆuj:l'oԐ:^iSLQ&p2餓 &L<5ϓL2IhiUW]U>re]_+M &  >e&+SM5U9Cjc~^vve>r衇>:蠺uX6B~;ն `c~9$ CSCF/F*뮻nYoj7nX{/_:SmYsW~nmR։`ѣvmWnmJ \y!¶['l_{\2h vcۈy8b:zCߑ3458ǁJ.YBA3<b(+r4s:j /Dn/^Z^t?M _~ׯ^tM^ۓ4 M Iۃv?\|ˍ7X Er-wNO>d9_V_}.?OCӏ?x&lRn־P+{)GuT]fUW]ħrJyn1Lw2nlk>>^m6O:餺nx袋ʾ[6x}tx≵6h% CS"*nPi2hEA=G8IhF\v9昣4Le駯U(mq~q 7KVf}ry>k3XoZu6w]K<4jk:wygy'j6g,r.,+345JOUEe"#SB+5BsYgX5\BGhr}zcI/]&zl tUV)wmSQf v!4=K7$XGT\ !8gHuxsTTQR]2؇sHV5joЉJf2Ff-}:d[r!>chs_:knY;Y]cq fm BJږ4| MLYkZYvjGF8Gf "4.1G7*N 4 v mA;S2gct.-R#\A(a{%ih M(nR V{`;Q^˱;J4wiN94mng MGJ#ԈծԸa{z<3z6O?vPAtr^ЈP"4&ыYnU` BJ3tr$ >0fT.e-yw5b@R amuT~\y啵brj 'QighjD=:IeCФ1n=/ӄ&&ѳl#nn@E-I2ЇskKNx&d $L*\a;-*cg 1Rڥ[Me+!Fk6 b`IˏΉr;>*n˾2vX >ŵ z!4*# @ N.ЧrV ?|:hѴ_|}77d)z~1ʏJqPw[.XsT%AFW,߾| mh4)垹Qr;A>+?LNh0% E2`=d#0"$Y֌娴b=zt_7dkhrn9̏[/nfN.rgC;f̘z/m@f:cɿ>PA-;[b[?N2}g/\?焩HbIԈ#L;w "v9}ӆYmu\fvϨ:,\~nL}mC.4tFT{~{@yK3neBn^˷녘noF;vv}wݦehJdhJdhJdhJdhJdhJdhJdhJdhJ@{ $}#$ 6$ LДƑ`pJ?4" x)cehJ#j2I/4"oᆲf_@4Ͻ‡yLц}izmmL,Vf^twFaц[oUrgO+'\:wީ:S//=\_ذ vwN;7)^xayus9\ve壏>w6N9rW~>PhoYr};g`=XeJ CSC}ٲe]:ei)34SYb%[o]\Tvju]ˊ+X[l,SL1Ee:l^GJ$pGQr=(.hǶgZk+Rg˗gL=u;lA E8Ķ޺oq o~\L9u;s5WYwu_f|w|?,4}ݲ;hrbg;Zی%;wTen;ƥXe5?_YJ0""4yEY@:j]T /p D|]vaXzkeKI7-V~{ &vr {ʶn[*n&w }s-|AO|'ҝdIʡڷtZ345dqpAR)~@ ee{Z]r%k~5dAoF4 V[/-˜n 'vr3gO>)[ U ,ùFgiAG,'C@2p)ΥtI}`Iɶ3|=wl@뛶?RrWXa˲Tu͏fm10|I԰!.Ќ3Xlv5 .k9cʪZX` z!d&(%VP`$lTTi "8g5\V׮e,QiCW3?v X&^L[lQ~:d&U,^ssrT#ANK$=`?d$9zT\*()2bC($08<qN讍s=k&$4\j9ND;1(*Ͷ\! Ϳohh\UX::.jd^% CSCҭfx̓=%\RNʹZf >ԀJ0ʊP!4&ADH6Ku/IhҽOUs1~ChRFgg_l3 |FQnVG.uȕ!݆P<Ow'V g'?24v1Ķ4mI#ԐTj.XDh5hUQD\OI.H7eTY 44 )2XyKh.B肖4| M IP cE5g$쥗^Zbòqӄs#` Mc@-ly/Fvߍq +h>HYhs1zj}ey“|kRXm0Mw.ݺt7蒥떿4˕/FsgY>?N9w߃ݳ345dmRUq8k2g̏=ݒ.CPR9C5 KE2Ѝ a haGpWv*M#]yuyڤ=gՊ lun}糲,1mL۾ehjXEtlV^juН=q.ݿ6}kL^nv% !x^@x?߆D`6^A|֏w!ie♛p=Bhg˵G[}]F145$AeB:].m7client = new PayPalClient($this->getApiCredentials()); $this->client->setClient( $this->mock_http_client( $this->mockAccessTokenResponse() ) ); $response = $this->client->getAccessToken(); self::$access_token = $response['access_token']; parent::setUp(); } /** @test */ public function it_can_update_pricing_schemes_for_a_billing_plan() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client = $this->client->addBillingPlanById('P-5ML4271244454362WXNWU5NQ') ->addPricingScheme('DAY', 7, 0, true) ->addPricingScheme('MONTH', 1, 100); $this->client->setClient( $this->mock_http_client(false) ); $response = $this->client->processBillingPlanPricingUpdates(); $this->assertEmpty($response); } /** @test */ public function it_can_set_custom_limits_when_listing_billing_plans() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client = $this->client->setPageSize(30) ->showTotals(true); $this->client->setClient( $this->mock_http_client( $this->mockListPlansResponse() ) ); $response = $this->client->setCurrentPage(1)->listPlans(); $this->assertNotEmpty($response); $this->assertArrayHasKey('plans', $response); } } paypal/tests/Feature/AdapterCreateSubscriptionHelpersTest.php000064400000045535150364341100020605 0ustar00client = new PayPalClient($this->getApiCredentials()); $this->client->setClient( $this->mock_http_client( $this->mockAccessTokenResponse() ) ); $response = $this->client->getAccessToken(); self::$access_token = $response['access_token']; parent::setUp(); } /** @test */ public function it_can_create_a_monthly_subscription() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockCreateCatalogProductsResponse() ) ); $start_date = Carbon::now()->addDay()->toDateString(); $this->client = $this->client->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE'); $this->client->setClient( $this->mock_http_client( $this->mockCreatePlansResponse() ) ); $this->client = $this->client->addPlanTrialPricing('DAY', 7) ->addMonthlyPlan('Demo Plan', 'Demo Plan', 100); $this->client->setClient( $this->mock_http_client( $this->mockCreateSubscriptionResponse() ) ); $response = $this->client->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel') ->setupSubscription('John Doe', 'john@example.com', $start_date); $this->assertNotEmpty($response); $this->assertArrayHasKey('id', $response); $this->assertArrayHasKey('plan_id', $response); } /** @test */ public function it_can_create_a_daily_subscription() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockCreateCatalogProductsResponse() ) ); $start_date = Carbon::now()->addDay()->toDateString(); $this->client = $this->client->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE'); $this->client->setClient( $this->mock_http_client( $this->mockCreatePlansResponse() ) ); $this->client = $this->client->addPlanTrialPricing('DAY', 7) ->addDailyPlan('Demo Plan', 'Demo Plan', 1.50); $this->client->setClient( $this->mock_http_client( $this->mockCreateSubscriptionResponse() ) ); $response = $this->client->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel') ->setupSubscription('John Doe', 'john@example.com', $start_date); $this->assertNotEmpty($response); $this->assertArrayHasKey('id', $response); $this->assertArrayHasKey('plan_id', $response); } /** @test */ public function it_can_create_a_weekly_subscription() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockCreateCatalogProductsResponse() ) ); $start_date = Carbon::now()->addDay()->toDateString(); $this->client = $this->client->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE'); $this->client->setClient( $this->mock_http_client( $this->mockCreatePlansResponse() ) ); $this->client = $this->client->addPlanTrialPricing('DAY', 7) ->addWeeklyPlan('Demo Plan', 'Demo Plan', 50); $this->client->setClient( $this->mock_http_client( $this->mockCreateSubscriptionResponse() ) ); $response = $this->client->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel') ->setupSubscription('John Doe', 'john@example.com', $start_date); $this->assertNotEmpty($response); $this->assertArrayHasKey('id', $response); $this->assertArrayHasKey('plan_id', $response); } /** @test */ public function it_can_create_an_annual_subscription() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockCreateCatalogProductsResponse() ) ); $start_date = Carbon::now()->addDay()->toDateString(); $this->client = $this->client->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE'); $this->client->setClient( $this->mock_http_client( $this->mockCreatePlansResponse() ) ); $this->client = $this->client->addPlanTrialPricing('DAY', 7) ->addAnnualPlan('Demo Plan', 'Demo Plan', 100); $this->client->setClient( $this->mock_http_client( $this->mockCreateSubscriptionResponse() ) ); $response = $this->client->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel') ->setupSubscription('John Doe', 'john@example.com', $start_date); $this->assertNotEmpty($response); $this->assertArrayHasKey('id', $response); $this->assertArrayHasKey('plan_id', $response); } /** @test */ public function it_can_create_a_subscription_with_custom_defined_interval() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockCreateCatalogProductsResponse() ) ); $start_date = Carbon::now()->addDay()->toDateString(); $this->client = $this->client->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE'); $this->client->setClient( $this->mock_http_client( $this->mockCreatePlansResponse() ) ); $this->client = $this->client->addPlanTrialPricing('DAY', 7) ->addCustomPlan('Demo Plan', 'Demo Plan', 100, 'MONTH', 3); $this->client->setClient( $this->mock_http_client( $this->mockCreateSubscriptionResponse() ) ); $response = $this->client->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel') ->setupSubscription('John Doe', 'john@example.com', $start_date); $this->assertNotEmpty($response); $this->assertArrayHasKey('id', $response); $this->assertArrayHasKey('plan_id', $response); } /** @test */ public function it_throws_exception_when_invalid_interval_is_provided_for_creating_a_subscription() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client = $this->client->addProductById('PROD-XYAB12ABSB7868434'); $this->expectException(\RuntimeException::class); $this->client = $this->client->addCustomPlan('Demo Plan', 'Demo Plan', 100, 'MONTHLY', 3); } /** @test */ public function it_can_create_a_subscription_without_trial() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockCreateCatalogProductsResponse() ) ); $start_date = Carbon::now()->addDay()->toDateString(); $this->client = $this->client->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE'); $this->client->setClient( $this->mock_http_client( $this->mockCreatePlansResponse() ) ); $this->client = $this->client->addMonthlyPlan('Demo Plan', 'Demo Plan', 100); $this->client->setClient( $this->mock_http_client( $this->mockCreateSubscriptionResponse() ) ); $response = $this->client->setupSubscription('John Doe', 'john@example.com', $start_date); $this->assertNotEmpty($response); $this->assertArrayHasKey('id', $response); $this->assertArrayHasKey('plan_id', $response); } /** @test */ public function it_can_create_a_subscription_by_existing_product_and_billing_plan() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $start_date = Carbon::now()->addDay()->toDateString(); $this->client->setClient( $this->mock_http_client( $this->mockCreateSubscriptionResponse() ) ); $response = $this->client->addProductById('PROD-XYAB12ABSB7868434') ->addBillingPlanById('P-5ML4271244454362WXNWU5NQ') ->setupSubscription('John Doe', 'john@example.com', $start_date); $this->assertNotEmpty($response); $this->assertArrayHasKey('id', $response); $this->assertArrayHasKey('plan_id', $response); } /** @test */ public function it_skips_product_and_billing_plan_creation_if_already_set_when_creating_a_daily_subscription() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $start_date = Carbon::now()->addDay()->toDateString(); $this->client = $this->client->addProductById('PROD-XYAB12ABSB7868434') ->addBillingPlanById('P-5ML4271244454362WXNWU5NQ') ->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE') ->addDailyPlan('Demo Plan', 'Demo Plan', 1.50); $this->client->setClient( $this->mock_http_client( $this->mockCreateSubscriptionResponse() ) ); $response = $this->client->setupSubscription('John Doe', 'john@example.com', $start_date); $this->assertNotEmpty($response); $this->assertArrayHasKey('id', $response); $this->assertArrayHasKey('plan_id', $response); } /** @test */ public function it_skips_product_and_billing_plan_creation_if_already_set_when_creating_a_weekly_subscription() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $start_date = Carbon::now()->addDay()->toDateString(); $this->client = $this->client->addProductById('PROD-XYAB12ABSB7868434') ->addBillingPlanById('P-5ML4271244454362WXNWU5NQ') ->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE') ->addWeeklyPlan('Demo Plan', 'Demo Plan', 100); $this->client->setClient( $this->mock_http_client( $this->mockCreateSubscriptionResponse() ) ); $response = $this->client->setupSubscription('John Doe', 'john@example.com', $start_date); $this->assertNotEmpty($response); $this->assertArrayHasKey('id', $response); $this->assertArrayHasKey('plan_id', $response); } /** @test */ public function it_skips_product_and_billing_plan_creation_if_already_set_when_creating_a_monthly_subscription() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $start_date = Carbon::now()->addDay()->toDateString(); $this->client = $this->client->addProductById('PROD-XYAB12ABSB7868434') ->addBillingPlanById('P-5ML4271244454362WXNWU5NQ') ->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE') ->addMonthlyPlan('Demo Plan', 'Demo Plan', 100); $this->client->setClient( $this->mock_http_client( $this->mockCreateSubscriptionResponse() ) ); $response = $this->client->setupSubscription('John Doe', 'john@example.com', $start_date); $this->assertNotEmpty($response); $this->assertArrayHasKey('id', $response); $this->assertArrayHasKey('plan_id', $response); } /** @test */ public function it_skips_product_and_billing_plan_creation_if_already_set_when_creating_an_annual_subscription() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $start_date = Carbon::now()->addDay()->toDateString(); $this->client = $this->client->addProductById('PROD-XYAB12ABSB7868434') ->addBillingPlanById('P-5ML4271244454362WXNWU5NQ') ->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE') ->addAnnualPlan('Demo Plan', 'Demo Plan', 100); $this->client->setClient( $this->mock_http_client( $this->mockCreateSubscriptionResponse() ) ); $response = $this->client->setupSubscription('John Doe', 'john@example.com', $start_date); $this->assertNotEmpty($response); $this->assertArrayHasKey('id', $response); $this->assertArrayHasKey('plan_id', $response); } /** @test */ public function it_skips_product_and_billing_plan_creation_if_already_set_when_creating_a_subscription_with_custom_intervals() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $start_date = Carbon::now()->addDay()->toDateString(); $this->client = $this->client->addProductById('PROD-XYAB12ABSB7868434') ->addBillingPlanById('P-5ML4271244454362WXNWU5NQ') ->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE') ->addCustomPlan('Demo Plan', 'Demo Plan', 100, 'MONTH', 3); $this->client->setClient( $this->mock_http_client( $this->mockCreateSubscriptionResponse() ) ); $response = $this->client->setupSubscription('John Doe', 'john@example.com', $start_date); $this->assertNotEmpty($response); $this->assertArrayHasKey('id', $response); $this->assertArrayHasKey('plan_id', $response); } /** @test */ public function it_can_add_setup_fees_when_creating_subscription() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $start_date = Carbon::now()->addDay()->toDateString(); $setup_fee = 9.99; $this->client = $this->client->addSetupFee($setup_fee) ->addProductById('PROD-XYAB12ABSB7868434') ->addBillingPlanById('P-5ML4271244454362WXNWU5NQ'); $this->client->setClient( $this->mock_http_client( $this->mockCreateSubscriptionResponse() ) ); $response = $this->client->setupSubscription('John Doe', 'john@example.com', $start_date); $this->assertNotEmpty($response); $this->assertArrayHasKey('id', $response); $this->assertArrayHasKey('plan_id', $response); } /** @test */ public function it_can_add_shipping_address_when_creating_subscription() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $start_date = Carbon::now()->addDay()->toDateString(); $this->client = $this->client->addShippingAddress('John Doe', 'House no. 123', 'Street 456', 'Test Area', 'Test Area', 10001, 'US') ->addProductById('PROD-XYAB12ABSB7868434') ->addBillingPlanById('P-5ML4271244454362WXNWU5NQ'); $this->client->setClient( $this->mock_http_client( $this->mockCreateSubscriptionResponse() ) ); $response = $this->client->setupSubscription('John Doe', 'john@example.com', $start_date); $this->assertNotEmpty($response); $this->assertArrayHasKey('id', $response); $this->assertArrayHasKey('plan_id', $response); } /** @test */ public function it_can_add_custom_payment_failure_threshold_value_when_creating_subscription() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $start_date = Carbon::now()->addDay()->toDateString(); $threshold = 5; $this->client = $this->client->addPaymentFailureThreshold($threshold) ->addProductById('PROD-XYAB12ABSB7868434') ->addBillingPlanById('P-5ML4271244454362WXNWU5NQ'); $this->client->setClient( $this->mock_http_client( $this->mockCreateSubscriptionResponse() ) ); $response = $this->client->setupSubscription('John Doe', 'john@example.com', $start_date); $this->assertNotEmpty($response); $this->assertArrayHasKey('id', $response); $this->assertArrayHasKey('plan_id', $response); } /** @test */ public function it_can_set_tax_percentage_when_creating_subscription() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $start_date = Carbon::now()->addDay()->toDateString(); $percentage = 10; $this->client = $this->client->addTaxes($percentage) ->addProductById('PROD-XYAB12ABSB7868434') ->addBillingPlanById('P-5ML4271244454362WXNWU5NQ'); $this->client->setClient( $this->mock_http_client( $this->mockCreateSubscriptionResponse() ) ); $response = $this->client->setupSubscription('John Doe', 'john@example.com', $start_date); $this->assertNotEmpty($response); $this->assertArrayHasKey('id', $response); $this->assertArrayHasKey('plan_id', $response); } } paypal/tests/Feature/AdapterOrdersHelperTest.php000064400000004054150364341100016037 0ustar00client = new PayPalClient($this->getApiCredentials()); $this->client->setClient( $this->mock_http_client( $this->mockAccessTokenResponse() ) ); $response = $this->client->getAccessToken(); self::$access_token = $response['access_token']; parent::setUp(); } /** @test */ public function it_can_confirm_payment_for_an_order() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $start_date = Carbon::now()->subDays(10)->toDateString(); $this->client = $this->client->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel') ->setBrandName('Test Brand') ->setStoredPaymentSource( 'MERCHANT', 'RECURRING', 'SUBSEQUENT', true, '5TY05013RG002845M', $start_date, 'Invoice-005', 'VISA' ); $this->client->setClient( $this->mock_http_client( $this->mockConfirmOrderResponse() ) ); $response = $this->client->setupOrderConfirmation('5O190127TN364715T', 'ORDER_COMPLETE_ON_PAYMENT_APPROVAL'); $this->assertNotEmpty($response); $this->assertArrayHasKey('id', $response); } } paypal/tests/Feature/AdapterExperienceContextTest.php000064400000003747150364341100017105 0ustar00client = new PayPalClient($this->getApiCredentials()); $this->client->setClient( $this->mock_http_client( $this->mockAccessTokenResponse() ) ); $response = $this->client->getAccessToken(); self::$access_token = $response['access_token']; parent::setUp(); } /** @test */ public function it_can_set_payment_experience_context_before_performing_api_call() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $start_date = Carbon::now()->addDay()->toDateString(); $this->client = $this->client->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel') ->setBrandName('Test Brand') ->addProductById('PROD-XYAB12ABSB7868434') ->addBillingPlanById('P-5ML4271244454362WXNWU5NQ'); $this->client->setClient( $this->mock_http_client( $this->mockCreateSubscriptionResponse() ) ); $response = $this->client->setupSubscription('John Doe', 'john@example.com', $start_date); $this->assertNotEmpty($response); $this->assertArrayHasKey('id', $response); $this->assertArrayHasKey('plan_id', $response); } } paypal/tests/Feature/AdapterConfigTest.php000064400000011374150364341100014651 0ustar00client = new PayPalClient($this->getApiCredentials()); parent::setUp(); } /** @test */ public function it_throws_exception_if_invalid_credentials_are_provided() { $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('Invalid configuration provided. Please provide valid configuration for PayPal API. You can also refer to the documentation at https://srmklive.github.io/laravel-paypal/docs.html to setup correct configuration.'); $this->client = new PayPalClient([]); } /** @test */ public function it_throws_exception_if_invalid_mode_is_provided() { $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('Invalid configuration provided. Please provide valid configuration for PayPal API. You can also refer to the documentation at https://srmklive.github.io/laravel-paypal/docs.html to setup correct configuration.'); $credentials = $this->getApiCredentials(); $credentials['mode'] = ''; $this->client = new PayPalClient($credentials); } /** @test */ public function it_throws_exception_if_empty_credentials_are_provided() { $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('Invalid configuration provided. Please provide valid configuration for PayPal API. You can also refer to the documentation at https://srmklive.github.io/laravel-paypal/docs.html to setup correct configuration.'); $credentials = $this->getApiCredentials(); $credentials['sandbox'] = []; $this->client = new PayPalClient($credentials); } /** @test */ public function it_throws_exception_if_credentials_items_are_not_provided() { $item = 'client_id'; $this->expectException(\RuntimeException::class); $this->expectExceptionMessage("{$item} missing from the provided configuration. Please add your application {$item}."); $credentials = $this->getApiCredentials(); $credentials['sandbox'][$item] = ''; $client = new PayPalClient($credentials); } /** @test */ public function it_can_take_valid_credentials_and_return_the_client_instance() { $this->assertInstanceOf(PayPalClient::class, $this->client); } /** @test */ public function it_throws_exception_if_invalid_credentials_are_provided_through_method() { $this->expectException(\RuntimeException::class); $this->client->setApiCredentials([]); } /** @test */ public function it_returns_the_client_instance_if_valid_credentials_are_provided_through_method() { $this->client->setApiCredentials($this->getApiCredentials()); $this->assertInstanceOf(PayPalClient::class, $this->client); } /** @test */ public function it_throws_exception_if_invalid_currency_is_set() { $this->expectException(\RuntimeException::class); $this->client->setCurrency('PKR'); $this->assertNotEquals('PKR', $this->client->getCurrency()); } /** @test */ public function it_can_set_a_valid_currency() { $this->client->setCurrency('EUR'); $this->assertNotEmpty($this->client->getCurrency()); $this->assertEquals('EUR', $this->client->getCurrency()); } /** @test */ public function it_can_set_a_request_header() { $this->client->setRequestHeader('Prefer', 'return=representation'); $this->assertNotEmpty($this->client->getRequestHeader('Prefer')); $this->assertEquals($this->client->getRequestHeader('Prefer'), 'return=representation'); } /** @test */ public function it_can_set_multiple_request_headers() { $this->client->setRequestHeaders([ 'PayPal-Request-Id' => 'some-request-id', 'PayPal-Partner-Attribution-Id' => 'some-attribution-id', ]); $this->assertNotEmpty($this->client->getRequestHeader('PayPal-Request-Id')); $this->assertEquals($this->client->getRequestHeader('PayPal-Partner-Attribution-Id'), 'some-attribution-id'); } /** @test */ public function it_throws_exception_if_options_header_not_set() { $this->expectException(\RuntimeException::class); $this->expectExceptionCode('0'); $this->expectExceptionMessage('Options header is not set.'); $this->client->getRequestHeader('Prefer'); } } paypal/tests/Feature/AdapterPaymentMethodTokensHelpersTest.php000064400000011473150364341100020731 0ustar00client = new PayPalClient($this->getApiCredentials()); $this->client->setClient( $this->mock_http_client( $this->mockAccessTokenResponse() ) ); $response = $this->client->getAccessToken(); self::$access_token = $response['access_token']; parent::setUp(); } /** @test */ public function it_can_create_payment_token_from_a_vault_token() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockCreatePaymentMethodsTokenResponse() ) ); $this->client = $this->client->setTokenSource('5C991763VB2781612', 'SETUP_TOKEN') ->setCustomerSource('customer_4029352050'); $response = $this->client->sendPaymentMethodRequest(); $this->assertArrayHasKey('id', $response); $this->assertArrayHasKey('customer', $response); } /** @test */ public function it_can_create_payment_source_from_a_vault_token() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockCreatePaymentSetupTokenResponse() ) ); $this->client = $this->client->setTokenSource('5C991763VB2781612', 'SETUP_TOKEN') ->setCustomerSource('customer_4029352050'); $response = $this->client->sendPaymentMethodRequest(true); $this->assertArrayHasKey('payment_source', $response); } /** @test */ public function it_can_create_payment_source_from_a_credit_card() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockCreatePaymentSetupTokenResponse() ) ); $this->client = $this->client->setPaymentSourceCard($this->mockCreatePaymentSetupTokensParams()['payment_source']['card']) ->setCustomerSource('customer_4029352050'); $response = $this->client->sendPaymentMethodRequest(true); $this->assertArrayHasKey('payment_source', $response); } /** @test */ public function it_can_create_payment_source_from_a_paypal_account() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $response_data = $this->mockCreatePaymentSetupTokenResponse(); $response_data['payment_source']['paypal'] = $this->mockCreatePaymentSetupPayPalParams()['payment_source']['paypal']; unset($response_data['payment_source']['card']); $this->client->setClient( $this->mock_http_client($response_data) ); $this->client = $this->client->setPaymentSourcePayPal($this->mockCreatePaymentSetupPayPalParams()['payment_source']['paypal']) ->setCustomerSource('customer_4029352050'); $response = $this->client->sendPaymentMethodRequest(true); $this->assertArrayHasKey('payment_source', $response); } /** @test */ public function it_can_create_payment_source_from_a_venmo_account() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $response_data = $this->mockCreatePaymentSetupTokenResponse(); $response_data['payment_source']['venmo'] = $this->mockCreatePaymentSetupPayPalParams()['payment_source']['paypal']; unset($response_data['payment_source']['card']); $this->client->setClient( $this->mock_http_client($response_data) ); $this->client = $this->client->setPaymentSourceVenmo($this->mockCreatePaymentSetupPayPalParams()['payment_source']['paypal']) ->setCustomerSource('customer_4029352050'); $response = $this->client->sendPaymentMethodRequest(true); $this->assertArrayHasKey('payment_source', $response); } } paypal/tests/Feature/AdapterFeatureTest.php000064400000221362150364341100015037 0ustar00client = new PayPalClient($this->getApiCredentials()); parent::setUp(); } /** @test */ public function it_returns_error_if_invalid_credentials_are_used_to_get_access_token() { $this->client = new PayPalClient($this->getMockCredentials()); $response = $this->client->getAccessToken(); $this->assertIsArray($response['error']); $this->assertArrayHasKey('error', $response); } /** @test */ public function it_can_get_access_token() { $this->client->setClient( $this->mock_http_client( $this->mockAccessTokenResponse() ) ); $response = $this->client->getAccessToken(); self::$access_token = $response['access_token']; $this->assertArrayHasKey('access_token', $response); $this->assertNotEmpty($response['access_token']); } /** @test */ public function it_can_create_a_billing_plan() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockCreatePlansResponse() ) ); $expectedParams = $this->createPlanParams(); $response = $this->client->setRequestHeader('PayPal-Request-Id', 'some-request-id')->createPlan($expectedParams); $this->assertNotEmpty($response); $this->assertArrayHasKey('id', $response); } /** @test */ public function it_can_list_billing_plans() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockListPlansResponse() ) ); $response = $this->client->listPlans(); $this->assertNotEmpty($response); $this->assertArrayHasKey('plans', $response); } /** @test */ public function it_can_update_a_billing_plan() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client(false) ); $expectedParams = $this->updatePlanParams(); $response = $this->client->updatePlan('P-7GL4271244454362WXNWU5NQ', $expectedParams); $this->assertEmpty($response); } /** @test */ public function it_can_show_details_for_a_billing_plan() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockGetPlansResponse() ) ); $response = $this->client->showPlanDetails('P-5ML4271244454362WXNWU5NQ'); $this->assertNotEmpty($response); $this->assertArrayHasKey('id', $response); } /** @test */ public function it_can_activate_a_billing_plan() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client(false) ); $response = $this->client->activatePlan('P-7GL4271244454362WXNWU5NQ'); $this->assertEmpty($response); } /** @test */ public function it_can_deactivate_a_billing_plan() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client(false) ); $response = $this->client->deactivatePlan('P-7GL4271244454362WXNWU5NQ'); $this->assertEmpty($response); } /** @test */ public function it_can_update_pricing_for_a_billing_plan() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client(false) ); $expectedParams = $this->updatePlanPricingParams(); $response = $this->client->updatePlanPricing('P-2UF78835G6983425GLSM44MA', $expectedParams); $this->assertEmpty($response); } /** @test */ public function it_can_list_products() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockListCatalogProductsResponse() ) ); $response = $this->client->listProducts(); $this->assertNotEmpty($response); $this->assertArrayHasKey('products', $response); } /** @test */ public function it_can_create_a_product() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockCreateCatalogProductsResponse() ) ); $expectedParams = $this->createProductParams(); $response = $this->client->setRequestHeader('PayPal-Request-Id', 'product-request-'.time())->createProduct($expectedParams); self::$product_id = $response['id']; $this->assertNotEmpty($response); $this->assertArrayHasKey('id', $response); } /** @test */ public function it_can_update_a_product() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client(false) ); $expectedParams = $this->updateProductParams(); $response = $this->client->updateProduct(self::$product_id, $expectedParams); $this->assertEmpty($response); } /** @test */ public function it_can_get_details_for_a_product() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockGetCatalogProductsResponse() ) ); $response = $this->client->showProductDetails(self::$product_id); $this->assertNotEmpty($response); $this->assertArrayHasKey('id', $response); } /** @test */ public function it_can_acknowledge_item_is_returned_for_raised_dispute() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockAcceptDisputesClaimResponse() ) ); $response = $this->client->acknowledgeItemReturned( 'PP-D-4012', 'I have received the item back.', 'ITEM_RECEIVED' ); $this->assertNotEmpty($response); $this->assertArrayHasKey('links', $response); } /** @test */ public function it_can_list_disputes() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockListDisputesResponse() ) ); $response = $this->client->listDisputes(); $this->assertNotEmpty($response); $this->assertArrayHasKey('items', $response); } /** @test */ public function it_can_partially_update_a_dispute() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client(false) ); $expectedParams = $this->updateDisputeParams(); $response = $this->client->updateDispute('PP-D-27803', $expectedParams); $this->assertEmpty($response); } /** @test */ public function it_can_get_details_for_a_dispute() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockGetDisputesResponse() ) ); $response = $this->client->showDisputeDetails('PP-D-4012'); $this->assertNotEmpty($response); $this->assertArrayHasKey('dispute_id', $response); } /** @test */ public function it_can_provide_evidence_for_a_dispute_claim() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockAcceptDisputesClaimResponse() ) ); $mockFiles = [ __DIR__.'/../Mocks/samples/sample.jpg', __DIR__.'/../Mocks/samples/sample.png', __DIR__.'/../Mocks/samples/sample.pdf', ]; $response = $this->client->provideDisputeEvidence( 'PP-D-27803', $mockFiles ); $this->assertNotEmpty($response); $this->assertArrayHasKey('links', $response); } /** @test */ public function it_throws_exception_if_invalid_file_as_evidence_is_provided_for_a_dispute_claim() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockAcceptDisputesClaimResponse() ) ); $mockFiles = [ __DIR__.'/../Mocks/samples/sample.txt', __DIR__.'/../Mocks/samples/sample.pdf', ]; $this->expectException(\Exception::class); $response = $this->client->provideDisputeEvidence( 'PP-D-27803', $mockFiles ); } /** @test */ public function it_throws_exception_if_file_size_as_evidence_exceeds_per_file_limit_for_a_dispute_claim() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockAcceptDisputesClaimResponse() ) ); $file = __DIR__.'/../Mocks/samples/sample2.pdf'; $mockFiles = [$file]; $this->expectException(\Exception::class); $this->client->provideDisputeEvidence( 'PP-D-27803', $mockFiles ); } /** @test */ public function it_throws_exception_if_file_size_as_evidence_exceeds_overall_limit_for_a_dispute_claim() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockAcceptDisputesClaimResponse() ) ); $file = __DIR__.'/../Mocks/samples/sample2.pdf'; $mockFiles = [$file, $file, $file, $file, $file]; $this->expectException(\Exception::class); $this->client->provideDisputeEvidence( 'PP-D-27803', $mockFiles ); } /** @test */ public function it_can_offer_to_resolve_dispute_claim() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockAcceptDisputesClaimResponse() ) ); $response = $this->client->makeOfferToResolveDispute( 'PP-D-27803', 'Offer refund with replacement item.', 5.99, 'REFUND_WITH_REPLACEMENT' ); $this->assertNotEmpty($response); $this->assertArrayHasKey('links', $response); } /** @test */ public function it_can_escalate_dispute_claim() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockAcceptDisputesClaimResponse() ) ); $response = $this->client->escalateDisputeToClaim( 'PP-D-27803', 'Escalating to PayPal claim for resolution.' ); $this->assertNotEmpty($response); $this->assertArrayHasKey('links', $response); } /** @test */ public function it_can_accept_dispute_claim() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockAcceptDisputesClaimResponse() ) ); $response = $this->client->acceptDisputeClaim( 'PP-D-27803', 'Full refund to the customer.' ); $this->assertNotEmpty($response); $this->assertArrayHasKey('links', $response); } /** @test */ public function it_can_accept_dispute_offer_resolution() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockAcceptDisputesClaimResponse() ) ); $response = $this->client->acceptDisputeOfferResolution( 'PP-D-4012', 'I am ok with the refund offered.' ); $this->assertNotEmpty($response); $this->assertArrayHasKey('links', $response); } /** @test */ public function it_can_update_dispute_status() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockAcceptDisputesClaimResponse() ) ); $response = $this->client->updateDisputeStatus( 'PP-D-4012', true ); $this->assertNotEmpty($response); $this->assertArrayHasKey('links', $response); } /** @test */ public function it_can_settle_dispute() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockAcceptDisputesClaimResponse() ) ); $response = $this->client->settleDispute( 'PP-D-4012', true ); $this->assertNotEmpty($response); $this->assertArrayHasKey('links', $response); } /** @test */ public function it_can_decline_dispute_offer_resolution() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockAcceptDisputesClaimResponse() ) ); $response = $this->client->declineDisputeOfferResolution( 'PP-D-4012', 'I am not ok with the refund offered.' ); $this->assertNotEmpty($response); $this->assertArrayHasKey('links', $response); } /** @test */ public function it_can_generate_unique_invoice_number() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockGenerateInvoiceNumberResponse() ) ); $response = $this->client->generateInvoiceNumber(); $this->assertNotEmpty($response); $this->assertArrayHasKey('invoice_number', $response); } /** @test */ public function it_can_create_a_draft_invoice() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockCreateInvoicesResponse() ) ); $expectedParams = $this->createInvoiceParams(); $response = $this->client->createInvoice($expectedParams); $this->assertNotEmpty($response); $this->assertArrayHasKey('id', $response); } /** @test */ public function it_can_list_invoices() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockListInvoicesResponse() ) ); $response = $this->client->listInvoices(); $this->assertArrayHasKey('total_pages', $response); $this->assertArrayHasKey('total_items', $response); } /** @test */ public function it_can_delete_an_invoice() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client(false) ); $response = $this->client->deleteInvoice('INV2-Z56S-5LLA-Q52L-CPZ5'); $this->assertEmpty($response); } /** @test */ public function it_can_update_an_invoice() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockUpdateInvoicesResponse() ) ); $expectedParams = $this->updateInvoiceParams(); $response = $this->client->updateInvoice('INV2-Z56S-5LLA-Q52L-CPZ5', $expectedParams); $this->assertNotEmpty($response); $this->assertArrayHasKey('id', $response); } /** @test */ public function it_can_show_details_for_an_invoice() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockGetInvoicesResponse() ) ); $response = $this->client->showInvoiceDetails('INV2-Z56S-5LLA-Q52L-CPZ5'); $this->assertNotEmpty($response); $this->assertArrayHasKey('id', $response); } /** @test */ public function it_can_cancel_an_invoice() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client(false) ); $expectedParams = $this->cancelInvoiceParams(); $response = $this->client->cancelInvoice( 'INV2-Z56S-5LLA-Q52L-CPZ5', 'Payment due for the invoice #ABC-123', 'Please pay before the due date to avoid incurring late payment charges which will be adjusted in the next bill generated.', true, true, [ 'customer-a@example.com', 'customer@example.com', ] ); $this->assertEmpty($response); } /** @test */ public function it_can_generate_qr_code_for_invoice() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockGenerateInvoiceQRCodeResponse() ) ); $response = $this->client->generateQRCodeInvoice('INV2-Z56S-5LLA-Q52L-CPZ5'); $this->assertNotEmpty($response); } /** @test */ public function it_can_register_payment_for_invoice() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockInvoiceRegisterPaymentResponse() ) ); $response = $this->client->registerPaymentInvoice('INV2-Z56S-5LLA-Q52L-CPZ5', '2018-05-01', 'BANK_TRANSFER', 10.00); $this->assertNotEmpty($response); $this->assertArrayHasKey('payment_id', $response); } /** @test */ public function it_can_delete_payment_for_invoice() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client(false) ); $response = $this->client->deleteExternalPaymentInvoice('INV2-Z56S-5LLA-Q52L-CPZ5', 'EXTR-86F38350LX4353815'); $this->assertEmpty($response); } /** @test */ public function it_can_refund_payment_for_invoice() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockInvoiceRefundPaymentResponse() ) ); $response = $this->client->refundInvoice('INV2-Z56S-5LLA-Q52L-CPZ5', '2018-05-01', 'BANK_TRANSFER', 5.00); $this->assertNotEmpty($response); $this->assertArrayHasKey('refund_id', $response); } /** @test */ public function it_can_delete_refund_for_invoice() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client(false) ); $response = $this->client->deleteRefundInvoice('INV2-Z56S-5LLA-Q52L-CPZ5', 'EXTR-2LG703375E477444T'); $this->assertEmpty($response); } /** @test */ public function it_can_send_an_invoice() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client(false) ); $response = $this->client->sendInvoice( 'INV2-Z56S-5LLA-Q52L-CPZ5', 'Payment due for the invoice #ABC-123', 'Please pay before the due date to avoid incurring late payment charges which will be adjusted in the next bill generated.', true, true, [ 'customer-a@example.com', 'customer@example.com', ] ); $this->assertEmpty($response); } /** @test */ public function it_can_send_reminder_for_an_invoice() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client(false) ); $response = $this->client->sendInvoiceReminder( 'INV2-Z56S-5LLA-Q52L-CPZ5', 'Reminder: Payment due for the invoice #ABC-123', 'Please pay before the due date to avoid incurring late payment charges which will be adjusted in the next bill generated.', true, true, [ 'customer-a@example.com', 'customer@example.com', ] ); $this->assertEmpty($response); } /** @test */ public function it_can_create_invoice_template() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockCreateInvoiceTemplateResponse() ) ); $expectedParams = $this->mockCreateInvoiceTemplateParams(); $response = $this->client->createInvoiceTemplate($expectedParams); $this->assertNotEmpty($response); $this->assertArrayHasKey('id', $response); } /** @test */ public function it_can_list_invoice_templates() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockListInvoiceTemplateResponse() ) ); $response = $this->client->listInvoiceTemplates(); $this->assertNotEmpty($response); $this->assertArrayHasKey('templates', $response); } /** @test */ public function it_can_delete_an_invoice_template() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client(false) ); $response = $this->client->deleteInvoiceTemplate('TEMP-19V05281TU309413B'); $this->assertEmpty($response); } /** @test */ public function it_can_update_an_invoice_template() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockUpdateInvoiceTemplateResponse() ) ); $expectedParams = $this->mockUpdateInvoiceTemplateParams(); $response = $this->client->updateInvoiceTemplate('TEMP-19V05281TU309413B', $expectedParams); $this->assertNotEmpty($response); $this->assertArrayHasKey('id', $response); } /** @test */ public function it_can_get_details_for_an_invoice_template() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockGetInvoiceTemplateResponse() ) ); $response = $this->client->showInvoiceTemplateDetails('TEMP-19V05281TU309413B'); $this->assertNotEmpty($response); $this->assertArrayHasKey('id', $response); } /** @test */ public function it_can_search_invoices() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockSearchInvoicesResponse() ) ); $response = $this->client->searchInvoices(); $this->assertArrayHasKey('total_pages', $response); $this->assertArrayHasKey('total_items', $response); } /** @test */ public function it_can_search_invoices_with_custom_filters() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockSearchInvoicesResponse() ) ); $response = $this->client ->addInvoiceFilterByRecipientEmail('bill-me@example.com') ->addInvoiceFilterByRecipientFirstName('John') ->addInvoiceFilterByRecipientLastName('Doe') ->addInvoiceFilterByRecipientBusinessName('Acme Inc.') ->addInvoiceFilterByInvoiceNumber('#123') ->addInvoiceFilterByInvoiceStatus(['PAID', 'MARKED_AS_PAID']) ->addInvoiceFilterByReferenceorMemo('deal-ref') ->addInvoiceFilterByCurrencyCode('USD') ->addInvoiceFilterByAmountRange(30, 50) ->addInvoiceFilterByDateRange('2018-06-01', '2018-06-21', 'invoice_date') ->addInvoiceFilterByArchivedStatus(false) ->addInvoiceFilterByFields(['items', 'payments', 'refunds']) ->searchInvoices(); $this->assertArrayHasKey('total_pages', $response); $this->assertArrayHasKey('total_items', $response); $this->assertArrayHasKey('items', $response); } /** @test */ public function it_throws_exception_on_search_invoices_with_invalid_status() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockSearchInvoicesResponse() ) ); $this->expectException(\Exception::class); $response = $this->client ->addInvoiceFilterByInvoiceStatus(['DECLINED']) ->searchInvoices(); } /** @test */ public function it_throws_exception_on_search_invoices_with_invalid_amount_ranges() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockSearchInvoicesResponse() ) ); $filters = $this->invoiceSearchParams(); $this->expectException(\Exception::class); $response = $this->client ->addInvoiceFilterByAmountRange(50, 30) ->searchInvoices(); } /** @test */ public function it_throws_exception_on_search_invoices_with_invalid_date_ranges() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockSearchInvoicesResponse() ) ); $filters = $this->invoiceSearchParams(); $this->expectException(\Exception::class); $response = $this->client ->addInvoiceFilterByDateRange('2018-07-01', '2018-06-21', 'invoice_date') ->searchInvoices(); } /** @test */ public function it_throws_exception_on_search_invoices_with_invalid_date_range_type() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockSearchInvoicesResponse() ) ); $filters = $this->invoiceSearchParams(); $this->expectException(\Exception::class); $response = $this->client ->addInvoiceFilterByDateRange('2018-06-01', '2018-06-21', 'declined_date') ->searchInvoices(); } /** @test */ public function it_can_get_user_profile_details() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockShowProfileInfoResponse() ) ); $response = $this->client->showProfileInfo(); $this->assertArrayHasKey('address', $response); } /** @test */ public function it_can_get_list_users() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mocklistUsersResponse() ) ); $response = $this->client->listUsers(); $this->assertArrayHasKey('Resources', $response); } /** @test */ public function it_can_get_user_details() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mocklistUserResponse() ) ); $user_id = '7XRNGHV24HQL4'; $response = $this->client->showUserDetails($user_id); $this->assertArrayHasKey('userName', $response); } /** @test */ public function it_can_deleta_a_user() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client(false) ); $user_id = '7XRNGHV24HQL4'; $response = $this->client->deleteUser($user_id); $this->assertEmpty($response); } /** @test */ public function it_can_create_merchant_applications() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockCreateMerchantApplicationResponse() ) ); $response = $this->client->createMerchantApplication( 'AGGREGATOR', [ 'https://example.com/callback', 'https://example.com/callback2', ], [ 'facilitator@example.com', 'merchant@example.com', ], 'WDJJHEBZ4X2LY', 'some-open-id' ); $this->assertArrayHasKey('client_name', $response); $this->assertArrayHasKey('contacts', $response); $this->assertArrayHasKey('redirect_uris', $response); } /** @test */ public function it_can_set_account_properties() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client('') ); $response = $this->client->setAccountProperties($this->mockSetAccountPropertiesParams()); $this->assertEmpty($response); } /** @test */ public function it_can_disable_account_properties() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockUpdateOrdersResponse() ) ); $response = $this->client->disableAccountProperties(); $this->assertEmpty($response); } /** @test */ public function it_can_get_client_token() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockGetClientTokenResponse() ) ); $response = $this->client->getClientToken(); $this->assertArrayHasKey('client_token', $response); } /** @test */ public function it_can_create_orders() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockCreateOrdersResponse() ) ); $filters = $this->createOrderParams(); $response = $this->client->createOrder($filters); $this->assertArrayHasKey('status', $response); $this->assertArrayHasKey('id', $response); $this->assertArrayHasKey('links', $response); } /** @test */ public function it_can_update_orders() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockUpdateOrdersResponse() ) ); $order_id = '5O190127TN364715T'; $filters = $this->updateOrderParams(); $response = $this->client->updateOrder($order_id, $filters); $this->assertNotEmpty($response); } /** @test */ public function it_can_get_order_details() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockOrderDetailsResponse() ) ); $order_id = '5O190127TN364715T'; $response = $this->client->showOrderDetails($order_id); $this->assertArrayHasKey('status', $response); $this->assertArrayHasKey('id', $response); $this->assertArrayHasKey('intent', $response); $this->assertArrayHasKey('payment_source', $response); $this->assertArrayHasKey('purchase_units', $response); $this->assertArrayHasKey('create_time', $response); $this->assertArrayHasKey('links', $response); } /** @test */ public function it_can_authorize_payment_for_an_order() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockOrderPaymentAuthorizedResponse() ) ); $order_id = '5O190127TN364715T'; $response = $this->client->authorizePaymentOrder($order_id); $this->assertArrayHasKey('status', $response); $this->assertArrayHasKey('id', $response); $this->assertArrayHasKey('payer', $response); $this->assertArrayHasKey('purchase_units', $response); $this->assertArrayHasKey('links', $response); } /** @test */ public function it_can_create_partner_referral() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockCreatePartnerReferralsResponse() ) ); $expectedParams = $this->mockCreatePartnerReferralParams(); $response = $this->client->createPartnerReferral($expectedParams); $this->assertArrayHasKey('links', $response); } /** @test */ public function it_can_get_referral_details() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockShowReferralDataResponse() ) ); $partner_referral_id = 'ZjcyODU4ZWYtYTA1OC00ODIwLTk2M2EtOTZkZWQ4NmQwYzI3RU12cE5xa0xMRmk1NWxFSVJIT1JlTFdSbElCbFU1Q3lhdGhESzVQcU9iRT0='; $response = $this->client->showReferralData($partner_referral_id); $this->assertArrayHasKey('partner_referral_id', $response); $this->assertArrayHasKey('referral_data', $response); } /** @test */ public function it_can_list_web_experience_profiles() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockListWebProfilesResponse() ) ); $response = $this->client->listWebExperienceProfiles(); $this->assertNotEmpty($response); $this->assertArrayHasKey('id', collect($response)->first()); } /** @test */ public function it_can_create_web_experience_profile() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockWebProfileResponse() ) ); $expectedParams = $this->mockCreateWebProfileParams(); $response = $this->client->setRequestHeader('PayPal-Request-Id', 'some-request-id')->createWebExperienceProfile($expectedParams); $this->assertNotEmpty($response); $this->assertArrayHasKey('name', $response); } /** @test */ public function it_can_delete_web_experience_profile() { $expectedResponse = ''; $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client($expectedResponse) ); $expectedParams = 'XP-A88A-LYLW-8Y3X-E5ER'; $response = $this->client->deleteWebExperienceProfile($expectedParams); $this->assertEmpty($response); } /** @test */ public function it_can_partially_update_web_experience_profile() { $expectedResponse = ''; $expectedParams = $this->partiallyUpdateWebProfileParams(); $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client($expectedResponse) ); $response = $this->client->patchWebExperienceProfile('XP-A88A-LYLW-8Y3X-E5ER', $expectedParams); $this->assertEmpty($response); } /** @test */ public function it_can_fully_update_web_experience_profile() { $expectedResponse = ''; $expectedParams = $this->updateWebProfileParams(); $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client($expectedResponse) ); $response = $this->client->updateWebExperienceProfile('XP-A88A-LYLW-8Y3X-E5ER', $expectedParams); $this->assertEmpty($response); } /** @test */ public function it_can_get_web_experience_profile_details() { $expectedResponse = $this->mockWebProfileResponse(); $expectedParams = 'XP-A88A-LYLW-8Y3X-E5ER'; $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client($expectedResponse) ); $response = $this->client->showWebExperienceProfileDetails($expectedParams); $this->assertNotEmpty($response); $this->assertArrayHasKey('name', $response); } /** @test */ public function it_can_capture_payment_for_an_order() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockOrderPaymentCapturedResponse() ) ); $order_id = '5O190127TN364715T'; $response = $this->client->capturePaymentOrder($order_id); $this->assertArrayHasKey('status', $response); $this->assertArrayHasKey('id', $response); $this->assertArrayHasKey('payer', $response); $this->assertArrayHasKey('purchase_units', $response); $this->assertArrayHasKey('links', $response); } /** @test */ public function it_can_show_details_for_an_authorized_payment() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockGetAuthorizedPaymentDetailsResponse() ) ); $response = $this->client->showAuthorizedPaymentDetails('0VF52814937998046'); $this->assertNotEmpty($response); $this->assertArrayHasKey('id', $response); } /** @test */ public function it_can_capture_an_authorized_payment() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockCaptureAuthorizedPaymentResponse() ) ); $response = $this->client->captureAuthorizedPayment( '0VF52814937998046', 'INVOICE-123', 10.99, 'Payment is due' ); $this->assertNotEmpty($response); $this->assertArrayHasKey('id', $response); } /** @test */ public function it_can_reauthorize_an_authorized_payment() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockReAuthorizeAuthorizedPaymentResponse() ) ); $response = $this->client->reAuthorizeAuthorizedPayment('0VF52814937998046', 10.99); $this->assertNotEmpty($response); $this->assertArrayHasKey('id', $response); } /** @test */ public function it_can_void_an_authorized_payment() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client(false) ); $response = $this->client->voidAuthorizedPayment('0VF52814937998046'); $this->assertEmpty($response); } /** @test */ public function it_can_show_details_for_a_captured_payment() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockGetCapturedPaymentDetailsResponse() ) ); $response = $this->client->showCapturedPaymentDetails('2GG279541U471931P'); $this->assertNotEmpty($response); $this->assertArrayHasKey('id', $response); } /** @test */ public function it_can_refund_a_captured_payment() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockRefundCapturedPaymentResponse() ) ); $response = $this->client->refundCapturedPayment( '2GG279541U471931P', 'INVOICE-123', 10.99, 'Defective product' ); $this->assertNotEmpty($response); $this->assertArrayHasKey('id', $response); } /** @test */ public function it_can_show_details_for_a_refund() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockGetRefundDetailsResponse() ) ); $response = $this->client->showRefundDetails('1JU08902781691411'); $this->assertNotEmpty($response); $this->assertArrayHasKey('id', $response); } /** @test */ public function it_can_create_batch_payout() { $expectedResponse = $this->mockCreateBatchPayoutResponse(); $expectedParams = $this->mockCreateBatchPayoutParams(); $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client($expectedResponse) ); $response = $this->client->createBatchPayout($expectedParams); $this->assertNotEmpty($response); $this->assertArrayHasKey('batch_header', $response); } /** @test */ public function it_can_show_batch_payout_details() { $expectedResponse = $this->showBatchPayoutResponse(); $expectedParams = 'FYXMPQTX4JC9N'; $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client($expectedResponse) ); $response = $this->client->showBatchPayoutDetails($expectedParams); $this->assertNotEmpty($response); $this->assertArrayHasKey('batch_header', $response); $this->assertArrayHasKey('items', $response); } /** @test */ public function it_can_show_batch_payout_item_details() { $expectedResponse = $this->showBatchPayoutItemResponse(); $expectedParams = '8AELMXH8UB2P8'; $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client($expectedResponse) ); $response = $this->client->showPayoutItemDetails($expectedParams); $this->assertNotEmpty($response); $this->assertArrayHasKey('payout_item_id', $response); $this->assertArrayHasKey('payout_batch_id', $response); $this->assertArrayHasKey('payout_item', $response); } /** @test */ public function it_can_cancel_unclaimed_batch_payout_item() { $expectedResponse = $this->mockCancelUnclaimedBatchItemResponse(); $expectedParams = '8AELMXH8UB2P8'; $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client($expectedResponse) ); $response = $this->client->cancelUnclaimedPayoutItem($expectedParams); $this->assertNotEmpty($response); $this->assertArrayHasKey('payout_item_id', $response); $this->assertArrayHasKey('payout_batch_id', $response); $this->assertArrayHasKey('payout_item', $response); } /** @test */ public function it_can_create_referenced_batch_payout() { $expectedResponse = $this->mockCreateReferencedBatchPayoutResponse(); $expectedParams = $this->mockCreateReferencedBatchPayoutParams(); $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client($expectedResponse) ); $response = $this->client->setRequestHeaders([ 'PayPal-Request-Id' => 'some-request-id', 'PayPal-Partner-Attribution-Id' => 'some-attribution-id', ])->createReferencedBatchPayout($expectedParams); $this->assertNotEmpty($response); $this->assertArrayHasKey('links', $response); } /** @test */ public function it_can_list_items_referenced_in_batch_payout() { $expectedResponse = $this->mockShowReferencedBatchPayoutResponse(); $expectedParams = 'KHbwO28lWlXwi2IlToJ2IYNG4juFv6kpbFx4J9oQ5Hb24RSp96Dk5FudVHd6v4E='; $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client($expectedResponse) ); $response = $this->client->listItemsReferencedInBatchPayout($expectedParams); $this->assertNotEmpty($response); $this->assertArrayHasKey('links', $response); } /** @test */ public function it_can_create_referenced_batch_payout_item() { $expectedResponse = $this->mockCreateReferencedBatchPayoutItemResponse(); $expectedParams = $this->mockCreateReferencedBatchPayoutItemParams(); $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client($expectedResponse) ); $response = $this->client->setRequestHeaders([ 'PayPal-Request-Id' => 'some-request-id', 'PayPal-Partner-Attribution-Id' => 'some-attribution-id', ])->createReferencedBatchPayoutItem($expectedParams); $this->assertNotEmpty($response); $this->assertArrayHasKey('links', $response); } /** @test */ public function it_can_show_referenced_payout_item_details() { $expectedResponse = $this->mockShowReferencedBatchPayoutItemResponse(); $expectedParams = 'CDZEC5MJ8R5HY'; $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client($expectedResponse) ); $response = $this->client->setRequestHeader('PayPal-Partner-Attribution-Id', 'some-attribution-id') ->showReferencedPayoutItemDetails($expectedParams); $this->assertNotEmpty($response); $this->assertArrayHasKey('item_id', $response); $this->assertArrayHasKey('reference_id', $response); } /** @test */ public function it_can_list_transactions() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockListTransactionsResponse() ) ); $filters = [ 'start_date' => Carbon::now()->toIso8601String(), 'end_date' => Carbon::now()->subDays(30)->toIso8601String(), ]; $response = $this->client->listTransactions($filters); $this->assertArrayHasKey('transaction_details', $response); $this->assertGreaterThan(0, sizeof($response['transaction_details'])); } /** @test */ public function it_can_list_account_balances() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockListBalancesResponse() ) ); $date = Carbon::now()->subDays(30)->toIso8601String(); $response = $this->client->listBalances($date); $this->assertNotEmpty($response); } /** @test */ public function it_can_list_account_balances_for_a_different_currency() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockListBalancesResponse() ) ); $date = Carbon::now()->subDays(30)->toIso8601String(); $response = $this->client->listBalances($date, 'EUR'); $this->assertNotEmpty($response); } /** @test */ public function it_can_create_a_subscription() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockCreateSubscriptionResponse() ) ); $expectedParams = $this->mockCreateSubscriptionParams(); $response = $this->client->createSubscription($expectedParams); $this->assertNotEmpty($response); $this->assertArrayHasKey('id', $response); } /** @test */ public function it_can_update_a_subscription() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client(false) ); $expectedParams = $this->mockUpdateSubscriptionParams(); $response = $this->client->updateSubscription('I-BW452GLLEP1G', $expectedParams); $this->assertEmpty($response); } /** @test */ public function it_can_show_details_for_a_subscription() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockGetSubscriptionDetailsResponse() ) ); $response = $this->client->showSubscriptionDetails('I-BW452GLLEP1G'); $this->assertNotEmpty($response); $this->assertArrayHasKey('id', $response); } /** @test */ public function it_can_activate_a_subscription() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client(false) ); $response = $this->client->activateSubscription('I-BW452GLLEP1G', 'Reactivating the subscription'); $this->assertEmpty($response); } /** @test */ public function it_can_cancel_a_subscription() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client(false) ); $response = $this->client->cancelSubscription('I-BW452GLLEP1G', 'Not satisfied with the service'); $this->assertEmpty($response); } /** @test */ public function it_can_suspend_a_subscription() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client(false) ); $response = $this->client->suspendSubscription('I-BW452GLLEP1G', 'Item out of stock'); $this->assertEmpty($response); } /** @test */ public function it_can_capture_payment_for_a_subscription() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client(false) ); $response = $this->client->captureSubscriptionPayment('I-BW452GLLEP1G', 'Charging as the balance reached the limit', 100); $this->assertEmpty($response); } /** @test */ public function it_can_update_quantity_or_product_for_a_subscription() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockUpdateSubscriptionItemsResponse() ) ); $expectedParams = $this->mockUpdateSubscriptionItemsParams(); $response = $this->client->reviseSubscription('I-BW452GLLEP1G', $expectedParams); $this->assertNotEmpty($response); $this->assertArrayHasKey('plan_id', $response); } /** @test */ public function it_can_list_transactions_for_a_subscription() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockListSubscriptionTransactionsResponse() ) ); $response = $this->client->listSubscriptionTransactions('I-BW452GLLEP1G', '2018-01-21T07:50:20.940Z', '2018-08-22T07:50:20.940Z'); $this->assertNotEmpty($response); $this->assertEquals($response, $this->mockListSubscriptionTransactionsResponse()); } /** @test */ public function it_can_list_tracking_details() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockGetTrackingDetailsResponse() ) ); $response = $this->client->listTrackingDetails('8MC585209K746392H-443844607820'); $this->assertNotEmpty($response); $this->assertEquals($response, $this->mockGetTrackingDetailsResponse()); $this->assertArrayHasKey('transaction_id', $response); $this->assertArrayHasKey('tracking_number', $response); } /** @test */ public function it_can_get_tracking_details_for_tracking_id() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockGetTrackingDetailsResponse() ) ); $response = $this->client->showTrackingDetails('8MC585209K746392H-443844607820'); $this->assertNotEmpty($response); $this->assertEquals($response, $this->mockGetTrackingDetailsResponse()); $this->assertArrayHasKey('tracking_number', $response); } /** @test */ public function it_can_update_tracking_details_for_tracking_id() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client(false) ); $response = $this->client->updateTrackingDetails( '8MC585209K746392H-443844607820', $this->mockUpdateTrackingDetailsParams() ); $this->assertEmpty($response); } /** @test */ public function it_can_create_tracking_in_batches() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockCreateTrackinginBatchesResponse() ) ); $expectedParams = $this->mockCreateTrackinginBatchesParams(); $response = $this->client->addBatchTracking($expectedParams); $this->assertNotEmpty($response); $this->assertArrayHasKey('tracker_identifiers', $response); } /** @test */ public function it_can_create_single_tracking_for_single_transaction() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockCreateTrackinginBatchesResponse() ) ); $expectedParams = $this->mockCreateTrackinginBatchesParams(); $response = $this->client->addTracking($expectedParams); $this->assertNotEmpty($response); $this->assertArrayHasKey('tracker_identifiers', $response); } /** @test */ public function it_can_list_web_hooks_event_types() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockListWebHookEventsTypesResponse() ) ); $response = $this->client->listEventTypes(); $this->assertNotEmpty($response); $this->assertArrayHasKey('event_types', $response); } /** @test */ public function it_can_list_web_hooks_events() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockWebHookEventsListResponse() ) ); $response = $this->client->listEvents(); $this->assertNotEmpty($response); $this->assertArrayHasKey('events', $response); } /** @test */ public function it_can_show_details_for_a_web_hooks_event() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockGetWebHookEventResponse() ) ); $response = $this->client->showEventDetails('8PT597110X687430LKGECATA'); $this->assertNotEmpty($response); $this->assertArrayHasKey('id', $response); } /** @test */ public function it_can_resend_notification_for_a_web_hooks_event() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockResendWebHookEventNotificationResponse() ) ); $expectedParams = ['12334456']; $response = $this->client->resendEventNotification('8PT597110X687430LKGECATA', $expectedParams); $this->assertNotEmpty($response); $this->assertArrayHasKey('id', $response); } /** @test */ public function it_can_create_a_web_hook() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockCreateWebHookResponse() ) ); $response = $this->client->createWebHook( 'https://example.com/example_webhook', ['PAYMENT.AUTHORIZATION.CREATED', 'PAYMENT.AUTHORIZATION.VOIDED'] ); $this->assertNotEmpty($response); $this->assertArrayHasKey('event_types', $response); } /** @test */ public function it_can_list_web_hooks() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockListWebHookResponse() ) ); $response = $this->client->listWebHooks(); $this->assertNotEmpty($response); $this->assertArrayHasKey('webhooks', $response); } /** @test */ public function it_can_delete_a_web_hook() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client(false) ); $response = $this->client->deleteWebHook('5GP028458E2496506'); $this->assertEmpty($response); } /** @test */ public function it_can_update_a_web_hook() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockUpdateWebHookResponse() ) ); $expectedParams = $this->mockUpdateWebHookParams(); $response = $this->client->updateWebHook('0EH40505U7160970P', $expectedParams); $this->assertNotEmpty($response); $this->assertArrayHasKey('event_types', $response); } /** @test */ public function it_can_show_details_for_a_web_hook() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockGetWebHookResponse() ) ); $response = $this->client->showWebHookDetails('0EH40505U7160970P'); $this->assertNotEmpty($response); $this->assertArrayHasKey('event_types', $response); } /** @test */ public function it_can_list_events_for_web_hooks() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockListWebHookEventsResponse() ) ); $response = $this->client->listWebHookEvents('0EH40505U7160970P'); $this->assertNotEmpty($response); $this->assertArrayHasKey('event_types', $response); } /** @test */ public function it_can_verify_web_hook_signature() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockVerifyWebHookSignatureResponse() ) ); $expectedParams = $this->mockVerifyWebHookSignatureParams(); $response = $this->client->verifyWebHook($expectedParams); $this->assertNotEmpty($response); $this->assertArrayHasKey('verification_status', $response); } /** @test */ public function it_can_list_payment_methods_source_tokens() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockListPaymentMethodsTokensResponse() ) ); $response = $this->client->setCustomerSource('customer_4029352050') ->listPaymentSourceTokens(); $this->assertNotEmpty($response); $this->assertArrayHasKey('payment_tokens', $response); } /** @test */ public function it_can_show_details_for_payment_method_source_token() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockCreatePaymentMethodsTokenResponse() ) ); $response = $this->client->showPaymentSourceTokenDetails('8kk8451t'); $this->assertNotEmpty($response); $this->assertArrayHasKey('id', $response); $this->assertArrayHasKey('customer', $response); $this->assertArrayHasKey('payment_source', $response); } /** @test */ public function it_can_delete_a_payment_method_source_token() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client(false) ); $response = $this->client->deletePaymentSourceToken('8kk8451t'); $this->assertEmpty($response); } /** @test */ public function it_can_show_details_for_payment_setup_token() { $this->client->setAccessToken([ 'access_token' => self::$access_token, 'token_type' => 'Bearer', ]); $this->client->setClient( $this->mock_http_client( $this->mockListPaymentSetupTokenResponse() ) ); $response = $this->client->showPaymentSetupTokenDetails('5C991763VB2781612'); $this->assertNotEmpty($response); $this->assertArrayHasKey('id', $response); $this->assertArrayHasKey('customer', $response); $this->assertArrayHasKey('payment_source', $response); } } paypal/src/Traits/PayPalHttpClient.php000064400000011450150364341100013763 0ustar00 32, 'CURL_SSLVERSION_TLSv1_2' => 6, 'CURLOPT_SSL_VERIFYPEER' => 64, 'CURLOPT_SSLCERT' => 10025, ]; foreach ($constants as $key => $item) { $this->defineCurlConstant($key, $item); } } /** * Declare a curl constant. * * @param string $key * @param string $value * * @return bool */ protected function defineCurlConstant(string $key, string $value) { return defined($key) ? true : define($key, $value); } /** * Function to initialize/override Http Client. * * @param \GuzzleHttp\Client|null $client * * @return void */ public function setClient(HttpClient $client = null) { if ($client instanceof HttpClient) { $this->client = $client; return; } $this->client = new HttpClient([ 'curl' => $this->httpClientConfig, ]); } /** * Function to set Http Client configuration. * * @return void */ protected function setHttpClientConfiguration() { $this->setCurlConstants(); $this->httpClientConfig = [ CURLOPT_SSLVERSION => CURL_SSLVERSION_TLSv1_2, CURLOPT_SSL_VERIFYPEER => $this->validateSSL, ]; // Initialize Http Client $this->setClient(); // Set default values. $this->setDefaultValues(); // Set PayPal IPN Notification URL $this->notifyUrl = $this->config['notify_url']; } /** * Set default values for configuration. * * @return void */ private function setDefaultValues() { $paymentAction = empty($this->paymentAction) ? 'Sale' : $this->paymentAction; $this->paymentAction = $paymentAction; $locale = empty($this->locale) ? 'en_US' : $this->locale; $this->locale = $locale; $validateSSL = empty($this->validateSSL) ? true : $this->validateSSL; $this->validateSSL = $validateSSL; } /** * Perform PayPal API request & return response. * * @throws \Throwable * * @return StreamInterface */ private function makeHttpRequest(): StreamInterface { try { return $this->client->{$this->verb}( $this->apiUrl, $this->options )->getBody(); } catch (HttpClientException $e) { throw new RuntimeException($e->getResponse()->getBody()); } } /** * Function To Perform PayPal API Request. * * @param bool $decode * * @throws \Throwable * * @return array|StreamInterface|string */ private function doPayPalRequest(bool $decode = true) { try { $this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/'); // Perform PayPal HTTP API request. $response = $this->makeHttpRequest(); return ($decode === false) ? $response->getContents() : Utils::jsonDecode($response, true); } catch (RuntimeException $t) { $error = ($decode === false) || (Str::isJson($t->getMessage()) === false) ? $t->getMessage() : Utils::jsonDecode($t->getMessage(), true); return ['error' => $error]; } } } paypal/src/Traits/PayPalVerifyIPN.php000064400000003215150364341100013520 0ustar00webhook_id = $webhook_id; return $this; } /** * Verify incoming IPN through a web hook id. * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string */ public function verifyIPN(\Illuminate\Http\Request $request) { $headers = array_change_key_case($request->headers->all(), CASE_UPPER); if (!isset($headers['PAYPAL-AUTH-ALGO'][0]) || !isset($headers['PAYPAL-TRANSMISSION-ID'][0]) || !isset($headers['PAYPAL-CERT-URL'][0]) || !isset($headers['PAYPAL-TRANSMISSION-SIG'][0]) || !isset($headers['PAYPAL-TRANSMISSION-TIME'][0]) || !isset($this->webhook_id) ) { \Log::error('Invalid headers or webhook id supplied for paypal webhook'); return ['error' => 'Invalid headers or webhook id provided']; } $params = $request->all(); $payload = [ 'auth_algo' => $headers['PAYPAL-AUTH-ALGO'][0], 'cert_url' => $headers['PAYPAL-CERT-URL'][0], 'transmission_id' => $headers['PAYPAL-TRANSMISSION-ID'][0], 'transmission_sig' => $headers['PAYPAL-TRANSMISSION-SIG'][0], 'transmission_time' => $headers['PAYPAL-TRANSMISSION-TIME'][0], 'webhook_id' => $this->webhook_id, 'webhook_event' => $params, ]; return $this->verifyWebHook($payload); } } paypal/src/Traits/PayPalRequest.php000064400000015203150364341100013335 0ustar00throwConfigurationException(); } // Setting Default PayPal Mode If not set $this->setApiEnvironment($credentials); // Set API configuration for the PayPal provider $this->setApiProviderConfiguration($credentials); // Set default currency. $this->setCurrency($credentials['currency']); // Set Http Client configuration. $this->setHttpClientConfiguration(); } /** * Function to set currency. * * @param string $currency * * @throws \RuntimeException * * @return \Srmklive\PayPal\Services\PayPal */ public function setCurrency(string $currency = 'USD'): \Srmklive\PayPal\Services\PayPal { $allowedCurrencies = ['AUD', 'BRL', 'CAD', 'CZK', 'DKK', 'EUR', 'HKD', 'HUF', 'ILS', 'INR', 'JPY', 'MYR', 'MXN', 'NOK', 'NZD', 'PHP', 'PLN', 'GBP', 'SGD', 'SEK', 'CHF', 'TWD', 'THB', 'USD', 'RUB', 'CNY']; // Check if provided currency is valid. if (!in_array($currency, $allowedCurrencies, true)) { throw new RuntimeException('Currency is not supported by PayPal.'); } $this->currency = $currency; return $this; } /** * Return the set currency. */ public function getCurrency(): string { return $this->currency; } /** * Function to add request header. * * @param string $key * @param string $value * * @return \Srmklive\PayPal\Services\PayPal */ public function setRequestHeader(string $key, string $value): \Srmklive\PayPal\Services\PayPal { $this->options['headers'][$key] = $value; return $this; } /** * Function to add multiple request headers. * * @param array $headers * * @return \Srmklive\PayPal\Services\PayPal */ public function setRequestHeaders(array $headers): \Srmklive\PayPal\Services\PayPal { foreach ($headers as $key=>$value) { $this->setRequestHeader($key, $value); } return $this; } /** * Return request options header. * * @param string $key * * @throws \RuntimeException * * @return string */ public function getRequestHeader(string $key): string { if (isset($this->options['headers'][$key])) { return $this->options['headers'][$key]; } throw new RuntimeException('Options header is not set.'); } /** * Function To Set PayPal API Configuration. * * @param array $config * * @throws \Exception */ private function setConfig(array $config): void { $api_config = empty($config) && function_exists('config') && !empty(config('paypal')) ? config('paypal') : $config; // Set Api Credentials $this->setApiCredentials($api_config); } /** * Set API environment to be used by PayPal. * * @param array $credentials */ private function setApiEnvironment(array $credentials): void { $this->mode = 'live'; if (!empty($credentials['mode'])) { $this->setValidApiEnvironment($credentials['mode']); } else { $this->throwConfigurationException(); } } /** * Validate & set the environment to be used by PayPal. * * @param string $mode */ private function setValidApiEnvironment(string $mode): void { $this->mode = !in_array($mode, ['sandbox', 'live']) ? 'live' : $mode; } /** * Set configuration details for the provider. * * @param array $credentials * * @throws \Exception */ private function setApiProviderConfiguration(array $credentials): void { // Setting PayPal API Credentials if (empty($credentials[$this->mode])) { $this->throwConfigurationException(); } $config_params = ['client_id', 'client_secret']; foreach ($config_params as $item) { if (empty($credentials[$this->mode][$item])) { throw new RuntimeException("{$item} missing from the provided configuration. Please add your application {$item}."); } } collect($credentials[$this->mode])->map(function ($value, $key) { $this->config[$key] = $value; }); $this->paymentAction = $credentials['payment_action']; $this->locale = $credentials['locale']; $this->setRequestHeader('Accept-Language', $this->locale); $this->validateSSL = $credentials['validate_ssl']; $this->setOptions($credentials); } /** * @throws RuntimeException */ private function throwConfigurationException() { throw new RuntimeException('Invalid configuration provided. Please provide valid configuration for PayPal API. You can also refer to the documentation at https://srmklive.github.io/laravel-paypal/docs.html to setup correct configuration.'); } /** * @throws RuntimeException */ private function throwInvalidEvidenceFileException() { throw new RuntimeException('Invalid evidence file type provided. 1. The party can upload up to 50 MB of files per request. 2. Individual files must be smaller than 10 MB. 3. The supported file formats are JPG, JPEG, GIF, PNG, and PDF. '); } } paypal/src/Traits/PayPalAPI/WebHooks.php000064400000006305150364341100014042 0ustar00apiEndPoint = 'v1/notifications/webhooks'; $data = ['url' => $url]; $data['event_types'] = collect($events)->map(function ($item) { return ['name' => $item]; })->toArray(); $this->options['json'] = $data; $this->verb = 'post'; return $this->doPayPalRequest(); } /** * List all web hooks. * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/webhooks/v1/#webhooks_list */ public function listWebHooks() { $this->apiEndPoint = 'v1/notifications/webhooks'; $this->verb = 'get'; return $this->doPayPalRequest(); } /** * Delete a web hook. * * @param string $web_hook_id * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/webhooks/v1/#webhooks_delete */ public function deleteWebHook(string $web_hook_id) { $this->apiEndPoint = "v1/notifications/webhooks/{$web_hook_id}"; $this->verb = 'delete'; return $this->doPayPalRequest(false); } /** * Update an existing web hook. * * @param string $web_hook_id * @param array $data * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/webhooks/v1/#webhooks_update */ public function updateWebHook(string $web_hook_id, array $data) { $this->apiEndPoint = "v1/notifications/webhooks/{$web_hook_id}"; $this->options['json'] = $data; $this->verb = 'patch'; return $this->doPayPalRequest(); } /** * Show details for an existing web hook. * * @param string $web_hook_id * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/webhooks/v1/#webhooks_get */ public function showWebHookDetails(string $web_hook_id) { $this->apiEndPoint = "v1/notifications/webhooks/{$web_hook_id}"; $this->verb = 'get'; return $this->doPayPalRequest(); } /** * List events for an existing web hook. * * @param string $web_hook_id * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/webhooks/v1/#webhooks_get */ public function listWebHookEvents($web_hook_id) { $this->apiEndPoint = "v1/notifications/webhooks/{$web_hook_id}/event-types"; $this->verb = 'get'; return $this->doPayPalRequest(); } } paypal/src/Traits/PayPalAPI/InvoicesTemplates.php000064400000005307150364341100015760 0ustar00apiEndPoint = "v2/invoicing/templates?page={$this->current_page}&page_size={$this->page_size}&fields={$fields}"; $this->verb = 'get'; return $this->doPayPalRequest(); } /** * Create a new invoice template. * * @param array $data * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/invoicing/v2/#templates_create */ public function createInvoiceTemplate(array $data) { $this->apiEndPoint = 'v2/invoicing/templates'; $this->options['json'] = $data; $this->verb = 'post'; return $this->doPayPalRequest(); } /** * Show details for an existing invoice. * * @param string $template_id * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/invoicing/v2/#templates_get */ public function showInvoiceTemplateDetails(string $template_id) { $this->apiEndPoint = "v2/invoicing/templates/{$template_id}"; $this->verb = 'get'; return $this->doPayPalRequest(); } /** * Update an existing invoice template. * * @param string $template_id * @param array $data * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/invoicing/v2/#templates_update */ public function updateInvoiceTemplate(string $template_id, array $data) { $this->apiEndPoint = "v2/invoicing/templates/{$template_id}"; $this->options['json'] = $data; $this->verb = 'put'; return $this->doPayPalRequest(); } /** * Delete an invoice template. * * @param string $template_id * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/invoicing/v2/#templates_delete */ public function deleteInvoiceTemplate(string $template_id) { $this->apiEndPoint = "v2/invoicing/templates/{$template_id}"; $this->verb = 'delete'; return $this->doPayPalRequest(false); } } paypal/src/Traits/PayPalAPI/BillingPlans/PricingSchemes.php000064400000002053150364341100017576 0ustar00pricing_schemes[] = $this->addPlanBillingCycle($interval_unit, $interval_count, $price, $trial); return $this; } /** * Process pricing updates for an existing billing plan. * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string */ public function processBillingPlanPricingUpdates() { return $this->updatePlanPricing($this->billing_plan['id'], $this->pricing_schemes); } } paypal/src/Traits/PayPalAPI/PartnerReferrals.php000064400000002231150364341100015574 0ustar00apiEndPoint = 'v2/customer/partner-referrals'; $this->options['json'] = $partner_data; $this->verb = 'post'; return $this->doPayPalRequest(); } /** * Get Partner Referral Details. * * @param string $partner_referral_id * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/partner-referrals/v2/#partner-referrals_read */ public function showReferralData(string $partner_referral_id) { $this->apiEndPoint = "v2/customer/partner-referrals/{$partner_referral_id}"; $this->verb = 'get'; return $this->doPayPalRequest(); } } paypal/src/Traits/PayPalAPI/PaymentRefunds.php000064400000001075150364341100015264 0ustar00apiEndPoint = "v2/payments/refunds/{$refund_id}"; $this->verb = 'get'; return $this->doPayPalRequest(); } } paypal/src/Traits/PayPalAPI/InvoicesSearch.php000064400000001653150364341100015227 0ustar00invoice_search_filters)->count() < 1) { $this->invoice_search_filters = [ 'currency_code' => $this->getCurrency(), ]; } $this->apiEndPoint = "v2/invoicing/search-invoices?page={$this->current_page}&page_size={$this->page_size}&total_required={$this->show_totals}"; $this->options['json'] = $this->invoice_search_filters; $this->verb = 'post'; return $this->doPayPalRequest(); } } paypal/src/Traits/PayPalAPI/BillingPlans.php000064400000007363150364341100014704 0ustar00apiEndPoint = 'v1/billing/plans'; $this->options['json'] = $data; $this->verb = 'post'; return $this->doPayPalRequest(); } /** * List all billing plans. * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_list */ public function listPlans() { $this->apiEndPoint = "v1/billing/plans?page={$this->current_page}&page_size={$this->page_size}&total_required={$this->show_totals}"; $this->verb = 'get'; return $this->doPayPalRequest(); } /** * Update an existing billing plan. * * @param string $plan_id * @param array $data * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_update */ public function updatePlan(string $plan_id, array $data) { $this->apiEndPoint = "v1/billing/plans/{$plan_id}"; $this->options['json'] = $data; $this->verb = 'patch'; return $this->doPayPalRequest(false); } /** * Show details for an existing billing plan. * * @param string $plan_id * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_get */ public function showPlanDetails(string $plan_id) { $this->apiEndPoint = "v1/billing/plans/{$plan_id}"; $this->verb = 'get'; return $this->doPayPalRequest(); } /** * Activate an existing billing plan. * * @param string $plan_id * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_activate */ public function activatePlan(string $plan_id) { $this->apiEndPoint = "v1/billing/plans/{$plan_id}/activate"; $this->verb = 'post'; return $this->doPayPalRequest(false); } /** * Deactivate an existing billing plan. * * @param string $plan_id * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_deactivate */ public function deactivatePlan(string $plan_id) { $this->apiEndPoint = "v1/billing/plans/{$plan_id}/deactivate"; $this->verb = 'post'; return $this->doPayPalRequest(false); } /** * Update pricing for an existing billing plan. * * @param string $plan_id * @param array $pricing * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_update-pricing-schemes */ public function updatePlanPricing(string $plan_id, array $pricing) { $this->apiEndPoint = "v1/billing/plans/{$plan_id}/update-pricing-schemes"; $this->options['json'] = [ 'pricing_schemes' => $pricing, ]; $this->verb = 'post'; return $this->doPayPalRequest(false); } } paypal/src/Traits/PayPalAPI/PaymentCaptures.php000064400000002715150364341100015446 0ustar00apiEndPoint = "v2/payments/captures/{$capture_id}"; $this->verb = 'get'; return $this->doPayPalRequest(); } /** * Refund a captured payment. * * @param string $capture_id * @param string $invoice_id * @param float $amount * @param string $note * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/payments/v2/#captures_refund */ public function refundCapturedPayment(string $capture_id, string $invoice_id, float $amount, string $note) { $this->apiEndPoint = "v2/payments/captures/{$capture_id}/refund"; $this->options['json'] = [ 'amount' => [ 'value' => $amount, 'currency_code' => $this->currency, ], 'invoice_id' => $invoice_id, 'note_to_payer' => $note, ]; $this->verb = 'post'; return $this->doPayPalRequest(); } } paypal/src/Traits/PayPalAPI/PaymentExperienceWebProfiles.php000064400000006517150364341100020115 0ustar00apiEndPoint = 'v1/payment-experience/web-profiles'; $this->verb = 'get'; return $this->doPayPalRequest(); } /** * Create a Web Experience Profile. * * @param array $data * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/payment-experience/v1/#web-profile_create */ public function createWebExperienceProfile(array $data) { $this->apiEndPoint = 'v1/payment-experience/web-profiles'; $this->options['json'] = $data; $this->verb = 'post'; return $this->doPayPalRequest(); } /** * Delete a Web Experience Profile. * * @param string $profile_id * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/payment-experience/v1/#web-profile_delete */ public function deleteWebExperienceProfile(string $profile_id) { $this->apiEndPoint = "v1/payment-experience/web-profiles/{$profile_id}"; $this->verb = 'delete'; return $this->doPayPalRequest(); } /** * Partially update a Web Experience Profile. * * @param string $profile_id * @param array $data * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/payment-experience/v1/#web-profile_partial-update */ public function patchWebExperienceProfile(string $profile_id, array $data) { $this->apiEndPoint = "v1/payment-experience/web-profiles/{$profile_id}"; $this->options['json'] = $data; $this->verb = 'patch'; return $this->doPayPalRequest(); } /** * Partially update a Web Experience Profile. * * @param string $profile_id * @param array $data * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/payment-experience/v1/#web-profile_update */ public function updateWebExperienceProfile(string $profile_id, array $data) { $this->apiEndPoint = "v1/payment-experience/web-profiles/{$profile_id}"; $this->options['json'] = $data; $this->verb = 'put'; return $this->doPayPalRequest(); } /** * Delete a Web Experience Profile. * * @param string $profile_id * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/payment-experience/v1/#web-profile_get */ public function showWebExperienceProfileDetails(string $profile_id) { $this->apiEndPoint = "v1/payment-experience/web-profiles/{$profile_id}"; $this->verb = 'get'; return $this->doPayPalRequest(); } } paypal/src/Traits/PayPalAPI/Identity.php000064400000012235150364341100014111 0ustar00apiEndPoint = 'v1/identity/openidconnect/userinfo?schema=openid'; $this->setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); $this->verb = 'get'; return $this->doPayPalRequest(); } /** * List Users. * * @param string $field * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/identity/v2/#users_list */ public function listUsers(string $field = 'userName') { $this->apiEndPoint = "v2/scim/Users?filter={$field}"; $this->setRequestHeader('Content-Type', 'application/scim+json'); $this->verb = 'get'; return $this->doPayPalRequest(); } /** * Show details for a user by ID. * * @param string $user_id * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/identity/v2/#users_get */ public function showUserDetails(string $user_id) { $this->apiEndPoint = "v2/scim/Users/{$user_id}"; $this->setRequestHeader('Content-Type', 'application/scim+json'); $this->verb = 'get'; return $this->doPayPalRequest(); } /** * Delete a user by ID. * * @param string $user_id * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/identity/v2/#users_get */ public function deleteUser(string $user_id) { $this->apiEndPoint = "v2/scim/Users/{$user_id}"; $this->setRequestHeader('Content-Type', 'application/scim+json'); $this->verb = 'delete'; return $this->doPayPalRequest(false); } /** * Create a merchant application. * * @param string $client_name * @param array $redirect_uris * @param array $contacts * @param string $payer_id * @param string $migrated_app * @param string $application_type * @param string $logo_url * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/identity/v1/#applications_post */ public function createMerchantApplication(string $client_name, array $redirect_uris, array $contacts, string $payer_id, string $migrated_app, string $application_type = 'web', string $logo_url = '') { $this->apiEndPoint = 'v1/identity/applications'; $this->options['json'] = array_filter([ 'application_type' => $application_type, 'redirect_uris' => $redirect_uris, 'client_name' => $client_name, 'contacts' => $contacts, 'payer_id' => $payer_id, 'migrated_app' => $migrated_app, 'logo_uri' => $logo_url, ]); $this->verb = 'post'; return $this->doPayPalRequest(); } /** * Create a merchant application. * * @param array $features * @param string $account_property * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/identity/v1/#account-settings_post */ public function setAccountProperties(array $features, string $account_property = 'BRAINTREE_MERCHANT') { $this->apiEndPoint = 'v1/identity/account-settings'; $this->options['json'] = [ 'account_property' => $account_property, 'features' => $features, ]; $this->verb = 'post'; return $this->doPayPalRequest(); } /** * Create a merchant application. * * @param string $account_property * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/identity/v1/#account-settings_deactivate */ public function disableAccountProperties(string $account_property = 'BRAINTREE_MERCHANT') { $this->apiEndPoint = 'v1/identity/account-settings/deactivate'; $this->options['json'] = [ 'account_property' => $account_property, ]; $this->verb = 'post'; return $this->doPayPalRequest(); } /** * Get a client token. * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/multiparty/checkout/advanced/integrate/#link-sampleclienttokenrequest */ public function getClientToken() { $this->apiEndPoint = 'v1/identity/generate-token'; $this->verb = 'post'; return $this->doPayPalRequest(); } } paypal/src/Traits/PayPalAPI/CatalogProducts.php000064400000004121150364341100015411 0ustar00apiEndPoint = 'v1/catalogs/products'; $this->options['json'] = $data; $this->verb = 'post'; return $this->doPayPalRequest(); } /** * List products. * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/catalog-products/v1/#products_list */ public function listProducts() { $this->apiEndPoint = "v1/catalogs/products?page={$this->current_page}&page_size={$this->page_size}&total_required={$this->show_totals}"; $this->verb = 'get'; return $this->doPayPalRequest(); } /** * Update a product. * * @param string $product_id * @param array $data * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/catalog-products/v1/#products_patch */ public function updateProduct(string $product_id, array $data) { $this->apiEndPoint = "v1/catalogs/products/{$product_id}"; $this->options['json'] = $data; $this->verb = 'patch'; return $this->doPayPalRequest(false); } /** * Get product details. * * @param string $product_id * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/catalog-products/v1/#products_get */ public function showProductDetails(string $product_id) { $this->apiEndPoint = "v1/catalogs/products/{$product_id}"; $this->verb = 'get'; return $this->doPayPalRequest(); } } paypal/src/Traits/PayPalAPI/Trackers.php000064400000005575150364341100014107 0ustar00apiEndPoint = 'v1/shipping/trackers-batch'; $this->options['json'] = $data; $this->verb = 'post'; return $this->doPayPalRequest(); } /** * Adds tracking information for a PayPal transaction. * * @param array $data * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/tracking/v1/#trackers_post */ public function addTracking(array $data) { $this->apiEndPoint = 'v1/shipping/trackers'; $this->options['json'] = $data; $this->verb = 'post'; return $this->doPayPalRequest(); } /** * List tracking information based on Transaction ID or tracking number. * * @param string $transaction_id * @param string $tracking_number * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/tracking/v1/#trackers-batch_get */ public function listTrackingDetails(string $transaction_id, string $tracking_number = null) { $this->apiEndPoint = "v1/shipping/trackers?transaction_id={$transaction_id}".!empty($tracking_number) ? "&tracking_number={$tracking_number}" : ''; $this->verb = 'get'; return $this->doPayPalRequest(); } /** * Update tracking information. * * @param string $tracking_id * @param array $data * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/tracking/v1/#trackers_put */ public function updateTrackingDetails(string $tracking_id, array $data) { $this->apiEndPoint = "v1/shipping/trackers/{$tracking_id}"; $this->options['json'] = $data; $this->verb = 'put'; return $this->doPayPalRequest(false); } /** * Show tracking information. * * @param string $tracking_id * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/tracking/v1/#trackers_get */ public function showTrackingDetails(string $tracking_id) { $this->apiEndPoint = "v1/shipping/trackers/{$tracking_id}"; $this->verb = 'get'; return $this->doPayPalRequest(); } } paypal/src/Traits/PayPalAPI/PaymentMethodsTokens.php000064400000006272150364341100016451 0ustar00apiEndPoint = 'v3/vault/payment-tokens'; $this->options['json'] = $data; $this->verb = 'post'; return $this->doPayPalRequest(); } /** * List all the payment tokens. * * @param int $page * @param int $page_size * @param bool $totals * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/payment-tokens/v3/#customer_payment-tokens_get */ public function listPaymentSourceTokens(int $page = 1, int $page_size = 10, bool $totals = true) { $this->apiEndPoint = "v3/vault/payment-tokens?customer_id={$this->customer_source['id']}&page={$page}&page_size={$page_size}&total_required={$totals}"; $this->verb = 'get'; return $this->doPayPalRequest(); } /** * Show details for a payment method token. * * @param string $token * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/payment-tokens/v3/#payment-tokens_get */ public function showPaymentSourceTokenDetails(string $token) { $this->apiEndPoint = "v3/vault/payment-tokens/{$token}"; $this->verb = 'get'; return $this->doPayPalRequest(); } /** * Show details for a payment token. * * @param string $token * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/payment-tokens/v3/#payment-tokens_delete */ public function deletePaymentSourceToken(string $token) { $this->apiEndPoint = "v3/vault/payment-tokens/{$token}"; $this->verb = 'delete'; return $this->doPayPalRequest(false); } /** * Create a payment setup token. * * @param array $data * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/payment-tokens/v3/#setup-tokens_create */ public function createPaymentSetupToken(array $data) { $this->apiEndPoint = 'v3/vault/setup-tokens'; $this->options['json'] = $data; $this->verb = 'post'; return $this->doPayPalRequest(); } /** * Show details for a payment setup token. * * @param string $token * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/payment-tokens/v3/#setup-tokens_get */ public function showPaymentSetupTokenDetails(string $token) { $this->apiEndPoint = "v3/vault/setup-tokens/{$token}"; $this->verb = 'get'; return $this->doPayPalRequest(); } } paypal/src/Traits/PayPalAPI/Subscriptions.php000064400000014465150364341100015176 0ustar00apiEndPoint = 'v1/billing/subscriptions'; $this->options['json'] = $data; $this->verb = 'post'; return $this->doPayPalRequest(); } /** * Update an existing billing plan. * * @param string $subscription_id * @param array $data * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_patch */ public function updateSubscription(string $subscription_id, array $data) { $this->apiEndPoint = "v1/billing/subscriptions/{$subscription_id}"; $this->options['json'] = $data; $this->verb = 'patch'; return $this->doPayPalRequest(false); } /** * Show details for an existing subscription. * * @param string $subscription_id * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_get */ public function showSubscriptionDetails(string $subscription_id) { $this->apiEndPoint = "v1/billing/subscriptions/{$subscription_id}"; $this->verb = 'get'; return $this->doPayPalRequest(); } /** * Activate an existing subscription. * * @param string $subscription_id * @param string $reason * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_activate */ public function activateSubscription(string $subscription_id, string $reason) { $this->apiEndPoint = "v1/billing/subscriptions/{$subscription_id}/activate"; $this->options['json'] = ['reason' => $reason]; $this->verb = 'post'; return $this->doPayPalRequest(false); } /** * Cancel an existing subscription. * * @param string $subscription_id * @param string $reason * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_cancel */ public function cancelSubscription(string $subscription_id, string $reason) { $this->apiEndPoint = "v1/billing/subscriptions/{$subscription_id}/cancel"; $this->options['json'] = ['reason' => $reason]; $this->verb = 'post'; return $this->doPayPalRequest(false); } /** * Suspend an existing subscription. * * @param string $subscription_id * @param string $reason * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_suspend */ public function suspendSubscription(string $subscription_id, string $reason) { $this->apiEndPoint = "v1/billing/subscriptions/{$subscription_id}/suspend"; $this->options['json'] = ['reason' => $reason]; $this->verb = 'post'; return $this->doPayPalRequest(false); } /** * Capture payment for an existing subscription. * * @param string $subscription_id * @param string $note * @param float $amount * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_capture */ public function captureSubscriptionPayment(string $subscription_id, string $note, float $amount) { $this->apiEndPoint = "v1/billing/subscriptions/{$subscription_id}/capture"; $this->options['json'] = [ 'note' => $note, 'capture_type' => 'OUTSTANDING_BALANCE', 'amount' => [ 'currency_code' => $this->currency, 'value' => "{$amount}", ], ]; $this->verb = 'post'; return $this->doPayPalRequest(false); } /** * Revise quantity, product or service for an existing subscription. * * @param string $subscription_id * @param array $items * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_revise */ public function reviseSubscription(string $subscription_id, array $items) { $this->apiEndPoint = "v1/billing/subscriptions/{$subscription_id}/revise"; $this->options['json'] = $items; $this->verb = 'post'; return $this->doPayPalRequest(); } /** * List transactions for an existing subscription. * * @param string $subscription_id * @param \DateTimeInterface|string $start_date * @param \DateTimeInterface|string $end_date * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_transactions */ public function listSubscriptionTransactions(string $subscription_id, $start_date = '', $end_date = '') { if (($start_date instanceof \DateTimeInterface) === false) { $start_date = Carbon::parse($start_date); } if (($end_date instanceof \DateTimeInterface) === false) { $end_date = Carbon::parse($end_date); } $start_date = $start_date->toIso8601ZuluString(); $end_date = $end_date->toIso8601ZuluString(); $this->apiEndPoint = "v1/billing/subscriptions/{$subscription_id}/transactions?start_time={$start_date}&end_time={$end_date}"; $this->verb = 'get'; return $this->doPayPalRequest(); } } paypal/src/Traits/PayPalAPI/PaymentAuthorizations.php000064400000005542150364341100016704 0ustar00apiEndPoint = "v2/payments/authorizations/{$authorization_id}"; $this->verb = 'get'; return $this->doPayPalRequest(); } /** * Capture an authorized payment. * * @param string $authorization_id * @param string $invoice_id * @param float $amount * @param string $note * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/payments/v2/#authorizations_capture */ public function captureAuthorizedPayment(string $authorization_id, string $invoice_id, float $amount, string $note) { $this->apiEndPoint = "v2/payments/authorizations/{$authorization_id}/capture"; $this->options['json'] = [ 'amount' => [ 'value' => $amount, 'currency_code' => $this->currency, ], 'invoice_id' => $invoice_id, 'note_to_payer' => $note, 'final_capture' => true, ]; $this->verb = 'post'; return $this->doPayPalRequest(); } /** * Reauthorize an authorized payment. * * @param string $authorization_id * @param float $amount * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/payments/v2/#authorizations_reauthorize */ public function reAuthorizeAuthorizedPayment(string $authorization_id, float $amount) { $this->apiEndPoint = "v2/payments/authorizations/{$authorization_id}/reauthorize"; $this->options['json'] = [ 'amount' => [ 'value' => $amount, 'currency_code' => $this->currency, ], ]; $this->verb = 'post'; return $this->doPayPalRequest(); } /** * Void an authorized payment. * * @param string $authorization_id * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/payments/v2/#authorizations_void */ public function voidAuthorizedPayment(string $authorization_id) { $this->apiEndPoint = "v2/payments/authorizations/{$authorization_id}/void"; $this->verb = 'post'; return $this->doPayPalRequest(false); } } paypal/src/Traits/PayPalAPI/WebHooksEvents.php000064400000004125150364341100015225 0ustar00apiEndPoint = 'v1/notifications/webhooks-event-types'; $this->verb = 'get'; return $this->doPayPalRequest(); } /** * List all events notifications for web hooks. * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/webhooks/v1/#webhooks-events_list */ public function listEvents() { $this->apiEndPoint = 'v1/notifications/webhooks-events'; $this->verb = 'get'; return $this->doPayPalRequest(); } /** * List all events notifications for web hooks. * * @param string $event_id * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/webhooks/v1/#webhooks-events_get */ public function showEventDetails(string $event_id) { $this->apiEndPoint = "v1/notifications/webhooks-events/{$event_id}"; $this->verb = 'get'; return $this->doPayPalRequest(); } /** * Resend notification for the event. * * @param string $event_id * @param array $items * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/webhooks/v1/#webhooks-events_resend */ public function resendEventNotification(string $event_id, array $items) { $this->apiEndPoint = "v1/notifications/webhooks-events/{$event_id}/resend"; $this->options['json'] = [ 'webhook_ids' => $items, ]; $this->verb = 'post'; return $this->doPayPalRequest(); } } paypal/src/Traits/PayPalAPI/Reporting.php000064400000003223150364341100014266 0ustar00isEmpty() ? '' : collect($filters)->map(function ($value, $key) { return "{$key}={$value}&"; })->implode(''); $this->apiEndPoint = "v1/reporting/transactions?{$filters_list}fields={$fields}&page={$this->current_page}&page_size={$this->page_size}"; $this->verb = 'get'; return $this->doPayPalRequest(); } /** * List available balance. * * @param string $date * @param string $balance_currency * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/transaction-search/v1/#balances_get */ public function listBalances(string $date = '', string $balance_currency = '') { $date = empty($date) ? Carbon::now()->toIso8601String() : Carbon::parse($date)->toIso8601String(); $currency = empty($balance_currency) ? $this->getCurrency() : $balance_currency; $this->apiEndPoint = "v1/reporting/balances?currency_code={$currency}&as_of_time={$date}"; $this->verb = 'get'; return $this->doPayPalRequest(); } } paypal/src/Traits/PayPalAPI/Payouts.php000064400000004151150364341100013762 0ustar00apiEndPoint = 'v1/payments/payouts'; $this->options['json'] = $data; $this->verb = 'post'; return $this->doPayPalRequest(); } /** * Show Batch Payout details by ID. * * @param string $payout_id * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/payments.payouts-batch/v1/#payouts_get */ public function showBatchPayoutDetails(string $payout_id) { $this->apiEndPoint = "v1/payments/payouts/{$payout_id}"; $this->verb = 'get'; return $this->doPayPalRequest(); } /** * Show Payout Item details by ID. * * @param string $payout_item_id * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/payments.payouts-batch/v1/#payouts-item_get */ public function showPayoutItemDetails(string $payout_item_id) { $this->apiEndPoint = "v1/payments/payouts-item/{$payout_item_id}"; $this->verb = 'get'; return $this->doPayPalRequest(); } /** * Show Payout Item details by ID. * * @param string $payout_item_id * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/payments.payouts-batch/v1/#payouts-item_cancel */ public function cancelUnclaimedPayoutItem(string $payout_item_id) { $this->apiEndPoint = "v1/payments/payouts-item/{$payout_item_id}/cancel"; $this->verb = 'post'; return $this->doPayPalRequest(); } } paypal/src/Traits/PayPalAPI/PaymentMethodsTokens/Helpers.php000064400000005663150364341100020056 0ustar00 $id, 'type' => $type, ]; return $this->setPaymentSourceDetails('token', $token_source); } /** * Set payment method token customer id. * * @param string $id * * @return \Srmklive\PayPal\Services\PayPal */ public function setCustomerSource(string $id): \Srmklive\PayPal\Services\PayPal { $this->customer_source = [ 'id' => $id, ]; return $this; } /** * Set payment source data for credit card. * * @param array $data * * @return \Srmklive\PayPal\Services\PayPal */ public function setPaymentSourceCard(array $data): \Srmklive\PayPal\Services\PayPal { return $this->setPaymentSourceDetails('card', $data); } /** * Set payment source data for PayPal. * * @param array $data * * @return \Srmklive\PayPal\Services\PayPal */ public function setPaymentSourcePayPal(array $data): \Srmklive\PayPal\Services\PayPal { return $this->setPaymentSourceDetails('paypal', $data); } /** * Set payment source data for Venmo. * * @param array $data * * @return \Srmklive\PayPal\Services\PayPal */ public function setPaymentSourceVenmo(array $data): \Srmklive\PayPal\Services\PayPal { return $this->setPaymentSourceDetails('venmo', $data); } /** * Set payment source details. * * @param string $source * @param array $data * * @return \Srmklive\PayPal\Services\PayPal */ protected function setPaymentSourceDetails(string $source, array $data): \Srmklive\PayPal\Services\PayPal { $this->payment_source[$source] = $data; return $this; } /** * Send request for creating payment method token/source. * * @param bool $create_source * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string */ public function sendPaymentMethodRequest(bool $create_source = false) { $token_payload = ['payment_source' => $this->payment_source]; if (!empty($this->customer_source)) { $token_payload['customer'] = $this->customer_source; } return ($create_source === true) ? $this->createPaymentSetupToken(array_filter($token_payload)) : $this->createPaymentSourceToken(array_filter($token_payload)); } } paypal/src/Traits/PayPalAPI/Orders.php000064400000006325150364341100013561 0ustar00apiEndPoint = 'v2/checkout/orders'; $this->options['json'] = (object) $data; $this->verb = 'post'; return $this->doPayPalRequest(); } /** * Shows details for an order. * * @param string $order_id * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/orders/v2/#orders_get */ public function showOrderDetails(string $order_id) { $this->apiEndPoint = "v2/checkout/orders/{$order_id}"; $this->verb = 'get'; return $this->doPayPalRequest(); } /** * Update order details. * * @param string $order_id * @param array $data * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/orders/v2/#orders_patch */ public function updateOrder(string $order_id, array $data) { $this->apiEndPoint = "v2/checkout/orders/{$order_id}"; $this->options['json'] = $data; $this->verb = 'patch'; return $this->doPayPalRequest(false); } /** * Confirm the order. * * @param string $order_id * @param array $data * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string */ public function confirmOrder(string $order_id, array $data) { $this->apiEndPoint = "v2/checkout/orders/{$order_id}/confirm-payment-source"; $this->options['json'] = (object) $data; $this->verb = 'post'; return $this->doPayPalRequest(); } /** * Authorizes payment for an order. * * @param string $order_id * @param array $data * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/orders/v2/#orders_authorize */ public function authorizePaymentOrder(string $order_id, array $data = []) { $this->apiEndPoint = "v2/checkout/orders/{$order_id}/authorize"; $this->options['json'] = (object) $data; $this->verb = 'post'; return $this->doPayPalRequest(); } /** * Captures payment for an order. * * @param string $order_id * @param array $data * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/orders/v2/#orders_capture */ public function capturePaymentOrder(string $order_id, array $data = []) { $this->apiEndPoint = "v2/checkout/orders/{$order_id}/capture"; $this->options['json'] = (object) $data; $this->verb = 'post'; return $this->doPayPalRequest(); } } paypal/src/Traits/PayPalAPI/Orders/Helpers.php000064400000001317150364341100015157 0ustar00 $processing_instruction, 'application_context' => $this->experience_context, 'payment_source' => $this->payment_source, ]; return $this->confirmOrder($order_id, $body); } } paypal/src/Traits/PayPalAPI/WebHooksVerification.php000064400000001153150364341100016401 0ustar00apiEndPoint = 'v1/notifications/verify-webhook-signature'; $this->options['json'] = $data; $this->verb = 'post'; return $this->doPayPalRequest(); } } paypal/src/Traits/PayPalAPI/DisputesActions.php000064400000015771150364341100015451 0ustar00apiEndPoint = "v1/customer/disputes/{$dispute_id}/acknowledge-return-item"; $this->options['json'] = [ 'note' => $dispute_note, 'acknowledgement_type' => $acknowledgement_type, ]; $this->verb = 'post'; return $this->doPayPalRequest(); } /** * Providence evidence in support of a dispute. * * @param string $dispute_id * @param array $file_path * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_provide-evidence */ public function provideDisputeEvidence(string $dispute_id, array $files) { if (VerifyDocuments::isValidEvidenceFile($files) === false) { $this->throwInvalidEvidenceFileException(); } $this->apiEndPoint = "/v1/customer/disputes/{$dispute_id}/provide-evidence"; $this->setRequestHeader('Content-Type', 'multipart/form-data'); $this->options['multipart'] = []; foreach ($files as $file) { $this->options['multipart'][] = [ 'name' => basename($file), 'contents' => Psr7\Utils::tryFopen($file, 'r'), ]; } $this->verb = 'post'; return $this->doPayPalRequest(); } /** * Make offer to resolve dispute claim. * * @param string $dispute_id * @param string $dispute_note * @param float $amount * @param string $refund_type * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_make-offer */ public function makeOfferToResolveDispute(string $dispute_id, string $dispute_note, float $amount, string $refund_type) { $this->apiEndPoint = "v1/customer/disputes/{$dispute_id}/make-offer"; $data['note'] = $dispute_note; $data['offer_type'] = $refund_type; $data['offer_amount'] = [ 'currency_code' => $this->getCurrency(), 'value' => $amount, ]; $this->options['json'] = $data; $this->verb = 'post'; return $this->doPayPalRequest(); } /** * Escalate dispute to claim. * * @param string $dispute_id * @param string $dispute_note * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_escalate */ public function escalateDisputeToClaim(string $dispute_id, string $dispute_note) { $this->apiEndPoint = "v1/customer/disputes/{$dispute_id}/escalate"; $data['note'] = $dispute_note; $this->options['json'] = $data; $this->verb = 'post'; return $this->doPayPalRequest(); } /** * Accept offer to resolve dispute. * * @param string $dispute_id * @param string $dispute_note * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_accept-offer */ public function acceptDisputeOfferResolution(string $dispute_id, string $dispute_note) { $this->apiEndPoint = "v1/customer/disputes/{$dispute_id}/accept-offer"; $this->options['json'] = [ 'note' => $dispute_note, ]; $this->verb = 'post'; return $this->doPayPalRequest(); } /** * Accept customer dispute claim. * * @param string $dispute_id * @param string $dispute_note * @param array $data * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_accept-claim */ public function acceptDisputeClaim(string $dispute_id, string $dispute_note, array $data = []) { $this->apiEndPoint = "v1/customer/disputes/{$dispute_id}/accept-claim"; $data['note'] = $dispute_note; $data['accept_claim_type'] = 'REFUND'; $this->options['json'] = $data; $this->verb = 'post'; return $this->doPayPalRequest(); } /** * Update dispute status. * * @param string $dispute_id * @param bool $merchant * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_require-evidence */ public function updateDisputeStatus(string $dispute_id, bool $merchant = true) { $this->apiEndPoint = "v1/customer/disputes/{$dispute_id}/require-evidence"; $data['action'] = ($merchant === true) ? 'SELLER_EVIDENCE' : 'BUYER_EVIDENCE'; $this->options['json'] = $data; $this->verb = 'post'; return $this->doPayPalRequest(); } /** * Settle dispute. * * @param string $dispute_id * @param bool $merchant * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_adjudicate */ public function settleDispute(string $dispute_id, bool $merchant = true) { $this->apiEndPoint = "v1/customer/disputes/{$dispute_id}/adjudicate"; $data['adjudication_outcome'] = ($merchant === true) ? 'SELLER_FAVOR' : 'BUYER_FAVOR'; $this->options['json'] = $data; $this->verb = 'post'; return $this->doPayPalRequest(); } /** * Decline offer to resolve dispute. * * @param string $dispute_id * @param string $dispute_note * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_deny-offer */ public function declineDisputeOfferResolution(string $dispute_id, string $dispute_note) { $this->apiEndPoint = "v1/customer/disputes/{$dispute_id}/deny-offer"; $this->options['json'] = [ 'note' => $dispute_note, ]; $this->verb = 'post'; return $this->doPayPalRequest(); } } paypal/src/Traits/PayPalAPI/InvoiceSearch/Filters.php000064400000014620150364341100016452 0ustar00invoice_search_filters['recipient_email'] = $email; return $this; } /** * @param string $name * * @return \Srmklive\PayPal\Services\PayPal */ public function addInvoiceFilterByRecipientFirstName(string $name): \Srmklive\PayPal\Services\PayPal { $this->invoice_search_filters['recipient_first_name'] = $name; return $this; } /** * @param string $name * * @return \Srmklive\PayPal\Services\PayPal */ public function addInvoiceFilterByRecipientLastName(string $name): \Srmklive\PayPal\Services\PayPal { $this->invoice_search_filters['recipient_last_name'] = $name; return $this; } /** * @param string $name * * @return \Srmklive\PayPal\Services\PayPal */ public function addInvoiceFilterByRecipientBusinessName(string $name): \Srmklive\PayPal\Services\PayPal { $this->invoice_search_filters['recipient_business_name'] = $name; return $this; } /** * @param string $invoice_number * * @return \Srmklive\PayPal\Services\PayPal */ public function addInvoiceFilterByInvoiceNumber(string $invoice_number): \Srmklive\PayPal\Services\PayPal { $this->invoice_search_filters['invoice_number'] = $invoice_number; return $this; } /** * @param array $status * * @throws \Exception * * @return \Srmklive\PayPal\Services\PayPal * * @see https://developer.paypal.com/docs/api/invoicing/v2/#definition-invoice_status */ public function addInvoiceFilterByInvoiceStatus(array $status): \Srmklive\PayPal\Services\PayPal { $invalid_status = false; foreach ($status as $item) { if (!in_array($item, $this->invoices_status_types)) { $invalid_status = true; } } if ($invalid_status === true) { throw new \Exception('status should be always one of these: '.implode(',', $this->invoices_date_types)); } $this->invoice_search_filters['status'] = $status; return $this; } /** * @param string $reference * @param bool $memo * * @return \Srmklive\PayPal\Services\PayPal */ public function addInvoiceFilterByReferenceorMemo(string $reference, bool $memo = false): \Srmklive\PayPal\Services\PayPal { $field = ($memo === false) ? 'reference' : 'memo'; $this->invoice_search_filters[$field] = $reference; return $this; } /** * @param string $currency_code * * @return \Srmklive\PayPal\Services\PayPal */ public function addInvoiceFilterByCurrencyCode(string $currency_code = ''): \Srmklive\PayPal\Services\PayPal { $currency = !isset($currency_code) ? $this->getCurrency() : $currency_code; $this->invoice_search_filters['currency_code'] = $currency; return $this; } /** * @param float $start_amount * @param float $end_amount * @param string $amount_currency * * @throws \Exception * * @return \Srmklive\PayPal\Services\PayPal */ public function addInvoiceFilterByAmountRange(float $start_amount, float $end_amount, string $amount_currency = ''): \Srmklive\PayPal\Services\PayPal { if ($start_amount > $end_amount) { throw new \Exception('Starting amount should always be less than end amount!'); } $currency = !isset($amount_currency) ? $this->getCurrency() : $amount_currency; $this->invoice_search_filters['total_amount_range'] = [ 'lower_amount' => [ 'currency_code' => $currency, 'value' => $start_amount, ], 'upper_amount' => [ 'currency_code' => $currency, 'value' => $end_amount, ], ]; return $this; } /** * @param string $start_date * @param string $end_date * @param string $date_type * * @throws \Exception * * @return \Srmklive\PayPal\Services\PayPal */ public function addInvoiceFilterByDateRange(string $start_date, string $end_date, string $date_type): \Srmklive\PayPal\Services\PayPal { $start_date_obj = Carbon::parse($start_date); $end_date_obj = Carbon::parse($end_date); if ($start_date_obj->gt($end_date_obj)) { throw new \Exception('Starting date should always be less than the end date!'); } if (!in_array($date_type, $this->invoices_date_types)) { throw new \Exception('date type should be always one of these: '.implode(',', $this->invoices_date_types)); } $this->invoice_search_filters["{$date_type}_range"] = [ 'start' => $start_date, 'end' => $end_date, ]; return $this; } /** * @param bool $archived * * @return \Srmklive\PayPal\Services\PayPal */ public function addInvoiceFilterByArchivedStatus(bool $archived = null): \Srmklive\PayPal\Services\PayPal { $this->invoice_search_filters['archived'] = $archived; return $this; } /** * @param array $fields * * @return \Srmklive\PayPal\Services\PayPal * * @see https://developer.paypal.com/docs/api/invoicing/v2/#definition-field */ public function addInvoiceFilterByFields(array $fields): \Srmklive\PayPal\Services\PayPal { $this->invoice_search_filters['status'] = $fields; return $this; } } paypal/src/Traits/PayPalAPI/Invoices.php000064400000025523150364341100014103 0ustar00apiEndPoint = 'v2/invoicing/invoices'; $this->options['json'] = $data; $this->verb = 'post'; return $this->doPayPalRequest(); } /** * Get list of invoices. * * @param array $fields * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_list */ public function listInvoices(array $fields = []) { $fields_list = collect($fields); $fields = ($fields_list->count() > 0) ? "&fields={$fields_list->implode(',')}" : ''; $this->apiEndPoint = "v2/invoicing/invoices?page={$this->current_page}&page_size={$this->page_size}&total_required={$this->show_totals}{$fields}"; $this->verb = 'get'; return $this->doPayPalRequest(); } /** * Send an existing invoice. * * @param string $invoice_id * @param string $subject * @param string $note * @param bool $send_recipient * @param bool $send_merchant * @param array $recipients * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_send */ public function sendInvoice(string $invoice_id, string $subject = '', string $note = '', bool $send_recipient = true, bool $send_merchant = false, array $recipients = []) { $this->apiEndPoint = "v2/invoicing/invoices/{$invoice_id}/send"; $this->options['json'] = $this->getInvoiceMessagePayload($subject, $note, $recipients, $send_recipient, $send_merchant); $this->verb = 'post'; return $this->doPayPalRequest(false); } /** * Send reminder for an existing invoice. * * @param string $invoice_id * @param string $subject * @param string $note * @param bool $send_recipient * @param bool $send_merchant * @param array $recipients * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_remind */ public function sendInvoiceReminder(string $invoice_id, string $subject = '', string $note = '', bool $send_recipient = true, bool $send_merchant = false, array $recipients = []) { $this->apiEndPoint = "v2/invoicing/invoices/{$invoice_id}/remind"; $this->options['json'] = $this->getInvoiceMessagePayload($subject, $note, $recipients, $send_recipient, $send_merchant); $this->verb = 'post'; return $this->doPayPalRequest(false); } /** * Cancel an existing invoice which is already sent. * * @param string $invoice_id * @param string $subject * @param string $note * @param bool $send_recipient * @param bool $send_merchant * @param array $recipients * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_cancel */ public function cancelInvoice(string $invoice_id, string $subject = '', string $note = '', bool $send_recipient = true, bool $send_merchant = false, array $recipients = []) { $this->apiEndPoint = "v2/invoicing/invoices/{$invoice_id}/cancel"; $this->options['json'] = $this->getInvoiceMessagePayload($subject, $note, $recipients, $send_recipient, $send_merchant); $this->verb = 'post'; return $this->doPayPalRequest(false); } /** * Register payment against an existing invoice. * * @param string $invoice_id * @param string $payment_date * @param string $payment_method * @param float $amount * @param string $payment_note * @param string $payment_id * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_payments */ public function registerPaymentInvoice(string $invoice_id, string $payment_date, string $payment_method, float $amount, string $payment_note = '', string $payment_id = '') { $this->apiEndPoint = "v2/invoicing/invoices/{$invoice_id}/payments"; $data = [ 'payment_id' => $payment_id, 'payment_date' => $payment_date, 'method' => $payment_method, 'note' => $payment_note, 'amount' => [ 'currency_code' => $this->currency, 'value' => $amount, ], ]; $this->options['json'] = $data; $this->verb = 'post'; return $this->doPayPalRequest(); } /** * Delete payment against an existing invoice. * * @param string $invoice_id * @param string $transaction_id * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_payments-delete */ public function deleteExternalPaymentInvoice(string $invoice_id, string $transaction_id) { $this->apiEndPoint = "v2/invoicing/invoices/{$invoice_id}/payments/{$transaction_id}"; $this->verb = 'delete'; return $this->doPayPalRequest(false); } /** * Register payment against an existing invoice. * * @param string $invoice_id * @param string $payment_date * @param string $payment_method * @param float $amount * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_refunds */ public function refundInvoice(string $invoice_id, string $payment_date, string $payment_method, float $amount) { $this->apiEndPoint = "v2/invoicing/invoices/{$invoice_id}/refunds"; $data = [ 'refund_date' => $payment_date, 'method' => $payment_method, 'amount' => [ 'currency_code' => $this->currency, 'value' => $amount, ], ]; $this->options['json'] = $data; $this->verb = 'post'; return $this->doPayPalRequest(); } /** * Delete refund against an existing invoice. * * @param string $invoice_id * @param string $transaction_id * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_refunds-delete */ public function deleteRefundInvoice(string $invoice_id, string $transaction_id) { $this->apiEndPoint = "v2/invoicing/invoices/{$invoice_id}/refunds/{$transaction_id}"; $this->verb = 'delete'; return $this->doPayPalRequest(false); } /** * Generate QR code against an existing invoice. * * @param string $invoice_id * @param int $width * @param int $height * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_generate-qr-code */ public function generateQRCodeInvoice(string $invoice_id, int $width = 100, int $height = 100) { $this->apiEndPoint = "v2/invoicing/invoices/{$invoice_id}/generate-qr-code"; $this->options['json'] = [ 'width' => $width, 'height' => $height, ]; $this->verb = 'post'; return $this->doPayPalRequest(); } /** * Generate the next invoice number. * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_generate-next-invoice-number */ public function generateInvoiceNumber() { $this->apiEndPoint = 'v2/invoicing/generate-next-invoice-number'; $this->verb = 'post'; return $this->doPayPalRequest(); } /** * Show details for an existing invoice. * * @param string $invoice_id * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_get */ public function showInvoiceDetails(string $invoice_id) { $this->apiEndPoint = "v2/invoicing/invoices/{$invoice_id}"; $this->verb = 'get'; return $this->doPayPalRequest(); } /** * Update an existing invoice. * * @param string $invoice_id * @param array $data * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_update */ public function updateInvoice(string $invoice_id, array $data) { $this->apiEndPoint = "v2/invoicing/invoices/{$invoice_id}"; $this->options['json'] = $data; $this->verb = 'put'; return $this->doPayPalRequest(); } /** * Delete an invoice. * * @param string $invoice_id * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_list */ public function deleteInvoice(string $invoice_id) { $this->apiEndPoint = "v2/invoicing/invoices/{$invoice_id}"; $this->verb = 'delete'; return $this->doPayPalRequest(false); } /** * Get Invoice Message Payload. * * @param string $subject * @param string $note * @param array $recipients * @param bool $send_recipient * @param bool $send_merchant * * @return array */ protected function getInvoiceMessagePayload(string $subject, string $note, array $recipients, bool $send_recipient, bool $send_merchant): array { $data = [ 'subject' => !empty($subject) ? $subject : '', 'note' => !empty($note) ? $note : '', 'additional_recipients' => (collect($recipients)->count() > 0) ? $recipients : '', 'send_to_recipient' => $send_recipient, 'send_to_invoicer' => $send_merchant, ]; return collect($data)->filter()->toArray(); } } paypal/src/Traits/PayPalAPI/Subscriptions/Helpers.php000064400000031724150364341100016575 0ustar00toIso8601String() : Carbon::now()->toIso8601String(); $body = [ 'plan_id' => $this->billing_plan['id'], 'start_time' => $start_date, 'quantity' => 1, 'subscriber' => [ 'name' => [ 'given_name' => $customer_name, ], 'email_address' => $customer_email, ], ]; if ($this->has_setup_fee) { $body['plan'] = [ 'payment_preferences' => $this->payment_preferences, ]; } if (isset($this->shipping_address)) { $body['subscriber']['shipping_address'] = $this->shipping_address; } if (isset($this->experience_context)) { $body['application_context'] = $this->experience_context; } if (isset($this->taxes)) { $body['taxes'] = $this->taxes; } $subscription = $this->createSubscription($body); unset($this->product); unset($this->billing_plan); unset($this->trial_pricing); unset($this->return_url); unset($this->cancel_url); return $subscription; } /** * Add a subscription trial pricing tier. * * @param string $interval_type * @param int $interval_count * @param float|int $price * * @return \Srmklive\PayPal\Services\PayPal */ public function addPlanTrialPricing(string $interval_type, int $interval_count, float $price = 0): \Srmklive\PayPal\Services\PayPal { $this->trial_pricing = $this->addPlanBillingCycle($interval_type, $interval_count, $price, true); return $this; } /** * Create a recurring daily billing plan. * * @param string $name * @param string $description * @param float|int $price * * @throws Throwable * * @return \Srmklive\PayPal\Services\PayPal */ public function addDailyPlan(string $name, string $description, float $price): \Srmklive\PayPal\Services\PayPal { if (isset($this->billing_plan)) { return $this; } $plan_pricing = $this->addPlanBillingCycle('DAY', 1, $price); $billing_cycles = empty($this->trial_pricing) ? [$plan_pricing] : collect([$this->trial_pricing, $plan_pricing])->filter()->toArray(); $this->addBillingPlan($name, $description, $billing_cycles); return $this; } /** * Create a recurring weekly billing plan. * * @param string $name * @param string $description * @param float|int $price * * @throws Throwable * * @return \Srmklive\PayPal\Services\PayPal */ public function addWeeklyPlan(string $name, string $description, float $price): \Srmklive\PayPal\Services\PayPal { if (isset($this->billing_plan)) { return $this; } $plan_pricing = $this->addPlanBillingCycle('WEEK', 1, $price); $billing_cycles = empty($this->trial_pricing) ? [$plan_pricing] : collect([$this->trial_pricing, $plan_pricing])->filter()->toArray(); $this->addBillingPlan($name, $description, $billing_cycles); return $this; } /** * Create a recurring monthly billing plan. * * @param string $name * @param string $description * @param float|int $price * * @throws Throwable * * @return \Srmklive\PayPal\Services\PayPal */ public function addMonthlyPlan(string $name, string $description, float $price): \Srmklive\PayPal\Services\PayPal { if (isset($this->billing_plan)) { return $this; } $plan_pricing = $this->addPlanBillingCycle('MONTH', 1, $price); $billing_cycles = empty($this->trial_pricing) ? [$plan_pricing] : collect([$this->trial_pricing, $plan_pricing])->filter()->toArray(); $this->addBillingPlan($name, $description, $billing_cycles); return $this; } /** * Create a recurring annual billing plan. * * @param string $name * @param string $description * @param float|int $price * * @throws Throwable * * @return \Srmklive\PayPal\Services\PayPal */ public function addAnnualPlan(string $name, string $description, float $price): \Srmklive\PayPal\Services\PayPal { if (isset($this->billing_plan)) { return $this; } $plan_pricing = $this->addPlanBillingCycle('YEAR', 1, $price); $billing_cycles = empty($this->trial_pricing) ? [$plan_pricing] : collect([$this->trial_pricing, $plan_pricing])->filter()->toArray(); $this->addBillingPlan($name, $description, $billing_cycles); return $this; } /** * Create a recurring billing plan with custom intervals. * * @param string $name * @param string $description * @param float|int $price * @param string $interval_unit * @param int $interval_count * * @throws Throwable * * @return \Srmklive\PayPal\Services\PayPal */ public function addCustomPlan(string $name, string $description, float $price, string $interval_unit, int $interval_count): \Srmklive\PayPal\Services\PayPal { $billing_intervals = ['DAY', 'WEEK', 'MONTH', 'YEAR']; if (isset($this->billing_plan)) { return $this; } if (!in_array($interval_unit, $billing_intervals)) { throw new \RuntimeException('Billing intervals should either be '.implode(', ', $billing_intervals)); } $plan_pricing = $this->addPlanBillingCycle($interval_unit, $interval_count, $price); $billing_cycles = empty($this->trial_pricing) ? [$plan_pricing] : collect([$this->trial_pricing, $plan_pricing])->filter()->toArray(); $this->addBillingPlan($name, $description, $billing_cycles); return $this; } /** * Add Plan's Billing cycle. * * @param string $interval_unit * @param int $interval_count * @param float $price * @param bool $trial * * @return array */ protected function addPlanBillingCycle(string $interval_unit, int $interval_count, float $price, bool $trial = false): array { $pricing_scheme = [ 'fixed_price' => [ 'value' => bcdiv($price, 1, 2), 'currency_code' => $this->getCurrency(), ], ]; if (empty($this->trial_pricing)) { $plan_sequence = 1; } else { $plan_sequence = 2; } return [ 'frequency' => [ 'interval_unit' => $interval_unit, 'interval_count' => $interval_count, ], 'tenure_type' => ($trial === true) ? 'TRIAL' : 'REGULAR', 'sequence' => ($trial === true) ? 1 : $plan_sequence, 'total_cycles' => ($trial === true) ? 1 : 0, 'pricing_scheme' => $pricing_scheme, ]; } /** * Create a product for a subscription's billing plan. * * @param string $name * @param string $description * @param string $type * @param string $category * * @throws Throwable * * @return \Srmklive\PayPal\Services\PayPal */ public function addProduct(string $name, string $description, string $type, string $category): \Srmklive\PayPal\Services\PayPal { if (isset($this->product)) { return $this; } $request_id = Str::random(); $this->product = $this->createProduct([ 'name' => $name, 'description' => $description, 'type' => $type, 'category' => $category, ], $request_id); return $this; } /** * Add subscription's billing plan's product by ID. * * @param string $product_id * * @return \Srmklive\PayPal\Services\PayPal */ public function addProductById(string $product_id): \Srmklive\PayPal\Services\PayPal { $this->product = [ 'id' => $product_id, ]; return $this; } /** * Add subscription's billing plan by ID. * * @param string $plan_id * * @return \Srmklive\PayPal\Services\PayPal */ public function addBillingPlanById(string $plan_id): \Srmklive\PayPal\Services\PayPal { $this->billing_plan = [ 'id' => $plan_id, ]; return $this; } /** * Create a product for a subscription's billing plan. * * @param string $name * @param string $description * @param array $billing_cycles * * @throws Throwable * * @return void */ protected function addBillingPlan(string $name, string $description, array $billing_cycles): void { $request_id = Str::random(); $plan_params = [ 'product_id' => $this->product['id'], 'name' => $name, 'description' => $description, 'status' => 'ACTIVE', 'billing_cycles' => $billing_cycles, 'payment_preferences' => [ 'auto_bill_outstanding' => true, 'setup_fee_failure_action' => 'CONTINUE', 'payment_failure_threshold' => $this->payment_failure_threshold, ], ]; $this->billing_plan = $this->createPlan($plan_params, $request_id); } /** * Set custom failure threshold when adding a subscription. * * @param int $threshold * * @return \Srmklive\PayPal\Services\PayPal */ public function addPaymentFailureThreshold(int $threshold): \Srmklive\PayPal\Services\PayPal { $this->payment_failure_threshold = $threshold; return $this; } /** * Add setup fee when adding a subscription. * * @param float $price * * @return \Srmklive\PayPal\Services\PayPal */ public function addSetupFee(float $price): \Srmklive\PayPal\Services\PayPal { $this->has_setup_fee = true; $this->payment_preferences = [ 'auto_bill_outstanding' => true, 'setup_fee' => [ 'value' => $price, 'currency_code' => $this->getCurrency(), ], 'setup_fee_failure_action' => 'CONTINUE', 'payment_failure_threshold' => $this->payment_failure_threshold, ]; return $this; } /** * Add shipping address. * * @param string $full_name * @param string $address_line_1 * @param string $address_line_2 * @param string $admin_area_2 * @param string $admin_area_1 * @param string $postal_code * @param string $country_code * * @return \Srmklive\PayPal\Services\PayPal */ public function addShippingAddress(string $full_name, string $address_line_1, string $address_line_2, string $admin_area_2, string $admin_area_1, string $postal_code, string $country_code): \Srmklive\PayPal\Services\PayPal { $this->shipping_address = [ 'name' => [ 'full_name' => $full_name, ], 'address' => [ 'address_line_1' => $address_line_1, 'address_line_2' => $address_line_2, 'admin_area_2' => $admin_area_2, 'admin_area_1' => $admin_area_1, 'postal_code' => $postal_code, 'country_code' => $country_code, ], ]; return $this; } /** * Add taxes when creating a subscription. * * @param float $percentage * * @return \Srmklive\PayPal\Services\PayPal */ public function addTaxes(float $percentage) { $this->taxes = [ 'percentage' => $percentage, 'inclusive' => false, ]; return $this; } } paypal/src/Traits/PayPalAPI/ReferencedPayouts.php000064400000004427150364341100015753 0ustar00apiEndPoint = 'v1/payments/referenced-payouts'; $this->options['json'] = $data; $this->verb = 'post'; return $this->doPayPalRequest(); } /** * Show Batch Payout details by ID. * * @param string $batch_payout_id * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/referenced-payouts/v1/#referenced-payouts_get_batch_details */ public function listItemsReferencedInBatchPayout(string $batch_payout_id) { $this->apiEndPoint = "v1/payments/referenced-payouts/{$batch_payout_id}"; $this->verb = 'get'; return $this->doPayPalRequest(); } /** * Create a referenced Batch Payout Item. * * @param array $data * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/referenced-payouts/v1/#referenced-payouts-items_create */ public function createReferencedBatchPayoutItem(array $data) { $this->apiEndPoint = 'v1/payments/referenced-payouts-items'; $this->options['json'] = $data; $this->verb = 'post'; return $this->doPayPalRequest(); } /** * Show Payout Item details by ID. * * @param string $payout_item_id * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/referenced-payouts/v1/#referenced-payouts-items_get */ public function showReferencedPayoutItemDetails(string $payout_item_id) { $this->apiEndPoint = "v1/payments/referenced-payouts-items/{$payout_item_id}"; $this->verb = 'get'; return $this->doPayPalRequest(); } } paypal/src/Traits/PayPalAPI/Disputes.php000064400000003035150364341100014116 0ustar00apiEndPoint = "v1/customer/disputes?page_size={$this->page_size}"; $this->verb = 'get'; return $this->doPayPalRequest(); } /** * Update a dispute. * * @param string $dispute_id * @param array $data * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_patch */ public function updateDispute(string $dispute_id, array $data) { $this->apiEndPoint = "v1/customer/disputes/{$dispute_id}"; $this->options['json'] = $data; $this->verb = 'patch'; return $this->doPayPalRequest(false); } /** * Get dispute details. * * @param string $dispute_id * * @throws \Throwable * * @return array|\Psr\Http\Message\StreamInterface|string * * @see https://developer.paypal.com/docs/api/customer-disputes/v1/#disputes_get */ public function showDisputeDetails(string $dispute_id) { $this->apiEndPoint = "v1/customer/disputes/{$dispute_id}"; $this->verb = 'get'; return $this->doPayPalRequest(); } } paypal/src/Traits/PayPalExperienceContext.php000064400000005224150364341100015343 0ustar00experience_context = array_merge($this->experience_context, [ 'brand_name' => $brand, ]); return $this; } /** * Set return & cancel urls. * * @param string $return_url * @param string $cancel_url * * @return \Srmklive\PayPal\Services\PayPal */ public function setReturnAndCancelUrl(string $return_url, string $cancel_url): \Srmklive\PayPal\Services\PayPal { $this->experience_context = array_merge($this->experience_context, [ 'return_url' => $return_url, 'cancel_url' => $cancel_url, ]); return $this; } /** * Set stored payment source. * * @param string $initiator * @param string $type * @param string $usage * @param bool $previous_reference * @param string|null $previous_transaction_id * @param string|null $previous_transaction_date * @param string|null $previous_transaction_reference_number * @param string|null $previous_transaction_network * * @return \Srmklive\PayPal\Services\PayPal */ public function setStoredPaymentSource(string $initiator, string $type, string $usage, bool $previous_reference = false, string $previous_transaction_id = null, string $previous_transaction_date = null, string $previous_transaction_reference_number = null, string $previous_transaction_network = null): \Srmklive\PayPal\Services\PayPal { $this->experience_context = array_merge($this->experience_context, [ 'stored_payment_source' => [ 'payment_initiator' => $initiator, 'payment_type' => $type, 'usage' => $usage, ], ]); if ($previous_reference === true) { $this->experience_context['stored_payment_source']['previous_network_transaction_reference'] = [ 'id' => $previous_transaction_id, 'date' => $previous_transaction_date, 'acquirer_reference_number' => $previous_transaction_reference_number, 'network' => $previous_transaction_network, ]; } return $this; } } paypal/src/Traits/PayPalAPI.php000064400000006513150364341100012322 0ustar00apiEndPoint = 'v1/oauth2/token'; $this->options['auth'] = [$this->config['client_id'], $this->config['client_secret']]; $this->options[$this->httpBodyParam] = [ 'grant_type' => 'client_credentials', ]; $response = $this->doPayPalRequest(); unset($this->options['auth']); unset($this->options[$this->httpBodyParam]); if (isset($response['access_token'])) { $this->setAccessToken($response); } return $response; } /** * Set PayPal Rest API access token. * * @param array $response * * @return void */ public function setAccessToken(array $response) { $this->access_token = $response['access_token']; $this->setPayPalAppId($response); $this->setRequestHeader('Authorization', "{$response['token_type']} {$this->access_token}"); } /** * Set PayPal App ID. * * @param array $response * * @return void */ private function setPayPalAppId(array $response) { $app_id = empty($response['app_id']) ? $this->config['app_id'] : $response['app_id']; $this->config['app_id'] = $app_id; } /** * Set records per page for list resources API calls. * * @param int $size * * @return \Srmklive\PayPal\Services\PayPal */ public function setPageSize(int $size): \Srmklive\PayPal\Services\PayPal { $this->page_size = $size; return $this; } /** * Set the current page for list resources API calls. * * @param int $size * * @return \Srmklive\PayPal\Services\PayPal */ public function setCurrentPage(int $page): \Srmklive\PayPal\Services\PayPal { $this->current_page = $page; return $this; } /** * Toggle whether totals for list resources are returned after every API call. * * @param bool $totals * * @return \Srmklive\PayPal\Services\PayPal */ public function showTotals(bool $totals): \Srmklive\PayPal\Services\PayPal { $this->show_totals = $totals; return $this; } } paypal/src/Services/Str.php000064400000001221150364341100011656 0ustar00setConfig($config); $this->httpBodyParam = 'form_params'; $this->options = []; $this->setRequestHeader('Accept', 'application/json'); } /** * Set ExpressCheckout API endpoints & options. * * @param array $credentials */ protected function setOptions(array $credentials): void { // Setting API Endpoints $this->config['api_url'] = 'https://api-m.paypal.com'; $this->config['gateway_url'] = 'https://www.paypal.com'; $this->config['ipn_url'] = 'https://ipnpb.paypal.com/cgi-bin/webscr'; if ($this->mode === 'sandbox') { $this->config['api_url'] = 'https://api-m.sandbox.paypal.com'; $this->config['gateway_url'] = 'https://www.sandbox.paypal.com'; $this->config['ipn_url'] = 'https://ipnpb.sandbox.paypal.com/cgi-bin/webscr'; } // Adding params outside sandbox / live array $this->config['payment_action'] = $credentials['payment_action']; $this->config['notify_url'] = $credentials['notify_url']; $this->config['locale'] = $credentials['locale']; } } paypal/src/Services/VerifyDocuments.php000064400000003227150364341100014244 0ustar00 $file_size) { $validSize = false; break; } $total_size += $size; } return (($validFile === false) || ($validSize === false)) || ($total_size > $overall_size) ? false : true; } } paypal/src/Facades/PayPal.php000064400000000652150364341100012046 0ustar00publishes([ __DIR__.'/../../config/config.php' => config_path('paypal.php'), ]); // Publish Lang Files $this->loadTranslationsFrom(__DIR__.'/../../lang', 'paypal'); } /** * Register the service provider. * * @return void */ public function register() { $this->registerPayPal(); $this->mergeConfig(); } /** * Register the application bindings. * * @return void */ private function registerPayPal() { $this->app->singleton('paypal_client', static function () { return new PayPalClient(); }); } /** * Merges user's and paypal's configs. * * @return void */ private function mergeConfig() { $this->mergeConfigFrom( __DIR__.'/../../config/config.php', 'paypal' ); } } paypal/src/PayPalFacadeAccessor.php000064400000001461150364341100013266 0ustar00 ## Documentation The documentation for the package can be viewed by clicking the following link: [https://srmklive.github.io/laravel-paypal/docs.html](https://srmklive.github.io/laravel-paypal/docs.html) ## Usage Following are some ways through which you can access the paypal provider: ```php // Import the class namespaces first, before using it directly use Srmklive\PayPal\Services\PayPal as PayPalClient; $provider = new PayPalClient; // Through facade. No need to import namespaces $provider = \PayPal::setProvider(); ``` ## Configuration File The configuration file **paypal.php** is located in the **config** folder. Following are its contents when published: ```php return [ 'mode' => env('PAYPAL_MODE', 'sandbox'), // Can only be 'sandbox' Or 'live'. If empty or invalid, 'live' will be used. 'sandbox' => [ 'client_id' => env('PAYPAL_SANDBOX_CLIENT_ID', ''), 'client_secret' => env('PAYPAL_SANDBOX_CLIENT_SECRET', ''), 'app_id' => 'APP-80W284485P519543T', ], 'live' => [ 'client_id' => env('PAYPAL_LIVE_CLIENT_ID', ''), 'client_secret' => env('PAYPAL_LIVE_CLIENT_SECRET', ''), 'app_id' => env('PAYPAL_LIVE_APP_ID', ''), ], 'payment_action' => env('PAYPAL_PAYMENT_ACTION', 'Sale'), // Can only be 'Sale', 'Authorization' or 'Order' 'currency' => env('PAYPAL_CURRENCY', 'USD'), 'notify_url' => env('PAYPAL_NOTIFY_URL', ''), // Change this accordingly for your application. 'locale' => env('PAYPAL_LOCALE', 'en_US'), // force gateway language i.e. it_IT, es_ES, en_US ... (for express checkout only) 'validate_ssl' => env('PAYPAL_VALIDATE_SSL', true), // Validate SSL when creating api client. ]; ``` ## Override PayPal API Configuration You can override PayPal API configuration by calling `setApiCredentials` method: ```php $config = [ 'mode' => 'live', 'live' => [ 'client_id' => 'PAYPAL_LIVE_CLIENT_ID', 'client_secret' => 'PAYPAL_LIVE_CLIENT_SECRET', 'app_id' => 'PAYPAL_LIVE_APP_ID', ], 'payment_action' => 'Sale', 'currency' => 'USD', 'notify_url' => 'https://your-site.com/paypal/notify', 'locale' => 'en_US', 'validate_ssl' => true, ]; $provider->setApiCredentials($config); ``` ## Get Access Token After setting the PayPal API configuration by calling `setApiCredentials` method. You need to get access token before performing any API calls ```php $provider->getAccessToken(); ``` ## Set Currency By default, the currency used is `USD`. If you wish to change it, you may call `setCurrency` method to set a different currency before calling any respective API methods: ```php $provider->setCurrency('EUR'); ``` ## Helper Methods > Please note that in the examples below, the call to `addPlanTrialPricing` is optional and it can be omitted when you are creating subscriptions without trial period. > `setReturnAndCancelUrl()` is optional. If you set urls you have to use real domains. e.g. localhost, project.test does not work. ### Create Recurring Daily Subscription ```php $response = $provider->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE') ->addPlanTrialPricing('DAY', 7) ->addDailyPlan('Demo Plan', 'Demo Plan', 1.50) ->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel') ->setupSubscription('John Doe', 'john@example.com', '2021-12-10'); ``` ### Create Recurring Weekly Subscription ```php $response = $provider->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE') ->addPlanTrialPricing('DAY', 7) ->addWeeklyPlan('Demo Plan', 'Demo Plan', 30) ->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel') ->setupSubscription('John Doe', 'john@example.com', '2021-12-10'); ``` ### Create Recurring Monthly Subscription ```php $response = $provider->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE') ->addPlanTrialPricing('DAY', 7) ->addMonthlyPlan('Demo Plan', 'Demo Plan', 100) ->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel') ->setupSubscription('John Doe', 'john@example.com', '2021-12-10'); ``` ### Create Recurring Annual Subscription ```php $response = $provider->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE') ->addPlanTrialPricing('DAY', 7) ->addAnnualPlan('Demo Plan', 'Demo Plan', 600) ->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel') ->setupSubscription('John Doe', 'john@example.com', '2021-12-10'); ``` ### Create Recurring Subscription with Custom Intervals ```php $response = $provider->addProduct('Demo Product', 'Demo Product', 'SERVICE', 'SOFTWARE') ->addCustomPlan('Demo Plan', 'Demo Plan', 150, 'MONTH', 3) ->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel') ->setupSubscription('John Doe', 'john@example.com', '2021-12-10'); ``` ### Create Subscription by Existing Product & Billing Plan ```php $response = $this->client->addProductById('PROD-XYAB12ABSB7868434') ->addBillingPlanById('P-5ML4271244454362WXNWU5NQ') ->setReturnAndCancelUrl('https://example.com/paypal-success', 'https://example.com/paypal-cancel') ->setupSubscription('John Doe', 'john@example.com', $start_date); ``` ## Support This version supports Laravel 6 or greater. * In case of any issues, kindly create one on the [Issues](https://github.com/srmklive/laravel-paypal/issues) section. * If you would like to contribute: * Fork this repository. * Implement your features. * Generate pull request. paypal/.github/workflows/tests.yml000064400000004672150364341100013322 0ustar00name: Laravel PayPal on: [push, pull_request] jobs: paypal: name: PHP ${{ matrix.php-versions }} runs-on: ubuntu-latest strategy: fail-fast: false matrix: php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2'] steps: - name: Checkout uses: actions/checkout@v2 with: lfs: true - name: Checkout LFS objects run: git lfs checkout - name: Setup PHP with Composer and extensions with: php-version: ${{ matrix.php-versions }} uses: shivammathur/setup-php@v2 - name: Get Composer cache directory id: composercache run: echo "::set-output name=dir::$(composer config cache-files-dir)" - name: Cache Composer dependencies uses: actions/cache@v2 with: php-version: ${{ matrix.php-versions }} path: ${{ steps.composercache.outputs.dir }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- - name: Install Composer dependencies env: PHP_VERSION: ${{ matrix.php-versions }} run: composer install --no-progress --prefer-dist --optimize-autoloader $(if [ "$PHP_VERSION" == "8.0" || "$PHP_VERSION" == "8.1" ]; then echo "--ignore-platform-reqs"; fi;) - name: Run tests with code coverage env: PHP_VERSION: ${{ matrix.php-versions }} run: vendor/bin/phpunit $(if [ "$PHP_VERSION" == "7.2" ]; then echo "-c phpunit.xml.dist.php72"; fi;) $(if [ "$PHP_VERSION" == "7.3" ]; then echo "-c phpunit.xml.dist.php8"; fi;) $(if [ "$PHP_VERSION" == "7.4" ]; then echo "-c phpunit.xml.dist.php8"; fi;) $(if [ "$PHP_VERSION" == "8.0" ]; then echo "-c phpunit.xml.dist.php8"; fi;) --coverage-clover build/logs/clover.xml - name: Install PHP Coveralls library env: PHP_VERSION: ${{ matrix.php-versions }} run: composer global require --dev php-coveralls/php-coveralls - name: Upload coverage results to Coveralls env: PHP_VERSION: ${{ matrix.php-versions }} COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} COVERALLS_PARALLEL: true COVERALLS_FLAG_NAME: php-${{ matrix.php-versions }} run: php-coveralls -v coveralls-finish: needs: [paypal] runs-on: ubuntu-latest steps: - name: Coveralls Finished uses: coverallsapp/github-action@master with: github-token: ${{ secrets.github_token }} parallel-finished: true paypal/.github/workflows/static-analysis.yml000064400000002451150364341100015261 0ustar00name: Static Analysis on: [push, pull_request] jobs: paypal: name: PHP ${{ matrix.php-versions }} runs-on: ubuntu-latest strategy: fail-fast: false matrix: php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2'] steps: - name: Checkout uses: actions/checkout@v2 - name: Setup PHP with Composer and extensions with: php-version: ${{ matrix.php-versions }} uses: shivammathur/setup-php@v2 - name: Get Composer cache directory id: composercache run: echo "::set-output name=dir::$(composer config cache-files-dir)" - name: Cache Composer dependencies uses: actions/cache@v2 with: php-version: ${{ matrix.php-versions }} path: ${{ steps.composercache.outputs.dir }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- - name: Install Composer dependencies env: PHP_VERSION: ${{ matrix.php-versions }} run: composer install --no-progress --prefer-dist --optimize-autoloader $(if [ "$PHP_VERSION" == "8.0" || "$PHP_VERSION" == "8.1" ]; then echo "--ignore-platform-reqs"; fi;) - name: Run type checking analysis env: PHP_VERSION: ${{ matrix.php-versions }} run: vendor/bin/phpstan paypal/config/config.php000064400000002241150364341100011251 0ustar00. */ return [ 'mode' => env('PAYPAL_MODE', 'sandbox'), // Can only be 'sandbox' Or 'live'. If empty or invalid, 'live' will be used. 'sandbox' => [ 'client_id' => env('PAYPAL_SANDBOX_CLIENT_ID', ''), 'client_secret' => env('PAYPAL_SANDBOX_CLIENT_SECRET', ''), 'app_id' => 'APP-80W284485P519543T', ], 'live' => [ 'client_id' => env('PAYPAL_LIVE_CLIENT_ID', ''), 'client_secret' => env('PAYPAL_LIVE_CLIENT_SECRET', ''), 'app_id' => env('PAYPAL_LIVE_APP_ID', ''), ], 'payment_action' => env('PAYPAL_PAYMENT_ACTION', 'Sale'), // Can only be 'Sale', 'Authorization' or 'Order' 'currency' => env('PAYPAL_CURRENCY', 'USD'), 'notify_url' => env('PAYPAL_NOTIFY_URL', ''), // Change this accordingly for your application. 'locale' => env('PAYPAL_LOCALE', 'en_US'), // force gateway language i.e. it_IT, es_ES, en_US ... (for express checkout only) 'validate_ssl' => env('PAYPAL_VALIDATE_SSL', true), // Validate SSL when creating api client. ]; paypal/phpunit.xml.dist.php72000064400000002245150364341100012144 0ustar00 tests src/ src/PayPalFacadeAccessor.php src/Traits/PayPalVerifyIPN.php src/Services/Str.php src/Facades/ src/Providers/ paypal/.gitattributes000064400000000052150364341100010717 0ustar00*.pdf filter=lfs diff=lfs merge=lfs -text paypal/Dockerfile000064400000000654150364341100010026 0ustar00FROM srmklive/docker-php-cli:7.4 LABEL maintainer="Raza Mehdi" ENV DEBIAN_FRONTEND=noninteractive # Set apps home directory. ENV APP_DIR /server/http # Define current working directory. WORKDIR ${APP_DIR} RUN apt-get -y autoclean \ && apt-get -y autoremove \ && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* COPY supervisor.conf /etc/supervisor/conf.d/supervisord.conf CMD ["/usr/bin/supervisord"]paypal/lang/en/error.php000064400000000463150364341100011217 0ustar00 'Unable To Process Payment As Your Transaction Was Declined On PayPal', 'paypal_transaction_not_verified' => 'Unable To Verify Transaction From PayPal', 'paypal_connection_error' => 'Unable To Connect To PayPal. Please Try Again', ]; paypal/lang/fr/error.php000064400000000532150364341100011221 0ustar00 'Impossible de traiter le paiement car votre transaction a été refusée sur PayPal', 'paypal_transaction_not_verified' => 'Impossible de vérifier la transaction depuis PayPal', 'paypal_connection_error' => 'Impossible de se connecter à PayPal. Veuillez réessayer', ]; paypal/.scrutinizer.yml000064400000001533150364341100011213 0ustar00filter: excluded_paths: [tests/*] checks: php: remove_extra_empty_lines: true remove_php_closing_tag: true remove_trailing_whitespace: true fix_use_statements: remove_unused: true preserve_multiple: false preserve_blanklines: true order_alphabetically: true fix_php_opening_tag: true fix_linefeed: true fix_line_ending: true fix_identation_4spaces: true fix_doc_comments: true build: nodes: analysis: tests: override: - php-scrutinizer-run environment: php: version: 8.1.13 tests: override: - command: 'vendor/bin/phpunit --coverage-clover=build/logs/clover.xml' coverage: file: 'build/logs/clover.xml' format: 'clover' paypal/phpunit.xml.dist000064400000002170150364341100011202 0ustar00 tests src/ src/PayPalFacadeAccessor.php src/Traits/PayPalVerifyIPN.php src/Services/Str.php src/Facades/ src/Providers/ paypal/docker-compose.yml000064400000000261150364341100011463 0ustar00version: '2' services: app: build: context: ./ dockerfile: Dockerfile image: srmklive/laravel-paypal restart: always volumes: - ./:/server/httppaypal/LICENSE000064400000002070150364341100007033 0ustar00The MIT License (MIT) Copyright (c) 2015 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. paypal/.coveralls.yml000064400000000030150364341100010613 0ustar00service_name: github-ci paypal/.gitignore000064400000000135150364341100010016 0ustar00/vendor /.idea .env composer.lock /build *-container* *.phpunit* test.php /.venv /docs/build paypal/phpstan.neon.dist000064400000000325150364341100011327 0ustar00parameters: paths: - src level: 0 ignoreErrors: - "#Parameter#" - "#Call to static method error\\(\\)\\ on an unknown class Log.#" excludePaths: - "src/Providers/PayPalServiceProvider.php" paypal/.travis.yml.bak000064400000001710150364341100010673 0ustar00language: php sudo: false php: - 7.0 - 7.1 - 7.2 - 7.3 - 7.4 env: global: - setup=stable - coverage=no before_script: - composer update --prefer-dist --no-interaction script: - if [[ $coverage = 'yes' ]]; then ./vendor/bin/phpunit $(if [ "$TRAVIS_PHP_VERSION" == "7.1" ] || [ "$TRAVIS_PHP_VERSION" == "7.2" ]; then echo "-c phpunit.xml.legacy"; fi;) --coverage-clover build/logs/clover.xml; fi - if [[ $coverage = 'no' ]]; then ./vendor/bin/phpunit $(if [ "$TRAVIS_PHP_VERSION" == "7.1" ] || [ "$TRAVIS_PHP_VERSION" == "7.2" ]; then echo "-c phpunit.xml.legacy"; fi;); fi after_script: - if [[ $setup = 'coveralls' ]]; then php vendor/bin/php-coveralls -v; fi matrix: include: - php: 7.0 env: setup=coveralls coverage=yes - php: 7.1 env: setup=coveralls coverage=yes - php: 7.2 env: setup=coveralls coverage=yes - php: 7.3 env: setup=coveralls coverage=yes - php: 7.4 env: setup=coveralls coverage=yes fast_finish: true