Skip to content

Commit

Permalink
fix: cache api client and update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardBaumrock committed Oct 22, 2024
1 parent 43e85f1 commit 77482c1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 4 additions & 2 deletions RockMollie.module.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@
*/
class RockMollie extends WireData implements Module, ConfigurableModule
{
public $api = false;

/**
* Get mollie api instance
*/
public function api(): MollieApiClient
{
if ($this->api) return $this->api;
require_once("vendor/autoload.php");
$api = new \Mollie\Api\MollieApiClient();
$api->setApiKey($this->wire->config->mollieApiKey);
return $api;
$api->setApiKey(wire()->config->mollieApiKey);
return $this->api = $api;
}

/**
Expand Down
7 changes: 3 additions & 4 deletions docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ Docs are under construction 😇
## Create a simple payment

```php
$mollie = new \Mollie\Api\MollieApiClient();
$mollie->setApiKey('xxx');
$mollie = wire()->modules->get('RockMollie')->api();
$payment = $mollie->payments->create([
"amount" => [
"currency" => "EUR",
"value" => "10.00"
],
"description" => "My first API payment",
"redirectUrl" => "https://www.baumrock.com/thanks/",
"webhookUrl" => "https://www.baumrock.com/mollie-webhook/",
"redirectUrl" => "https://www.example.com/thanks/",
"webhookUrl" => "https://www.example.com/mollie-webhook/",
]);
db($payment);
```
Expand Down

0 comments on commit 77482c1

Please sign in to comment.