added beads and fixes for paddle checkout
This commit is contained in:
@@ -33,6 +33,87 @@ class PaddleTransactionService
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function retrieve(string $transactionId): array
|
||||
{
|
||||
$response = $this->client->get("/transactions/{$transactionId}");
|
||||
$transaction = Arr::get($response, 'data');
|
||||
|
||||
return is_array($transaction) ? $transaction : (is_array($response) ? $response : []);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
public function findByCheckoutId(string $checkoutId): ?array
|
||||
{
|
||||
$response = $this->client->get('/transactions', [
|
||||
'checkout_id' => $checkoutId,
|
||||
'order_by' => '-created_at',
|
||||
]);
|
||||
|
||||
$transactions = Arr::get($response, 'data', []);
|
||||
|
||||
if (! is_array($transactions) || $transactions === []) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$first = $transactions[0] ?? null;
|
||||
|
||||
return is_array($first) ? $first : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, string|int|null> $criteria
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
public function findByCustomData(array $criteria, int $limit = 20): ?array
|
||||
{
|
||||
$payload = array_filter([
|
||||
'order_by' => '-created_at',
|
||||
'per_page' => max(1, min($limit, 50)),
|
||||
], static fn ($value) => $value !== null && $value !== '');
|
||||
|
||||
$response = $this->client->get('/transactions', $payload);
|
||||
$transactions = Arr::get($response, 'data', []);
|
||||
|
||||
if (! is_array($transactions) || $transactions === []) {
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach ($transactions as $transaction) {
|
||||
if (! is_array($transaction)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$customData = Arr::get($transaction, 'custom_data', Arr::get($transaction, 'customData', []));
|
||||
if (! is_array($customData) || $customData === []) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$matches = true;
|
||||
foreach ($criteria as $key => $value) {
|
||||
if ($value === null || $value === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$candidate = $customData[$key] ?? null;
|
||||
if ((string) $candidate !== (string) $value) {
|
||||
$matches = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($matches) {
|
||||
return $transaction;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Issue a refund for a Paddle transaction.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user