diff --git a/src/MollieLaravelHttpClientAdapter.php b/src/MollieLaravelHttpClientAdapter.php index 2b9a45c..6c790a0 100644 --- a/src/MollieLaravelHttpClientAdapter.php +++ b/src/MollieLaravelHttpClientAdapter.php @@ -13,8 +13,11 @@ class MollieLaravelHttpClientAdapter implements MollieHttpAdapterInterface public function send($httpMethod, $url, $headers, $httpBody): object { - $response = Http::withHeaders($headers) - ->withBody($httpBody, 'application/json') + $contentType = $headers['Content-Type'] ?? 'application/json'; + unset($headers['Content-Type']); + + $response = Http::withBody($httpBody, $contentType) + ->withHeaders($headers) ->send($httpMethod, $url); return $this->parseResponseBody($response); diff --git a/tests/Wrappers/MollieApiLaravelClientTest.php b/tests/Wrappers/MollieApiLaravelClientTest.php new file mode 100644 index 0000000..93060df --- /dev/null +++ b/tests/Wrappers/MollieApiLaravelClientTest.php @@ -0,0 +1,65 @@ +id = uniqid('tr_'); + $payment->redirectUrl = 'https://google.com/redirect'; + $payment->description = 'test'; + + Http::fake([ + 'https://api.mollie.com/*' => Http::response(json_encode($payment)) + ]); + + $client->setApiKey('test_nawruSyCR7UE84EhtVmMmDGdRswBqj'); + $returnedPayment = $client->payments->create([ + 'redirectUrl' => 'https://google.com/redirect', + 'description' => 'test', + 'amount' => [ + 'value' => '10.00', + 'currency' => 'EUR' + ] + ]); + + $this->assertEquals($payment->id, $returnedPayment->id); + $this->assertEquals($payment->redirectUrl, $returnedPayment->redirectUrl); + $this->assertEquals($payment->description, $returnedPayment->description); + } + + public function testGetRequest() + { + /** @var MollieApiClient $client */ + $client = app(MollieApiClient::class); + $payment = new Payment($client); + $payment->id = uniqid('tr_'); + $payment->redirectUrl = 'https://google.com/redirect'; + $payment->description = 'test'; + + Http::fake([ + 'https://api.mollie.com/v2/payments/' . $payment->id => Http::response(json_encode($payment)) + ]); + + $client->setApiKey('test_nawruSyCR7UE84EhtVmMmDGdRswBqj'); + $returnedPayment = $client->payments->get($payment->id); + + $this->assertEquals($payment->id, $returnedPayment->id); + $this->assertEquals($payment->redirectUrl, $returnedPayment->redirectUrl); + $this->assertEquals($payment->description, $returnedPayment->description); + } +}