Skip to content

Commit d806411

Browse files
committed
implemented the new paystack subscription statuses
1 parent 45241ed commit d806411

File tree

8 files changed

+262
-258
lines changed

8 files changed

+262
-258
lines changed

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
<env name="PAYSTACK_TRANSACTION_REF" value="abcf12345679" />
3535
<env name="PAYSTACK_TRANSACTION_REF_INVALID" value="Tref3456869" />
3636
<env name="PAYSTACK_CUSTOMER" value="CUS_abcdefgh123" />
37-
<env name="PAYSTACK_CUSTOMER" value="CUS_123abcdefgh123" />
37+
<env name="PAYSTACK_OTHER_CUSTOMER" value="CUS_123abcdefgh123" />
3838
<env name="DB_CONNECTION" value="testing"/>
3939
</php>
4040
</phpunit>

src/Payment.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
use Digikraaft\Paystack\Paystack;
77
use Digikraaft\Paystack\Transaction;
8+
use GuzzleHttp\Exception\ClientException;
89

910
class Payment
1011
{
@@ -17,11 +18,15 @@ class Payment
1718
public static function hasValidTransaction(string $trandactionRef)
1819
{
1920
Paystack::setApiKey(config('paystacksubscription.secret', env('PAYSTACK_SECRET')));
20-
$transaction = Transaction::verify($trandactionRef);
21-
if ($transaction->status && $transaction->data->status == 'success') {
22-
return $transaction;
23-
}
2421

22+
try {
23+
$transaction = Transaction::verify($trandactionRef);
24+
if ($transaction->status && $transaction->data->status == 'success') {
25+
return $transaction;
26+
}
27+
} catch (ClientException $exception) {
28+
return false;
29+
}
2530
return false;
2631
}
2732
}

src/PaystackSubscription.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
class PaystackSubscription
66
{
7+
const CANCELLED_STATUS = 'cancelled';
8+
const ACTIVE_STATUS = 'active';
9+
const COMPLETED_STATUS = 'complete';
10+
711
/**
812
* Get the billable entity instance by Paystack ID.
913
*

0 commit comments

Comments
 (0)