Skip to content

Commit 782312d

Browse files
Merge pull request #14 from utopia-php/feat-get-mandate-details
update with get mandate method
2 parents 4032deb + 4647808 commit 782312d

4 files changed

Lines changed: 66 additions & 4 deletions

File tree

src/Pay/Adapter.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,14 @@ abstract public function createFuturePayment(string $customerId, ?string $paymen
158158
*/
159159
abstract public function listFuturePayments(?string $customerId = null, ?string $paymentMethodId = null): array;
160160

161+
/**
162+
* Get Future payment
163+
*
164+
* @param string $id
165+
* @return array
166+
*/
167+
abstract public function getFuturePayment(string $id): array;
168+
161169
/**
162170
* Update future payment setup
163171
*
@@ -170,6 +178,14 @@ abstract public function listFuturePayments(?string $customerId = null, ?string
170178
*/
171179
abstract public function updateFuturePayment(string $id, ?string $customerId = null, ?string $paymentMethod = null, array $paymentMethodOptions = [], ?string $paymentMethodConfiguration = null): array;
172180

181+
/**
182+
* Get mandate
183+
*
184+
* @param string $id
185+
* @return array
186+
*/
187+
abstract public function getMandate(string $id): array;
188+
173189
/**
174190
* Call
175191
* Make a request

src/Pay/Adapter/Stripe.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,13 @@ public function createFuturePayment(string $customerId, ?string $paymentMethod =
258258
return $result;
259259
}
260260

261+
public function getFuturePayment(string $id): array
262+
{
263+
$path = '/setup_intents/'.$id;
264+
265+
return $this->execute(self::METHOD_GET, $path);
266+
}
267+
261268
public function listFuturePayments(?string $customerId = null, ?string $pyamentMethodId = null): array
262269
{
263270
$path = '/setup_intents';
@@ -271,7 +278,7 @@ public function listFuturePayments(?string $customerId = null, ?string $pyamentM
271278
}
272279
$result = $this->execute(self::METHOD_GET, $path, $requestBody);
273280

274-
return $result;
281+
return $result['data'];
275282
}
276283

277284
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
294301
return $this->execute(self::METHOD_POST, $path, $requestBody);
295302
}
296303

304+
public function getMandate(string $id): array
305+
{
306+
$path = '/mandates/'.$id;
307+
308+
return $this->execute(self::METHOD_GET, $path);
309+
}
310+
297311
private function execute(string $method, string $path, array $requestBody = [], array $headers = []): array
298312
{
299313
$headers = array_merge(['content-type' => 'application/x-www-form-urlencoded', 'Authorization' => 'Bearer '.$this->secretKey], $headers);

src/Pay/Pay.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,27 @@ public function createFuturePayment(string $customerId, ?string $paymentMethod =
253253
return $this->adapter->createFuturePayment($customerId, $paymentMethod, $paymentMethodTypes, $paymentMethodOptions, $paymentMethodConfiguration);
254254
}
255255

256+
/**
257+
* Get future payment
258+
*
259+
* @param string $id
260+
* @return array
261+
*/
262+
public function getFuturePayment(string $id): array
263+
{
264+
return $this->adapter->getFuturePayment($id);
265+
}
266+
267+
/**
268+
* Update Future payment
269+
*
270+
* @param string $id
271+
* @param string|null $customerId
272+
* @param string|null $paymentMethod
273+
* @param array $paymentMethodOptions
274+
* @param string|null $paymentMethodConfiguration
275+
* @return array
276+
*/
256277
public function updateFuturePayment(string $id, ?string $customerId = null, ?string $paymentMethod = null, array $paymentMethodOptions = [], ?string $paymentMethodConfiguration = null): array
257278
{
258279
return $this->adapter->updateFuturePayment($id, $customerId, $paymentMethod, $paymentMethodOptions, $paymentMethodConfiguration);
@@ -269,4 +290,15 @@ public function listFuturePayment(?string $customerId, ?string $paymentMethodId
269290
{
270291
return $this->adapter->listFuturePayments($customerId, $paymentMethodId);
271292
}
293+
294+
/**
295+
* Get mandate
296+
*
297+
* @param string $id
298+
* @return array
299+
*/
300+
public function getMandate(string $id): array
301+
{
302+
return $this->adapter->getMandate($id);
303+
}
272304
}

tests/Pay/Adapter/StripeTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,9 @@ public function testListFuturePayment(array $data)
198198
$setupIntentId = $data['setupIntentId'];
199199

200200
$setupIntents = $this->stripe->listFuturePayments($customerId);
201-
$this->assertNotEmpty($setupIntents['data'] ?? []);
202-
$this->assertCount(1, $setupIntents['data'] ?? []);
203-
$this->assertEquals($setupIntentId, $setupIntents['data'][0]['id']);
201+
$this->assertNotEmpty($setupIntents);
202+
$this->assertCount(1, $setupIntents);
203+
$this->assertEquals($setupIntentId, $setupIntents[0]['id']);
204204
}
205205

206206
/** @depends testCreatePaymentMethod */

0 commit comments

Comments
 (0)