#How to capture MollieApiClient requests in Laravel.
1 messages · Page 1 of 1 (latest)
@wicked quartz
Here a snippet of my test:
<?php
namespace Pixelpillow\LunarMollie\Tests\Unit\Managers;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Http;
use Mollie\Api\MollieApiClient;
use Mollie\Api\Resources\Payment;
use Pixelpillow\LunarMollie\Actions\SetPaymentIssuerOnCart;
use Pixelpillow\LunarMollie\Managers\MollieManager;
use Pixelpillow\LunarMollie\Tests\TestCase;
use Pixelpillow\LunarMollie\Tests\Utils\CartBuilder;
class MollieManagerTest extends TestCase
{
use RefreshDatabase;
/**
* @var \GuzzleHttp\Client
*/
protected $guzzleClient;
/**
* @var MollieManager
*/
protected $mollieManager;
/**
* @var MollieApiClient
*/
protected $mollieApiClient;
public function setUp(): void
{
parent::setUp();
$this->guzzleClient = resolve(\GuzzleHttp\Client::class);
$this->mollieManager = new MollieManager($this->guzzleClient);
$this->mollieApiClient = app(MollieApiClient::class);
}
public function test_payment_intent_is_created()
{
$cart = CartBuilder::build();
$payment_issuer = 'ideal_ABNANL2A';
App::make(SetPaymentIssuerOnCart::class)($cart, $payment_issuer);
$payment = new Payment($this->mollieApiClient);
$payment->id = uniqid('tr_');
Http::fake([
'https://api.mollie.com/*' => Http::response(json_encode($payment)),
]);
$this->mollieManager->createIntent($cart->calculate());
$this->assertEquals(
$cart->refresh()->meta->payment_intent,
$payment->id
);
}
}
Hi @lucid mist good to hear Lunar is getting some love!
🙂
Are you using mollie-api-php or laravel-mollie?
the mollie-api-php
Ok. So the Laravel HTTP fake facade you’re using is available on laravel-mollie. On mollie-api-php, you’d need to use a mocked Guzzle adapter. Which one do you prefer?
Ah I'am mixing code now
I prefer the mollie-api-php so I need to create a mocked Guzzle adapter and use that one in my mollie manager
Great. I am diving in a bit to see what’s easiest for this case and see if I have an example
I would love to use the Http::fake functions of laravel 😏
I may need to switch to the Laravel-Mollie package, but this feels a bit excessive.
Ok, so what laravel-mollie does is injecting an adapter into mollie-api-php's client, so you can use the Http facade. You could grab that adapter and use it without laravel-mollie
Would that be a solution for you?
Hmm let me try
Client instantiation then becomes
$mollie = new MollieApiClient(new MollieLaravelHttpClientAdapter);
Feel free to tag me here if you need more help. And tell Lunar's Glenn Jacobs I said hi!
@wicked quartz Thanks yeah this is the way! Dank je wel!
Great, enjoy! 🚀
Thanks Sander!
Do Mollie's payment providers for Ideal have capture modes like manual and automatic, like Stripe does? Or is Ideal always direct and automatic?
iDEAL is a guaranteed method. So it's captured directly 🙂
Oke 🙂
This can’t be a coincidence, I just was looking into lunar for a pet project and was looking for a mollie integration 🙂
🎉
Hi @wicked quartz, are you willing to review my Lunar-Mollie payment provider when it's ready?
Hi @lucid mist , sure, though you may have to walk me through some Lunar specifics 🙂