| 1 | <?php |
||
| 2 | |||
| 3 | namespace ByTIC\Payments\Stripe\Message; |
||
| 4 | |||
| 5 | use ByTIC\Omnipay\Common\Message\Traits\GatewayNotificationRequestTrait; |
||
| 6 | use ByTIC\Payments\Gateways\Providers\AbstractGateway\Message\Traits\HasGatewayRequestTrait; |
||
| 7 | use ByTIC\Payments\Gateways\Providers\AbstractGateway\Message\Traits\HasModelRequest; |
||
| 8 | use ByTIC\Payments\Stripe\Gateway; |
||
| 9 | |||
| 10 | /** |
||
| 11 | * Class PurchaseResponse |
||
| 12 | * @package ByTIC\Payments\Gateways\Providers\Paylike\Message |
||
| 13 | * |
||
| 14 | * @method CompletePurchaseResponse send |
||
| 15 | */ |
||
| 16 | class CompletePurchaseRequest extends AbstractCheckoutRequest |
||
| 17 | { |
||
| 18 | use Traits\HasKeysTrait; |
||
| 19 | use \ByTIC\Omnipay\Common\Message\Traits\SendDataRequestTrait; |
||
| 20 | use HasModelRequest; |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 21 | use GatewayNotificationRequestTrait { |
||
|
0 ignored issues
–
show
|
|||
| 22 | getData as getDataNotificationTrait; |
||
| 23 | } |
||
| 24 | use HasGatewayRequestTrait; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @inheritdoc |
||
| 28 | */ |
||
| 29 | public function getData(): array |
||
| 30 | { |
||
| 31 | $return = $this->getDataNotificationTrait(); |
||
| 32 | // Add model only if has data |
||
| 33 | if (count($return)) { |
||
| 34 | $return['model'] = $this->getModel(); |
||
| 35 | } |
||
| 36 | |||
| 37 | return $return; |
||
| 38 | } |
||
| 39 | /** |
||
| 40 | * @return mixed |
||
| 41 | */ |
||
| 42 | public function isValidNotification() |
||
| 43 | { |
||
| 44 | return $this->hasGet('stpsid'); |
||
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @return bool|mixed |
||
| 49 | * @throws \Exception |
||
| 50 | */ |
||
| 51 | protected function parseNotification() |
||
| 52 | { |
||
| 53 | if ($this->validateModel()) { |
||
| 54 | $model = $this->getModel(); |
||
| 55 | $this->updateParametersFromPurchase($model); |
||
| 56 | } |
||
| 57 | |||
| 58 | // Retrieve the session that would have been started earlier. |
||
| 59 | \Stripe\Stripe::setApiKey($this->getApiKey()); |
||
| 60 | |||
| 61 | $session = \Stripe\Checkout\Session::retrieve($this->httpRequest->query->get('stpsid')); |
||
| 62 | $paymentIntent = \Stripe\PaymentIntent::retrieve($session->payment_intent); |
||
| 63 | |||
| 64 | return [ |
||
| 65 | 'session' => $session, |
||
| 66 | 'paymentIntent' => $paymentIntent |
||
| 67 | ]; |
||
| 68 | } |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @param Gateway $modelGateway |
||
| 72 | */ |
||
| 73 | protected function updateParametersFromGateway(Gateway $modelGateway) |
||
| 74 | { |
||
| 75 | $this->setPublicKey($modelGateway->getPublicKey()); |
||
| 76 | $this->setApiKey($modelGateway->getApiKey()); |
||
| 77 | } |
||
| 78 | } |
||
| 79 |