Skip to content

Commit

Permalink
Merge pull request #213 from Skullbock/feature/fix-issue-v2.20
Browse files Browse the repository at this point in the history
fix issue with double headers
  • Loading branch information
sandervanhooft authored Dec 6, 2022
2 parents c491c95 + e209442 commit ab5a32d
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/MollieLaravelHttpClientAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
65 changes: 65 additions & 0 deletions tests/Wrappers/MollieApiLaravelClientTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace Mollie\Laravel\Tests\Wrappers;

use Illuminate\Support\Facades\Http;
use Mollie\Api\MollieApiClient;
use Mollie\Api\Resources\Payment;
use Mollie\Laravel\Tests\TestCase;
use Mollie\Laravel\Wrappers\MollieApiWrapper;

/**
* Class MollieApiWrapper
*/
class MollieApiLaravelClientTest extends TestCase
{

public function testPostRequest()
{
/** @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/*' => 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);
}
}

0 comments on commit ab5a32d

Please sign in to comment.