Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update with get mandate method #14

Merged
merged 5 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/Pay/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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
Expand Down
16 changes: 15 additions & 1 deletion src/Pay/Adapter/Stripe.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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
Expand All @@ -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);
Expand Down
32 changes: 32 additions & 0 deletions src/Pay/Pay.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}
6 changes: 3 additions & 3 deletions tests/Pay/Adapter/StripeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Loading