| 1 | <?php |
||
| 2 | |||
| 3 | namespace ByTIC\Payments\Stripe\Message; |
||
| 4 | |||
| 5 | use ByTIC\Omnipay\Common\Message\Traits\HtmlResponses\ConfirmHtmlTrait; |
||
| 6 | use Omnipay\Common\Message\AbstractResponse; |
||
| 7 | use ByTIC\Payments\Gateways\Providers\AbstractGateway\Message\Traits\CompletePurchaseResponseTrait; |
||
| 8 | use Stripe\PaymentIntent; |
||
| 9 | |||
| 10 | /** |
||
| 11 | * Class CompletePurchaseResponse |
||
| 12 | * @package ByTIC\Payments\Gateways\Providers\Paylike\Message |
||
| 13 | */ |
||
| 14 | class CompletePurchaseResponse extends AbstractResponse |
||
| 15 | { |
||
| 16 | use ConfirmHtmlTrait; |
||
| 17 | use CompletePurchaseResponseTrait; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @var bool |
||
| 21 | */ |
||
| 22 | private $successful = false; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @inheritDoc |
||
| 26 | */ |
||
| 27 | public function __construct(CompletePurchaseRequest $request, $data) |
||
| 28 | { |
||
| 29 | parent::__construct($request, $data); |
||
| 30 | |||
| 31 | if (isset($data['notification']['paymentIntent'])) { |
||
| 32 | /** @var \Stripe\PaymentIntent $paymentIntent */ |
||
| 33 | $paymentIntent = $data['notification']['paymentIntent']; |
||
| 34 | |||
| 35 | $this->internalTransactionRef = $paymentIntent->id; |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 36 | |||
| 37 | // Amazingly there doesn't seem to be a simple code nor message when the payment succeeds (or fails). |
||
| 38 | // For now, just use the status for the message, and leave the code blank. |
||
| 39 | switch ($paymentIntent->status) { |
||
| 40 | case PaymentIntent::STATUS_SUCCEEDED: |
||
| 41 | $this->successful = true; |
||
| 42 | $this->message = $paymentIntent->status; |
||
|
0 ignored issues
–
show
|
|||
| 43 | break; |
||
| 44 | case PaymentIntent::STATUS_CANCELED: |
||
| 45 | $this->successful = false; |
||
| 46 | $this->message = 'Canceled by customer'; |
||
| 47 | break; |
||
| 48 | default: |
||
| 49 | // We don't know what happened, so act accordingly. Would be nice to make this better over time. |
||
| 50 | $this->successful = false; |
||
| 51 | $this->message = 'Unknown error'; |
||
| 52 | break; |
||
| 53 | |||
| 54 | } |
||
| 55 | } else { |
||
| 56 | $this->successful = false; // Just make sure. |
||
| 57 | $this->message = 'Could not retrieve payment'; |
||
| 58 | } |
||
| 59 | } |
||
| 60 | |||
| 61 | public function isSuccessful() |
||
| 62 | { |
||
| 63 | return $this->successful; |
||
| 64 | } |
||
| 65 | |||
| 66 | public function getMessage() |
||
| 67 | { |
||
| 68 | return $this->message; |
||
| 69 | } |
||
| 70 | |||
| 71 | public function getCode() |
||
| 72 | { |
||
| 73 | return $this->code; |
||
|
0 ignored issues
–
show
|
|||
| 74 | } |
||
| 75 | |||
| 76 | |||
| 77 | /** @noinspection PhpMissingParentCallCommonInspection |
||
| 78 | * @return bool |
||
| 79 | */ |
||
| 80 | protected function canProcessModel() |
||
| 81 | { |
||
| 82 | return true; |
||
| 83 | } |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @return [] |
||
|
0 ignored issues
–
show
|
|||
| 87 | */ |
||
| 88 | public function getSessionDebug(): array |
||
| 89 | { |
||
| 90 | $notification = $this->getDataProperty('notification'); |
||
| 91 | return [ |
||
| 92 | 'session' => $notification['session']->toArray(), |
||
| 93 | 'paymentIntent' => $notification['paymentIntent']->toArray() |
||
| 94 | ]; |
||
| 95 | } |
||
| 96 | } |
||
| 97 |