diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml old mode 100644 new mode 100755 diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 index ebf292d..b0e0a1b --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ /vendor/ .phpunit.result.cache -.idea/ -.idea +.idea/* +.idea* ray.php +.phpunit.cache +.env diff --git a/.phpunit.result.cache b/.phpunit.result.cache old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/ROADMAP.md b/ROADMAP.md old mode 100644 new mode 100755 diff --git a/composer.json b/composer.json old mode 100644 new mode 100755 diff --git a/composer.lock b/composer.lock old mode 100644 new mode 100755 diff --git a/config/paypal.php b/config/paypal.php old mode 100644 new mode 100755 diff --git a/phpunit.xml b/phpunit.xml old mode 100644 new mode 100755 diff --git a/ray.php b/ray.php old mode 100644 new mode 100755 diff --git a/src/Client/PaypalClient.php b/src/Client/PaypalClient.php old mode 100644 new mode 100755 index dc0938c..c37d9a4 --- a/src/Client/PaypalClient.php +++ b/src/Client/PaypalClient.php @@ -2,21 +2,18 @@ namespace Drewdan\Paypal\Client; -use JsonMapper; use Illuminate\Support\Str; -use Illuminate\Http\Request; use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Http; use Illuminate\Http\Client\Response; use Illuminate\Http\Client\PendingRequest; -use Drewdan\Paypal\Builders\PaymentSource\Paypal; use Drewdan\Paypal\Exceptions\InvalidClientException; use Drewdan\Paypal\Exceptions\InvalidRequestException; use Drewdan\Paypal\Exceptions\MissingCredentialsException; class PaypalClient { - const VERSION = '/v2/'; + private string $version = '/v2/'; const SANDBOX_URL = 'https://api-m.sandbox.paypal.com'; @@ -28,19 +25,39 @@ class PaypalClient { /** * @throws \Drewdan\Paypal\Exceptions\MissingCredentialsException */ - public function __construct(public bool $responseAsArray = false) { + public function __construct(public bool $responseAsArray = false, public bool $useV1 = false) { if ( Str::of(config('paypal.client_id'))->trim()->isEmpty() || Str::of(config('paypal.secret'))->trim()->isEmpty()) { throw new MissingCredentialsException('You have not set your Paypal Credentials'); } + + if ($this->useV1) { + $this->version = '/v1/'; + } + $this->client = Http::withBasicAuth(config('paypal.client_id'), config('paypal.secret')) ->asJson() ->baseUrl($this->generateBaseUrl()); } - public static function make(bool $responseAsArray = false): static { - return App::make(PaypalClient::class, ['responseAsArray' => $responseAsArray]); + public static function make(bool $responseAsArray = false, bool $useV1 = false): static { + return App::make( + PaypalClient::class, + [ + 'responseAsArray' => $responseAsArray, + 'useV1' => $useV1, + ] + ); + } + + public function getClient(): PendingRequest { + return $this->client; + } + + public function withQuery(array $query): static { + $this->client->withQuery($query); + return $this; } /** @@ -76,7 +93,7 @@ public function __call(string $name, array $arguments = []) { public function generateBaseUrl(): string { return (config('paypal.environment') === 'LIVE' ? self::LIVE_URL - : self::SANDBOX_URL) . self::VERSION; + : self::SANDBOX_URL) . $this->version; } /** diff --git a/src/Contracts/BuildsPayload.php b/src/Common/Contracts/BuildsPayload.php old mode 100644 new mode 100755 similarity index 60% rename from src/Contracts/BuildsPayload.php rename to src/Common/Contracts/BuildsPayload.php index 582c6fc..33502ac --- a/src/Contracts/BuildsPayload.php +++ b/src/Common/Contracts/BuildsPayload.php @@ -1,6 +1,6 @@ purchaseUnits = collect(); $this->client = PaypalClient::make(true); } @@ -61,7 +59,7 @@ public function setPaymentSource(PaymentSource $paymentSource): static { public function buildPayload(): array { return [ - 'purchase_units' => $this->purchaseUnits->map(fn($unit) => $unit->buildPayload())->toArray(), + 'purchase_units' => $this->purchaseUnits->map(fn ($unit) => $unit->buildPayload())->toArray(), 'intent' => $this->intent->value, 'payment_source' => $this->paymentSource->buildPaymentSource(), ]; diff --git a/src/Builders/PaymentSource/PaymentSource.php b/src/Orders/Builders/PaymentSource/PaymentSource.php old mode 100644 new mode 100755 similarity index 86% rename from src/Builders/PaymentSource/PaymentSource.php rename to src/Orders/Builders/PaymentSource/PaymentSource.php index 1cd9398..4ff4e4b --- a/src/Builders/PaymentSource/PaymentSource.php +++ b/src/Orders/Builders/PaymentSource/PaymentSource.php @@ -1,6 +1,6 @@ client = PaypalClient::make(true); } - public static function fromResponse(array $response): Order { + public static function fromResponse(array $response): static { return new Order( create_time: $response['create_time'] ?? null, update_time: $response['update_time'] ?? null, diff --git a/src/Models/Payment.php b/src/Orders/Models/Payment.php old mode 100644 new mode 100755 similarity index 83% rename from src/Models/Payment.php rename to src/Orders/Models/Payment.php index 41241f8..bc26939 --- a/src/Models/Payment.php +++ b/src/Orders/Models/Payment.php @@ -1,8 +1,8 @@ events = collect(); + $this->client = PaypalClient::make( + responseAsArray: true, + useV1: true + ); + } + + public static function make(): static { + return App::make(static::class); + } + + public function setUrl(string $url): static { + $this->url = $url; + + return $this; + } + + public function setEvents(array|Collection $events): static { + $this->events = $events instanceof Collection + ? $events + : collect($events); + + return $this; + } + + public function addEvent(string $event): static { + $this->events->push($event); + + return $this; + } + + public function buildPayload(): array { + return [ + 'url' => $this->url, + 'events' => $this->events->mapWithKeys(fn (WebhookEventEnum $event) => ['name' => $event]), + ]; + } + + public function create(): Webhook { + $response = $this->client->client->post('notifications/webhooks', $this->buildPayload()); + + return Webhook::fromResponse($response->json()); + } +} diff --git a/src/Webhooks/Builders/WebhookEventQueryBuilder.php b/src/Webhooks/Builders/WebhookEventQueryBuilder.php new file mode 100644 index 0000000..e111c66 --- /dev/null +++ b/src/Webhooks/Builders/WebhookEventQueryBuilder.php @@ -0,0 +1,75 @@ +client = PaypalClient::make( + responseAsArray: true, + useV1: true + ); + } + + public static function make(): static { + return App::make(static::class); + } + + public function pageSize(int $page_size): static { + $this->page_size = $page_size; + return $this; + } + + public function startTime(CarbonImmutable|Carbon $start_time): static { + $this->start_time = $start_time; + return $this; + } + + public function endTime(CarbonImmutable|Carbon $end_time): static { + $this->end_time = $end_time; + return $this; + } + + public function transactionId(string $transaction_id): static { + $this->transaction_id = $transaction_id; + return $this; + } + + public function eventType(WebhookEventEnum $event_type): static { + $this->event_type = $event_type; + return $this; + } + + public function get(): Events { + $response = $this->client->get( + 'notifications/webhooks-events', + array_filter( + [ + 'page_size' => $this->page_size, + 'start_time' => $this->start_time?->toIso8601ZuluString(), + 'end_time' => $this->end_time?->toIso8601ZuluString(), + 'transaction_id' => $this->transaction_id, + 'event_type' => $this->event_type?->value, + ] + ) + ); + + return Events::fromResponse($response); + } + +} diff --git a/src/Webhooks/Enums/WebhookEventEnum.php b/src/Webhooks/Enums/WebhookEventEnum.php new file mode 100644 index 0000000..ea6636e --- /dev/null +++ b/src/Webhooks/Enums/WebhookEventEnum.php @@ -0,0 +1,38 @@ +push(EventType::fromArray($eventType)); + } + + return new static( + eventTypes: $eventTypes, + ); + } + + public static function listForWebhookById(string $id) { + $response = PaypalClient::make(responseAsArray: true, useV1: true)->get("notifications/webhooks/{$id}/event-types"); + + + return static::fromArray($response['event_types']); + } +} diff --git a/src/Webhooks/Models/Events.php b/src/Webhooks/Models/Events.php new file mode 100644 index 0000000..b0bfffd --- /dev/null +++ b/src/Webhooks/Models/Events.php @@ -0,0 +1,72 @@ +client = PaypalClient::make( + responseAsArray: true, + useV1: true + )->getClient()->baseUrl(''); + } + + public static function fromResponse(array $response): static { + return new static( + events: collect($response['events'] ?? [])->map(fn ($event) => WebhookEvent::fromResponse($event)), + count: $response['count'] ?? 0, + links: Arr::has($response, 'links') + ? Links::fromArray($response['links']) + : null, + ); + } + + public function getEvents(): Collection { + return $this->events; + } + + public function hasNextPage(): bool { + return $this->links->getByRef('next') !== null; + } + + public function hasPreviousPage(): bool { + return $this->links->getByRef('previous') !== null; + } + + public function nextPage(): null|static { + $link = $this->links->getByRef('next'); + + if ($link) { + $response = $this->client->get($link->href); + return static::fromResponse($response); + } + + return null; + } + + public function previousPage(): null|static { + $link = $this->links->getByRef('previous'); + + if ($link) { + $response = $this->client->get($link->href); + return static::fromResponse($response); + } + + return null; + + } + +} diff --git a/src/Webhooks/Models/Resource.php b/src/Webhooks/Models/Resource.php new file mode 100644 index 0000000..74a7d8d --- /dev/null +++ b/src/Webhooks/Models/Resource.php @@ -0,0 +1,36 @@ +client = PaypalClient::make( + responseAsArray: true, + useV1: true + ); + } + + public static function builder(): WebhookBuilder { + return App::make(WebhookBuilder::class); + } + + public static function all(): Collection { + $response = PaypalClient::make(responseAsArray: true, useV1: true)->get('notifications/webhooks'); + $webhooks = collect(); + + if (!Arr::has($response, 'webhooks')) { + return $webhooks; + } + + foreach($response['webhooks'] as $webhook) { + $webhooks->push(static::fromResponse($webhook)); + } + + return $webhooks; + } + + public static function retrieve(string $id): static { + $response = PaypalClient::make(responseAsArray: true, useV1: true)->get("notifications/webhooks/{$id}"); + + return static::fromResponse($response); + } + + public static function fromResponse(array $response): static { + return new Webhook( + id: $response['id'] ?? null, + url: $response['url'] ?? null, + event_types: Arr::has($response, 'event_types') + ? EventTypes::fromArray($response['event_types']) + : null, + links: $response['links'] + ? Links::fromArray($response['links']) + : null, + ); + } + + public function listEvents(): Collection { + return $this->event_types->eventTypes; + } + + public function delete(): void { + $this->client->delete("notifications/webhooks/{$this->id}"); + $this->isDeleted = true; + } +} diff --git a/src/Webhooks/Models/WebhookEvent.php b/src/Webhooks/Models/WebhookEvent.php new file mode 100644 index 0000000..a7c3554 --- /dev/null +++ b/src/Webhooks/Models/WebhookEvent.php @@ -0,0 +1,66 @@ +get("notifications/webhooks-events/{$id}"); + + return static::fromResponse($response); + } + + public static function resend(string $id): static { + $response = PaypalClient::make(responseAsArray: true, useV1: true)->post("notifications/webhooks-events/{$id}/resend"); + + return static::fromResponse($response); + } + + public static function simulate(string $url, WebhookEventEnum $eventType, string $resourceVersion = '2.0'): static { + $response = PaypalClient::make(responseAsArray: true, useV1: true)->post('notifications/simulate-event', [ + 'url' => $url, + 'event_type' => $eventType->value, + 'resource_version' => $resourceVersion, + ]); + + return static::fromResponse($response); + } + + public static function query(): WebhookEventQueryBuilder { + return WebhookEventQueryBuilder::make(); + } +} diff --git a/tests/TestCase.php b/tests/TestCase.php old mode 100644 new mode 100755 diff --git a/tests/Unit/Client/PaypalClientTest.php b/tests/Unit/Client/PaypalClientTest.php old mode 100644 new mode 100755 diff --git a/tests/Unit/Builders/OrderBuilderTest.php b/tests/Unit/Orders/Builders/OrderBuilderTest.php old mode 100644 new mode 100755 similarity index 86% rename from tests/Unit/Builders/OrderBuilderTest.php rename to tests/Unit/Orders/Builders/OrderBuilderTest.php index bb44da2..b79900c --- a/tests/Unit/Builders/OrderBuilderTest.php +++ b/tests/Unit/Orders/Builders/OrderBuilderTest.php @@ -1,21 +1,21 @@ Http::response($this->getApiResponse('create_webhook')), + ]); + + $webhook = WebhookBuilder::make() + ->setUrl('https://example.com/example_webhook') + ->setEvents( + [ + WebhookEventEnum::PAYMENT_AUTHORIZATION_CREATED, + WebhookEventEnum::PAYMENT_CAPTURE_COMPLETED, + ] + ) + ->create(); + + $this->assertEquals('https://example.com/example_webhook', $webhook->url); + $this->assertCount(2, $webhook->listEvents()); + } +} diff --git a/tests/Unit/Webhooks/Models/EventTypesTest.php b/tests/Unit/Webhooks/Models/EventTypesTest.php new file mode 100644 index 0000000..c9e73df --- /dev/null +++ b/tests/Unit/Webhooks/Models/EventTypesTest.php @@ -0,0 +1,21 @@ + Http::response($this->getApiResponse('list_event_subscriptions_for_webhook')), + ]); + + $eventTypes = EventTypes::listForWebhookById('0EH40505U7160970P'); + + $this->assertCount(3, $eventTypes->eventTypes); + + } +} diff --git a/tests/Unit/Webhooks/Models/WebhookEventTest.php b/tests/Unit/Webhooks/Models/WebhookEventTest.php new file mode 100644 index 0000000..05f6f29 --- /dev/null +++ b/tests/Unit/Webhooks/Models/WebhookEventTest.php @@ -0,0 +1,144 @@ + Http::response($this->getApiResponse('simulate_webhook')), + ]); + + $webhookEvent = WebhookEvent::simulate( + 'https://example.com', + WebhookEventEnum::PAYMENT_AUTHORIZATION_CREATED + ); + + $this->assertInstanceOf(WebhookEvent::class, $webhookEvent); + + $this->assertEquals('8PT597110X687430LKGECATA', $webhookEvent->id); + $this->assertEquals(Date::parse('2013-06-25T21:41:28Z'), $webhookEvent->create_time); + $this->assertEquals('authorization', $webhookEvent->resource_type); + $this->assertEquals('1.0', $webhookEvent->event_version); + $this->assertEquals(WebhookEventEnum::PAYMENT_AUTHORIZATION_CREATED, $webhookEvent->event_type); + $this->assertEquals('A payment authorization was created', $webhookEvent->summary); + $this->assertEquals('1.0', $webhookEvent->resource_version); + + $resource = $webhookEvent->resource; + + $this->assertEquals('2DC87612EK520411B', $resource->id); + $this->assertEquals(Date::parse('2013-06-25T21:39:15Z'), $resource->create_time); + $this->assertEquals(Date::parse('2013-06-25T21:39:17Z'), $resource->update_time); + $this->assertEquals('authorized', $resource->state); + $this->assertEquals('PAY-36246664YD343335CKHFA4AY', $resource->parent_payment); + $this->assertEquals(Date::parse('2013-07-24T21:39:15Z'), $resource->valid_until); + + $amount = $resource->amount; + + $this->assertEquals('USD', $amount->currency); + $this->assertEquals('7.47', $amount->total); + + $details = $amount->details; + + $this->assertEquals('7.47', $details->subtotal); + } + + public function testCanResendEvent() { + Http::fake([ + 'https://api-m.paypal.com/v1/notifications/webhooks-events/8PT597110X687430LKGECATA/resend' => Http::response($this->getApiResponse('simulate_webhook')), + ]); + + $webhookEvent = WebhookEvent::resend('8PT597110X687430LKGECATA'); + + $this->assertInstanceOf(WebhookEvent::class, $webhookEvent); + + $this->assertEquals('8PT597110X687430LKGECATA', $webhookEvent->id); + $this->assertEquals(Date::parse('2013-06-25T21:41:28Z'), $webhookEvent->create_time); + $this->assertEquals('authorization', $webhookEvent->resource_type); + $this->assertEquals('1.0', $webhookEvent->event_version); + $this->assertEquals(WebhookEventEnum::PAYMENT_AUTHORIZATION_CREATED, $webhookEvent->event_type); + $this->assertEquals('A payment authorization was created', $webhookEvent->summary); + $this->assertEquals('1.0', $webhookEvent->resource_version); + + $resource = $webhookEvent->resource; + + $this->assertEquals('2DC87612EK520411B', $resource->id); + $this->assertEquals(Date::parse('2013-06-25T21:39:15Z'), $resource->create_time); + $this->assertEquals(Date::parse('2013-06-25T21:39:17Z'), $resource->update_time); + $this->assertEquals('authorized', $resource->state); + $this->assertEquals('PAY-36246664YD343335CKHFA4AY', $resource->parent_payment); + $this->assertEquals(Date::parse('2013-07-24T21:39:15Z'), $resource->valid_until); + + $amount = $resource->amount; + + $this->assertEquals('USD', $amount->currency); + $this->assertEquals('7.47', $amount->total); + + $details = $amount->details; + + $this->assertEquals('7.47', $details->subtotal); + } + + public function testCanRetrieveEvent() { + Http::fake([ + 'https://api-m.paypal.com/v1/notifications/webhooks-events/8PT597110X687430LKGECATA' => Http::response($this->getApiResponse('simulate_webhook')), + ]); + + $webhookEvent = WebhookEvent::retrieve('8PT597110X687430LKGECATA'); + + $this->assertInstanceOf(WebhookEvent::class, $webhookEvent); + + $this->assertEquals('8PT597110X687430LKGECATA', $webhookEvent->id); + $this->assertEquals(Date::parse('2013-06-25T21:41:28Z'), $webhookEvent->create_time); + $this->assertEquals('authorization', $webhookEvent->resource_type); + $this->assertEquals('1.0', $webhookEvent->event_version); + $this->assertEquals(WebhookEventEnum::PAYMENT_AUTHORIZATION_CREATED, $webhookEvent->event_type); + $this->assertEquals('A payment authorization was created', $webhookEvent->summary); + $this->assertEquals('1.0', $webhookEvent->resource_version); + + $resource = $webhookEvent->resource; + + $this->assertEquals('2DC87612EK520411B', $resource->id); + $this->assertEquals(Date::parse('2013-06-25T21:39:15Z'), $resource->create_time); + $this->assertEquals(Date::parse('2013-06-25T21:39:17Z'), $resource->update_time); + $this->assertEquals('authorized', $resource->state); + $this->assertEquals('PAY-36246664YD343335CKHFA4AY', $resource->parent_payment); + $this->assertEquals(Date::parse('2013-07-24T21:39:15Z'), $resource->valid_until); + + $amount = $resource->amount; + + $this->assertEquals('USD', $amount->currency); + $this->assertEquals('7.47', $amount->total); + + $details = $amount->details; + + $this->assertEquals('7.47', $details->subtotal); + } + + public function testCanQueryEventList() { + Http::fake([ + 'https://api-m.paypal.com/v1/notifications/webhooks-events?page_size=10&start_time=2021-01-01T00%3A00%3A00Z&end_time=2021-01-31T23%3A59%3A59Z&transaction_id=8PT597110X687430LKGECATA&event_type=PAYMENT.AUTHORIZATION.CREATED' => Http::response($this->getApiResponse('list_event_notifications')), + ]); + + $events = WebhookEvent::query() + ->pageSize(10) + ->startTime(Date::parse('2021-01-01T00:00:00Z')) + ->endTime(Date::parse('2021-01-31T23:59:59Z')) + ->transactionId('8PT597110X687430LKGECATA') + ->eventType(WebhookEventEnum::PAYMENT_AUTHORIZATION_CREATED) + ->get(); + + $this->assertCount(2, $events->getEvents()); + + $this->assertTrue($events->hasNextPage()); + $this->assertTrue($events->hasPreviousPage()); + + } +} diff --git a/tests/Unit/Webhooks/Models/WebhookTest.php b/tests/Unit/Webhooks/Models/WebhookTest.php new file mode 100644 index 0000000..e2b96a8 --- /dev/null +++ b/tests/Unit/Webhooks/Models/WebhookTest.php @@ -0,0 +1,73 @@ + Http::response($this->getApiResponse('create_webhook')), + ]); + + $webhook = Webhook::builder() + ->setUrl('https://example.com/example_webhook') + ->setEvents( + [ + WebhookEventEnum::PAYMENT_AUTHORIZATION_CREATED, + WebhookEventEnum::PAYMENT_CAPTURE_COMPLETED, + ] + ) + ->create(); + + $this->assertEquals('https://example.com/example_webhook', $webhook->url); + $this->assertCount(2, $webhook->listEvents()); + } + + public function testListingWebhooks() { + Http::fake([ + 'https://api-m.paypal.com/v1/notifications/webhooks' => Http::response($this->getApiResponse('list_webhooks')), + ]); + + $webhooks = Webhook::all(); + + $this->assertCount(2, $webhooks); + $this->assertInstanceOf(Webhook::class, $webhooks->first()); + } + + public function testRetrievingWebhook() { + Http::fake([ + 'https://api-m.paypal.com/v1/notifications/webhooks/0EH40505U7160970P' => Http::response($this->getApiResponse('show_webhook_details')), + ]); + + $webhook = Webhook::retrieve('0EH40505U7160970P'); + + $this->assertEquals('https://example.com/example_webhook', $webhook->url); + $this->assertCount(3, $webhook->listEvents()); + + // get the first event + $event = $webhook->listEvents()->first(); + + $this->assertEquals(WebhookEventEnum::PAYMENT_AUTHORIZATION_CREATED, $event->name); + $this->assertEquals('A payment authorization was created.', $event->description); + $this->assertEquals('ENABLED', $event->status); + } + + public function testDeletingWebhook() { + Http::fake([ + 'https://api-m.paypal.com/v1/notifications/webhooks/0EH40505U7160970P' => Http::response($this->getApiResponse('show_webhook_details')), + + ]); + + $webhook = Webhook::retrieve('0EH40505U7160970P'); + + $webhook->delete(); + + Http::assertSentCount(2); + } +} diff --git a/tests/stubs/add_tracking_information_for_an_order.json b/tests/stubs/add_tracking_information_for_an_order.json old mode 100644 new mode 100755 diff --git a/tests/stubs/authorized.json b/tests/stubs/authorized.json old mode 100644 new mode 100755 diff --git a/tests/stubs/capture.json b/tests/stubs/capture.json old mode 100644 new mode 100755 diff --git a/tests/stubs/capture_refund.json b/tests/stubs/capture_refund.json old mode 100644 new mode 100755 diff --git a/tests/stubs/captured_order.json b/tests/stubs/captured_order.json old mode 100644 new mode 100755 diff --git a/tests/stubs/create_webhook.json b/tests/stubs/create_webhook.json new file mode 100644 index 0000000..76573d6 --- /dev/null +++ b/tests/stubs/create_webhook.json @@ -0,0 +1,31 @@ +{ + "id": "0EH40505U7160970P", + "url": "https://example.com/example_webhook", + "event_types": [ + { + "name": "PAYMENT.AUTHORIZATION.CREATED", + "description": "A payment authorization was created." + }, + { + "name": "PAYMENT.AUTHORIZATION.VOIDED", + "description": "A payment authorization was voided." + } + ], + "links": [ + { + "href": "https://api-m.paypal.com/v1/notifications/webhooks/0EH40505U7160970P", + "rel": "self", + "method": "GET" + }, + { + "href": "https://api-m.paypal.com/v1/notifications/webhooks/0EH40505U7160970P", + "rel": "update", + "method": "PATCH" + }, + { + "href": "https://api-m.paypal.com/v1/notifications/webhooks/0EH40505U7160970P", + "rel": "delete", + "method": "DELETE" + } + ] +} diff --git a/tests/stubs/invalid-client.json b/tests/stubs/invalid-client.json old mode 100644 new mode 100755 diff --git a/tests/stubs/invalid-request.json b/tests/stubs/invalid-request.json old mode 100644 new mode 100755 diff --git a/tests/stubs/list_event_notifications.json b/tests/stubs/list_event_notifications.json new file mode 100644 index 0000000..dbfa9dc --- /dev/null +++ b/tests/stubs/list_event_notifications.json @@ -0,0 +1,133 @@ +{ + "events": [ + { + "id": "8PT597110X687430LKGECATA", + "create_time": "2013-06-25T21:41:28Z", + "resource_type": "authorization", + "event_version": "1.0", + "event_type": "PAYMENT.AUTHORIZATION.CREATED", + "summary": "A payment authorization was created", + "resource_version": "1.0", + "resource": { + "id": "2DC87612EK520411B", + "create_time": "2013-06-25T21:39:15Z", + "update_time": "2013-06-25T21:39:17Z", + "state": "authorized", + "amount": { + "total": "7.47", + "currency": "USD", + "details": { + "subtotal": "7.47" + } + }, + "parent_payment": "PAY-36246664YD343335CKHFA4AY", + "valid_until": "2013-07-24T21:39:15Z", + "links": [ + { + "href": "https://api-m.paypal.com/v1/payments/authorization/2DC87612EK520411B", + "rel": "self", + "method": "GET" + }, + { + "href": "https://api-m.paypal.com/v1/payments/authorization/2DC87612EK520411B/capture", + "rel": "capture", + "method": "POST" + }, + { + "href": "https://api-m.paypal.com/v1/payments/authorization/2DC87612EK520411B/void", + "rel": "void", + "method": "POST" + }, + { + "href": "https://api-m.paypal.com/v1/payments/payment/PAY-36246664YD343335CKHFA4AY", + "rel": "parent_payment", + "method": "GET" + } + ] + }, + "links": [ + { + "href": "https://api-m.paypal.com/v1/notfications/webhooks-events/8PT597110X687430LKGECATA", + "rel": "self", + "method": "GET" + }, + { + "href": "https://api-m.paypal.com/v1/notfications/webhooks-events/8PT597110X687430LKGECATA/resend", + "rel": "resend", + "method": "POST" + } + ] + }, + { + "id": "HTSPGS710X687430LKGECATA", + "create_time": "2013-06-25T21:41:28Z", + "resource_type": "authorization", + "event_version": "1.0", + "event_type": "PAYMENT.AUTHORIZATION.CREATED", + "summary": "A payment authorization was created", + "resource_version": "1.0", + "resource": { + "id": "HATH7S72EK520411B", + "create_time": "2013-06-25T21:39:15Z", + "update_time": "2013-06-25T21:39:17Z", + "state": "authorized", + "amount": { + "total": "7.47", + "currency": "USD", + "details": { + "subtotal": "7.47" + } + }, + "parent_payment": "PAY-ALDSFJ64YD343335CKHFA4AY", + "valid_until": "2013-07-24T21:39:15Z", + "links": [ + { + "href": "https://api-m.paypal.com/v1/payments/authorization/HATH7S72EK520411B", + "rel": "self", + "method": "GET" + }, + { + "href": "https://api-m.paypal.com/v1/payments/authorization/HATH7S72EK520411B/capture", + "rel": "capture", + "method": "POST" + }, + { + "href": "https://api-m.paypal.com/v1/payments/authorization/HATH7S72EK520411B/void", + "rel": "void", + "method": "POST" + }, + { + "href": "https://api-m.paypal.com/v1/payments/payment/PAY-HATH7S72EK520411B", + "rel": "parent_payment", + "method": "GET" + } + ] + }, + "links": [ + { + "href": "https://api-m.paypal.com/v1/notfications/webhooks-events/HTSPGS710X687430LKGECATA", + "rel": "self", + "method": "GET" + }, + { + "href": "https://api-m.paypal.com/v1/notfications/webhooks-events/HTSPGS710X687430LKGECATA/resend", + "rel": "resend", + "method": "POST" + } + ] + } + ], + "count": 2, + "links": [ + { + "href": "https://api-m.paypal.com/v1/notifications/webhooks-events/?start_time=2014-08-04T12:46:47-07:00&end_time=2014-09-18T12:46:47-07:00&page_size=2&move_to=next&index_time=2014-09-17T23:07:35Z&index_id=3", + "rel": "next", + "method": "GET" + }, + { + "href": "https://api-m.paypal.com/v1/notifications/webhooks-events/?start_time=2014-08-04T12:46:47-07:00&end_time=2014-09-18T12:46:47-07:00&page_size=2&move_to=previous&index_time=2014-09-17T23:07:35Z&index_id=0", + "rel": "previous", + "method": "GET" + } + ] +} diff --git a/tests/stubs/list_event_subscriptions_for_webhook.json b/tests/stubs/list_event_subscriptions_for_webhook.json new file mode 100644 index 0000000..f9ebb96 --- /dev/null +++ b/tests/stubs/list_event_subscriptions_for_webhook.json @@ -0,0 +1,19 @@ +{ + "event_types": [ + { + "name": "PAYMENT.AUTHORIZATION.CREATED", + "description": "A payment authorization was created.", + "status": "ENABLED" + }, + { + "name": "PAYMENT.AUTHORIZATION.VOIDED", + "description": "A payment authorization was voided.", + "status": "ENABLED" + }, + { + "name": "RISK.DISPUTE.CREATED", + "description": "A dispute was filed against a transaction.", + "status": "DEPRECATED" + } + ] +} diff --git a/tests/stubs/list_webhooks.json b/tests/stubs/list_webhooks.json new file mode 100644 index 0000000..5422035 --- /dev/null +++ b/tests/stubs/list_webhooks.json @@ -0,0 +1,66 @@ +{ + "webhooks": [ + { + "id": "40Y916089Y8324740", + "url": "https://example.com/example_webhook", + "event_types": [ + { + "name": "PAYMENT.AUTHORIZATION.CREATED", + "description": "A payment authorization was created." + }, + { + "name": "PAYMENT.AUTHORIZATION.VOIDED", + "description": "A payment authorization was voided." + } + ], + "links": [ + { + "href": "https://api-m.paypal.com/v1/notifications/webhooks/40Y916089Y8324740", + "rel": "self", + "method": "GET" + }, + { + "href": "https://api-m.paypal.com/v1/notifications/webhooks/40Y916089Y8324740", + "rel": "update", + "method": "PATCH" + }, + { + "href": "https://api-m.paypal.com/v1/notifications/webhooks/40Y916089Y8324740", + "rel": "delete", + "method": "DELETE" + } + ] + }, + { + "id": "0EH40505U7160970P", + "url": "https://example.com/another_example_webhook", + "event_types": [ + { + "name": "PAYMENT.AUTHORIZATION.CREATED", + "description": "A payment authorization was created." + }, + { + "name": "PAYMENT.AUTHORIZATION.VOIDED", + "description": "A payment authorization was voided." + } + ], + "links": [ + { + "href": "https://api-m.paypal.com/v1/notifications/webhooks/0EH40505U7160970P", + "rel": "self", + "method": "GET" + }, + { + "href": "https://api-m.paypal.com/v1/notifications/webhooks/0EH40505U7160970P", + "rel": "update", + "method": "PATCH" + }, + { + "href": "https://api-m.paypal.com/v1/notifications/webhooks/0EH40505U7160970P", + "rel": "delete", + "method": "DELETE" + } + ] + } + ] +} diff --git a/tests/stubs/order_created.json b/tests/stubs/order_created.json old mode 100644 new mode 100755 diff --git a/tests/stubs/order_created_new.json b/tests/stubs/order_created_new.json old mode 100644 new mode 100755 diff --git a/tests/stubs/show_order.json b/tests/stubs/show_order.json old mode 100644 new mode 100755 diff --git a/tests/stubs/show_webhook_details.json b/tests/stubs/show_webhook_details.json new file mode 100644 index 0000000..8720434 --- /dev/null +++ b/tests/stubs/show_webhook_details.json @@ -0,0 +1,38 @@ +{ + "id": "0EH40505U7160970P", + "url": "https://example.com/example_webhook", + "event_types": [ + { + "name": "PAYMENT.AUTHORIZATION.CREATED", + "description": "A payment authorization was created.", + "status": "ENABLED" + }, + { + "name": "PAYMENT.AUTHORIZATION.VOIDED", + "description": "A payment authorization was voided.", + "status": "ENABLED" + }, + { + "name": "CHECKOUT.PAYMENT-APPROVAL.REVERSED", + "description": "A payment has been reversed after approval.", + "status": "ENABLED" + } + ], + "links": [ + { + "href": "https://api-m.paypal.com/v1/notifications/webhooks/0EH40505U7160970P", + "rel": "self", + "method": "GET" + }, + { + "href": "https://api-m.paypal.com/v1/notifications/webhooks/0EH40505U7160970P", + "rel": "update", + "method": "PATCH" + }, + { + "href": "https://api-m.paypal.com/v1/notifications/webhooks/0EH40505U7160970P", + "rel": "delete", + "method": "DELETE" + } + ] +} diff --git a/tests/stubs/simulate_webhook.json b/tests/stubs/simulate_webhook.json new file mode 100644 index 0000000..4ea4b14 --- /dev/null +++ b/tests/stubs/simulate_webhook.json @@ -0,0 +1,58 @@ +{ + "id": "8PT597110X687430LKGECATA", + "create_time": "2013-06-25T21:41:28Z", + "resource_type": "authorization", + "event_version": "1.0", + "event_type": "PAYMENT.AUTHORIZATION.CREATED", + "summary": "A payment authorization was created", + "resource_version": "1.0", + "resource": { + "id": "2DC87612EK520411B", + "create_time": "2013-06-25T21:39:15Z", + "update_time": "2013-06-25T21:39:17Z", + "state": "authorized", + "amount": { + "total": "7.47", + "currency": "USD", + "details": { + "subtotal": "7.47" + } + }, + "parent_payment": "PAY-36246664YD343335CKHFA4AY", + "valid_until": "2013-07-24T21:39:15Z", + "links": [ + { + "href": "https://api-m.paypal.com/v1/payments/authorization/2DC87612EK520411B", + "rel": "self", + "method": "GET" + }, + { + "href": "https://api-m.paypal.com/v1/payments/authorization/2DC87612EK520411B/capture", + "rel": "capture", + "method": "POST" + }, + { + "href": "https://api-m.paypal.com/v1/payments/authorization/2DC87612EK520411B/void", + "rel": "void", + "method": "POST" + }, + { + "href": "https://api-m.paypal.com/v1/payments/payment/PAY-36246664YD343335CKHFA4AY", + "rel": "parent_payment", + "method": "GET" + } + ] + }, + "links": [ + { + "href": "https://api-m.paypal.com/v1/notfications/webhooks-events/8PT597110X687430LKGECATA", + "rel": "self", + "method": "GET" + }, + { + "href": "https://api-m.paypal.com/v1/notfications/webhooks-events/8PT597110X687430LKGECATA/resend", + "rel": "resend", + "method": "POST" + } + ] +}