Skip to content

Commit

Permalink
Merge pull request #18 from utopia-php/feat-payment-intent
Browse files Browse the repository at this point in the history
Feat: get payment details
  • Loading branch information
christyjacob4 authored Aug 26, 2024
2 parents 3f09fe6 + 1ca173c commit 705ce9e
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Pay/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ abstract public function purchase(int $amount, string $customerId, ?string $paym
*/
abstract public function refund(string $paymentId, int $amount = null, string $reason = null): array;

/**
* Get a payment details
*
* @param string $paymentId
* @return array<mixed>
*/
abstract public function getPayment(string $paymentId): array;

/**
* Add a payment method
*
Expand Down
13 changes: 13 additions & 0 deletions src/Pay/Adapter/Stripe.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@ public function refund(string $paymentId, int $amount = null, string $reason = n
return $this->execute(self::METHOD_POST, $path, $requestBody);
}

/**
* Get a payment details
*
* @param string $paymentId
* @return array<mixed>
*/
public function getPayment(string $paymentId): array
{
$path = '/payment_intents/'.$paymentId;

return $this->execute(self::METHOD_GET, $path);
}

/**
* Add a credit card for customer
*/
Expand Down
11 changes: 11 additions & 0 deletions src/Pay/Pay.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,17 @@ public function refund(string $paymentId, int $amount): array
return $this->adapter->refund($paymentId, $amount);
}

/**
* Get a payment details
*
* @param string $paymentId
* @return array<mixed>
*/
public function getPayment(string $paymentId): array
{
return $this->adapter->getPayment($paymentId);
}

/**
* Delete Payment Method
*
Expand Down
15 changes: 15 additions & 0 deletions tests/Pay/Adapter/StripeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,21 @@ public function testPurchase(array $data): array
return $data;
}

/**
* @depends testPurchase
*/
public function testGetPayment(array $data): array
{
$paymentId = $data['paymentId'];
$payment = $this->stripe->getPayment($paymentId);
$this->assertNotEmpty($payment['id']);
$this->assertEquals(5000, $payment['amount_received']);
$this->assertEquals('payment_intent', $payment['object']);
$this->assertEquals('succeeded', $payment['status']);

return $data;
}

/**
* @depends testPurchase
*
Expand Down

0 comments on commit 705ce9e

Please sign in to comment.