From 77482c134770c07968a1c9368e667315150f8735 Mon Sep 17 00:00:00 2001 From: BernhardBaumrock Date: Tue, 22 Oct 2024 17:45:29 +0200 Subject: [PATCH] fix: cache api client and update docs --- RockMollie.module.php | 6 ++++-- docs/readme.md | 7 +++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/RockMollie.module.php b/RockMollie.module.php index 52a432e..40ac2c8 100644 --- a/RockMollie.module.php +++ b/RockMollie.module.php @@ -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; } /** diff --git a/docs/readme.md b/docs/readme.md index 8472baa..b43c881 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -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); ```