diff --git a/src/Pay/Adapter.php b/src/Pay/Adapter.php index 62b3956..a8b63da 100644 --- a/src/Pay/Adapter.php +++ b/src/Pay/Adapter.php @@ -158,6 +158,14 @@ abstract public function createFuturePayment(string $customerId, ?string $paymen */ abstract public function listFuturePayments(?string $customerId = null, ?string $paymentMethodId = null): array; + /** + * Get Future payment + * + * @param string $id + * @return array + */ + abstract public function getFuturePayment(string $id): array; + /** * Update future payment setup * @@ -170,6 +178,14 @@ abstract public function listFuturePayments(?string $customerId = null, ?string */ abstract public function updateFuturePayment(string $id, ?string $customerId = null, ?string $paymentMethod = null, array $paymentMethodOptions = [], ?string $paymentMethodConfiguration = null): array; + /** + * Get mandate + * + * @param string $id + * @return array + */ + abstract public function getMandate(string $id): array; + /** * Call * Make a request diff --git a/src/Pay/Adapter/Stripe.php b/src/Pay/Adapter/Stripe.php index 363f092..0f01e85 100644 --- a/src/Pay/Adapter/Stripe.php +++ b/src/Pay/Adapter/Stripe.php @@ -258,6 +258,13 @@ public function createFuturePayment(string $customerId, ?string $paymentMethod = return $result; } + public function getFuturePayment(string $id): array + { + $path = '/setup_intents/'.$id; + + return $this->execute(self::METHOD_GET, $path); + } + public function listFuturePayments(?string $customerId = null, ?string $pyamentMethodId = null): array { $path = '/setup_intents'; @@ -271,7 +278,7 @@ public function listFuturePayments(?string $customerId = null, ?string $pyamentM } $result = $this->execute(self::METHOD_GET, $path, $requestBody); - return $result; + return $result['data']; } public function updateFuturePayment(string $id, ?string $customerId = null, ?string $paymentMethod = null, array $paymentMethodOptions = [], ?string $paymentMethodConfiguration = null): array @@ -294,6 +301,13 @@ public function updateFuturePayment(string $id, ?string $customerId = null, ?str return $this->execute(self::METHOD_POST, $path, $requestBody); } + public function getMandate(string $id): array + { + $path = '/mandates/'.$id; + + return $this->execute(self::METHOD_GET, $path); + } + private function execute(string $method, string $path, array $requestBody = [], array $headers = []): array { $headers = array_merge(['content-type' => 'application/x-www-form-urlencoded', 'Authorization' => 'Bearer '.$this->secretKey], $headers); diff --git a/src/Pay/Pay.php b/src/Pay/Pay.php index 89d1a66..c792a34 100644 --- a/src/Pay/Pay.php +++ b/src/Pay/Pay.php @@ -253,6 +253,27 @@ public function createFuturePayment(string $customerId, ?string $paymentMethod = return $this->adapter->createFuturePayment($customerId, $paymentMethod, $paymentMethodTypes, $paymentMethodOptions, $paymentMethodConfiguration); } + /** + * Get future payment + * + * @param string $id + * @return array + */ + public function getFuturePayment(string $id): array + { + return $this->adapter->getFuturePayment($id); + } + + /** + * Update Future payment + * + * @param string $id + * @param string|null $customerId + * @param string|null $paymentMethod + * @param array $paymentMethodOptions + * @param string|null $paymentMethodConfiguration + * @return array + */ public function updateFuturePayment(string $id, ?string $customerId = null, ?string $paymentMethod = null, array $paymentMethodOptions = [], ?string $paymentMethodConfiguration = null): array { return $this->adapter->updateFuturePayment($id, $customerId, $paymentMethod, $paymentMethodOptions, $paymentMethodConfiguration); @@ -269,4 +290,15 @@ public function listFuturePayment(?string $customerId, ?string $paymentMethodId { return $this->adapter->listFuturePayments($customerId, $paymentMethodId); } + + /** + * Get mandate + * + * @param string $id + * @return array + */ + public function getMandate(string $id): array + { + return $this->adapter->getMandate($id); + } } diff --git a/tests/Pay/Adapter/StripeTest.php b/tests/Pay/Adapter/StripeTest.php index 4af59c1..0796b5c 100644 --- a/tests/Pay/Adapter/StripeTest.php +++ b/tests/Pay/Adapter/StripeTest.php @@ -198,9 +198,9 @@ public function testListFuturePayment(array $data) $setupIntentId = $data['setupIntentId']; $setupIntents = $this->stripe->listFuturePayments($customerId); - $this->assertNotEmpty($setupIntents['data'] ?? []); - $this->assertCount(1, $setupIntents['data'] ?? []); - $this->assertEquals($setupIntentId, $setupIntents['data'][0]['id']); + $this->assertNotEmpty($setupIntents); + $this->assertCount(1, $setupIntents); + $this->assertEquals($setupIntentId, $setupIntents[0]['id']); } /** @depends testCreatePaymentMethod */