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 \ByTIC\Omnipay\Common\Message\Traits\SendDataRequestTrait; |
19
|
|
|
use HasModelRequest; |
|
|
|
|
20
|
|
|
use GatewayNotificationRequestTrait { |
|
|
|
|
21
|
|
|
getData as getDataNotificationTrait; |
22
|
|
|
} |
23
|
|
|
use HasGatewayRequestTrait; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @inheritdoc |
27
|
|
|
*/ |
28
|
|
|
public function getData(): array |
29
|
|
|
{ |
30
|
|
|
$return = $this->getDataNotificationTrait(); |
31
|
|
|
// Add model only if has data |
32
|
|
|
if (count($return)) { |
33
|
|
|
$return['model'] = $this->getModel(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
return $return; |
37
|
|
|
} |
38
|
|
|
/** |
39
|
|
|
* @return mixed |
40
|
|
|
*/ |
41
|
|
|
public function isValidNotification() |
42
|
|
|
{ |
43
|
|
|
return $this->hasGet('stpsid'); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return bool|mixed |
48
|
|
|
* @throws \Exception |
49
|
|
|
*/ |
50
|
|
|
protected function parseNotification() |
51
|
|
|
{ |
52
|
|
|
if ($this->validateModel()) { |
53
|
|
|
$model = $this->getModel(); |
54
|
|
|
$this->updateParametersFromPurchase($model); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
// Retrieve the session that would have been started earlier. |
58
|
|
|
\Stripe\Stripe::setApiKey($this->getApiKey()); |
59
|
|
|
|
60
|
|
|
$session = \Stripe\Checkout\Session::retrieve($this->httpRequest->query->get('stpsid')); |
61
|
|
|
$paymentIntent = \Stripe\PaymentIntent::retrieve($session->payment_intent); |
62
|
|
|
|
63
|
|
|
return [ |
64
|
|
|
'session' => $session, |
65
|
|
|
'paymentIntent' => $paymentIntent |
66
|
|
|
]; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param Gateway $modelGateway |
71
|
|
|
*/ |
72
|
|
|
protected function updateParametersFromGateway(Gateway $modelGateway) |
73
|
|
|
{ |
74
|
|
|
$this->setPublicKey($modelGateway->getPublicKey()); |
75
|
|
|
$this->setApiKey($modelGateway->getApiKey()); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|