paddle-logging verbessert
This commit is contained in:
@@ -47,9 +47,11 @@ class PaddleWebhookControllerTest extends TestCase
|
||||
],
|
||||
];
|
||||
|
||||
$signature = hash_hmac('sha256', json_encode($payload), 'test_secret');
|
||||
$timestamp = time();
|
||||
$signature = hash_hmac('sha256', $timestamp.':'.json_encode($payload), 'test_secret');
|
||||
$header = sprintf('ts=%s,h1=%s', $timestamp, $signature);
|
||||
|
||||
$response = $this->withHeader('Paddle-Webhook-Signature', $signature)
|
||||
$response = $this->withHeader('Paddle-Signature', $header)
|
||||
->postJson('/paddle/webhook', $payload);
|
||||
|
||||
$response->assertOk()->assertJson(['status' => 'processed']);
|
||||
@@ -108,14 +110,16 @@ class PaddleWebhookControllerTest extends TestCase
|
||||
],
|
||||
];
|
||||
|
||||
$signature = hash_hmac('sha256', json_encode($payload), 'test_secret');
|
||||
$timestamp = time();
|
||||
$signature = hash_hmac('sha256', $timestamp.':'.json_encode($payload), 'test_secret');
|
||||
$header = sprintf('ts=%s,h1=%s', $timestamp, $signature);
|
||||
|
||||
$first = $this->withHeader('Paddle-Webhook-Signature', $signature)
|
||||
$first = $this->withHeader('Paddle-Signature', $header)
|
||||
->postJson('/paddle/webhook', $payload);
|
||||
|
||||
$first->assertOk()->assertJson(['status' => 'processed']);
|
||||
|
||||
$second = $this->withHeader('Paddle-Webhook-Signature', $signature)
|
||||
$second = $this->withHeader('Paddle-Signature', $header)
|
||||
->postJson('/paddle/webhook', $payload);
|
||||
|
||||
$second->assertStatus(200)->assertJson(['status' => 'processed']);
|
||||
@@ -168,9 +172,11 @@ class PaddleWebhookControllerTest extends TestCase
|
||||
],
|
||||
];
|
||||
|
||||
$signature = hash_hmac('sha256', json_encode($payload), 'test_secret');
|
||||
$timestamp = time();
|
||||
$signature = hash_hmac('sha256', $timestamp.':'.json_encode($payload), 'test_secret');
|
||||
$header = sprintf('ts=%s,h1=%s', $timestamp, $signature);
|
||||
|
||||
$response = $this->withHeader('Paddle-Webhook-Signature', $signature)
|
||||
$response = $this->withHeader('Paddle-Signature', $header)
|
||||
->postJson('/paddle/webhook', $payload);
|
||||
|
||||
$response->assertOk()->assertJson(['status' => 'processed']);
|
||||
@@ -185,7 +191,7 @@ class PaddleWebhookControllerTest extends TestCase
|
||||
{
|
||||
config(['paddle.webhook_secret' => 'secret']);
|
||||
|
||||
$response = $this->withHeader('Paddle-Webhook-Signature', 'invalid')
|
||||
$response = $this->withHeader('Paddle-Signature', 'invalid')
|
||||
->postJson('/paddle/webhook', ['event_type' => 'transaction.completed']);
|
||||
|
||||
$response->assertStatus(400)->assertJson(['status' => 'invalid']);
|
||||
|
||||
66
tests/Unit/PaddleTransactionServiceTest.php
Normal file
66
tests/Unit/PaddleTransactionServiceTest.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use App\Services\Paddle\PaddleClient;
|
||||
use App\Services\Paddle\PaddleTransactionService;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
|
||||
class PaddleTransactionServiceTest extends TestCase
|
||||
{
|
||||
public function test_list_for_customer_uses_expected_order_by_format(): void
|
||||
{
|
||||
$client = Mockery::mock(PaddleClient::class);
|
||||
$client->shouldReceive('get')
|
||||
->once()
|
||||
->with('/transactions', Mockery::on(function (array $payload) {
|
||||
return $payload['customer_id'] === 'ctm_123'
|
||||
&& $payload['order_by'] === 'created_at[desc]';
|
||||
}))
|
||||
->andReturn(['data' => [], 'meta' => ['pagination' => []]]);
|
||||
|
||||
$this->app->instance(PaddleClient::class, $client);
|
||||
|
||||
$service = $this->app->make(PaddleTransactionService::class);
|
||||
$service->listForCustomer('ctm_123');
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
public function test_find_by_checkout_id_uses_expected_order_by_format(): void
|
||||
{
|
||||
$client = Mockery::mock(PaddleClient::class);
|
||||
$client->shouldReceive('get')
|
||||
->once()
|
||||
->with('/transactions', Mockery::on(function (array $payload) {
|
||||
return $payload['checkout_id'] === 'chk_123'
|
||||
&& $payload['order_by'] === 'created_at[desc]';
|
||||
}))
|
||||
->andReturn(['data' => []]);
|
||||
|
||||
$this->app->instance(PaddleClient::class, $client);
|
||||
|
||||
$service = $this->app->make(PaddleTransactionService::class);
|
||||
$this->assertNull($service->findByCheckoutId('chk_123'));
|
||||
}
|
||||
|
||||
public function test_find_by_custom_data_uses_expected_order_by_format(): void
|
||||
{
|
||||
$client = Mockery::mock(PaddleClient::class);
|
||||
$client->shouldReceive('get')
|
||||
->once()
|
||||
->with('/transactions', Mockery::on(function (array $payload) {
|
||||
return $payload['order_by'] === 'created_at[desc]'
|
||||
&& $payload['per_page'] === 20;
|
||||
}))
|
||||
->andReturn(['data' => []]);
|
||||
|
||||
$this->app->instance(PaddleClient::class, $client);
|
||||
|
||||
$service = $this->app->make(PaddleTransactionService::class);
|
||||
$this->assertNull($service->findByCustomData([
|
||||
'checkout_session_id' => 'sess_123',
|
||||
]));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user