Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e88d50d
commit 4483f54
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
namespace StripeModule\PaymentMethod; | ||
|
||
use Cart; | ||
use PrestaShopException; | ||
use Stripe\Exception\ApiErrorException; | ||
use StripeModule\ExecutionResult; | ||
use StripeModule\PaymentMetadata; | ||
use StripeModule\PaymentMethod; | ||
|
||
class BlikMethod extends PaymentMethod | ||
{ | ||
const METHOD_ID = 'blik'; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getMethodId(): string | ||
{ | ||
return static::METHOD_ID; | ||
} | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
protected function getAllowedCurrencies(): array | ||
{ | ||
return [ 'PLN' ]; | ||
} | ||
|
||
|
||
/** | ||
* @return array|string[] | ||
*/ | ||
protected function getAllowedAccountCountries(): array | ||
{ | ||
return static::ALL; | ||
} | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
protected function getAllowedCustomerCountries(): array | ||
{ | ||
return static::ALL; | ||
} | ||
|
||
/** | ||
* @param Cart $cart | ||
* | ||
* @return ExecutionResult | ||
* @throws PrestaShopException | ||
*/ | ||
public function executeMethod(Cart $cart): ExecutionResult | ||
{ | ||
try { | ||
$api = $this->getStripeApi(); | ||
$session = $api->createCheckoutSession( | ||
$cart, | ||
$this->getMethodId(), | ||
[\Stripe\PaymentMethod::TYPE_BLIK], | ||
[] | ||
); | ||
$metadata = PaymentMetadata::createForSession($this->getMethodId(), $cart, $session); | ||
return ExecutionResult::redirect($metadata, $session->url); | ||
} catch (ApiErrorException $e) { | ||
return $this->handleApiException($e); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getName(): string | ||
{ | ||
return $this->l('Blik', 'stripe'); | ||
} | ||
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.