Skip to content

Commit

Permalink
feat(checkout): add api
Browse files Browse the repository at this point in the history
  • Loading branch information
owenvoke committed Nov 3, 2021
1 parent 4db1297 commit b7a016d
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Navigation

- [Account API](account.md)
- [Checkout API](checkout.md)
- [Delivery API](delivery.md)
- [Event API](event.md)
- [Token API](token.md)
Expand Down
20 changes: 20 additions & 0 deletions docs/checkout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Checkout API

[Back to the navigation](README.md)

Allows interacting with the Checkout API.

### Get details for a specific checkout

```php
$response = $client->checkout()->show('pest-php-meetup-1-2021');
```

### Redeem a checkout

```php
$response = $client->checkout()->redeem(
'pest-php-meetup-1-2021',
$googleRecaptchaResponse
);
```
20 changes: 20 additions & 0 deletions src/Api/Checkout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace OwenVoke\POAP\Api;

class Checkout extends AbstractApi
{
public function show(string $slug): array
{
return $this->get("/checkouts/{$slug}");
}

public function redeem(string $slug, string $googleRecaptchaResponse): array
{
return $this->post("/checkouts/{$slug}/redeem", [
'gRecaptchaResponse' => $googleRecaptchaResponse,
]);
}
}
8 changes: 7 additions & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Http\Discovery\Psr17FactoryDiscovery;
use OwenVoke\POAP\Api\AbstractApi;
use OwenVoke\POAP\Api\Account;
use OwenVoke\POAP\Api\Checkout;
use OwenVoke\POAP\Api\Delivery;
use OwenVoke\POAP\Api\Event;
use OwenVoke\POAP\Api\Token;
Expand All @@ -24,7 +25,8 @@
/**
* @method Api\Account account()
* @method Api\Account accounts()
* @method Api\Delivery delivery()
* @method Api\Checkout checkout()
* @method Api\Checkout checkouts()
* @method Api\Delivery deliveries()
* @method Api\Event event()
* @method Api\Event events()
Expand Down Expand Up @@ -67,6 +69,10 @@ public function api(string $name): AbstractApi
case 'accounts':
return new Account($this);

case 'checkout':
case 'checkouts':
return new Checkout($this);

case 'delivery':
case 'deliveries':
return new Delivery($this);
Expand Down

0 comments on commit b7a016d

Please sign in to comment.