|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Stripe Payment Intents Response. |
| 5 | + */ |
| 6 | + |
| 7 | +namespace Omnipay\Stripe\Message\SetupIntents; |
| 8 | + |
| 9 | +use Omnipay\Common\Message\ResponseInterface; |
| 10 | +use Omnipay\Stripe\Message\Response as BaseResponse; |
| 11 | + |
| 12 | +/** |
| 13 | + * Stripe Payment Intents Response. |
| 14 | + * |
| 15 | + * This is the response class for all payment intents related responses. |
| 16 | + * |
| 17 | + * @see \Omnipay\Stripe\PaymentIntentsGateway |
| 18 | + */ |
| 19 | +class Response extends BaseResponse implements ResponseInterface |
| 20 | +{ |
| 21 | + /** |
| 22 | + * Get the status of a payment intents response. |
| 23 | + * |
| 24 | + * @return string|null |
| 25 | + */ |
| 26 | + public function getStatus() |
| 27 | + { |
| 28 | + if (isset($this->data['object']) && 'setup_intent' === $this->data['object']) { |
| 29 | + return $this->data['status']; |
| 30 | + } |
| 31 | + |
| 32 | + return null; |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * Return true if the payment intent requires confirmation. |
| 37 | + * |
| 38 | + * @return bool |
| 39 | + */ |
| 40 | + public function requiresConfirmation() |
| 41 | + { |
| 42 | + return $this->getStatus() === 'requires_confirmation'; |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * @inheritdoc |
| 47 | + */ |
| 48 | + public function getClientSecret() |
| 49 | + { |
| 50 | + if (isset($this->data['object']) && 'setup_intent' === $this->data['object']) { |
| 51 | + if (!empty($this->data['client_secret'])) { |
| 52 | + return $this->data['client_secret']; |
| 53 | + } |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * @inheritdoc |
| 59 | + */ |
| 60 | + public function getCustomerReference() |
| 61 | + { |
| 62 | + |
| 63 | + if (isset($this->data['object']) && 'setup_intent' === $this->data['object']) { |
| 64 | + if (!empty($this->data['customer'])) { |
| 65 | + return $this->data['customer']; |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + return parent::getCustomerReference(); |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * @inheritdoc |
| 74 | + */ |
| 75 | + public function isSuccessful() |
| 76 | + { |
| 77 | + if (isset($this->data['object']) && 'setup_intent' === $this->data['object']) { |
| 78 | + return in_array($this->getStatus(), ['succeeded', 'requires_payment_method']); |
| 79 | + } |
| 80 | + |
| 81 | + return parent::isSuccessful(); |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * @inheritdoc |
| 86 | + */ |
| 87 | + public function isCancelled() |
| 88 | + { |
| 89 | + if (isset($this->data['object']) && 'setup_intent' === $this->data['object']) { |
| 90 | + return $this->getStatus() === 'canceled'; |
| 91 | + } |
| 92 | + |
| 93 | + return parent::isCancelled(); |
| 94 | + } |
| 95 | + |
| 96 | + /** |
| 97 | + * @inheritdoc |
| 98 | + */ |
| 99 | + public function isRedirect() |
| 100 | + { |
| 101 | + if ($this->getStatus() === 'requires_action' || $this->getStatus() === 'requires_source_action') { |
| 102 | + // Currently this gateway supports only manual confirmation, so any other |
| 103 | + // next action types pretty much mean a failed transaction for us. |
| 104 | + return (!empty($this->data['next_action']) && $this->data['next_action']['type'] === 'redirect_to_url'); |
| 105 | + } |
| 106 | + |
| 107 | + return parent::isRedirect(); |
| 108 | + } |
| 109 | + |
| 110 | + /** |
| 111 | + * @inheritdoc |
| 112 | + */ |
| 113 | + public function getRedirectUrl() |
| 114 | + { |
| 115 | + return $this->isRedirect() ? $this->data['next_action']['redirect_to_url']['url'] : parent::getRedirectUrl(); |
| 116 | + } |
| 117 | + |
| 118 | + /** |
| 119 | + * Get the payment intent reference. |
| 120 | + * |
| 121 | + * @return string|null |
| 122 | + */ |
| 123 | + public function getSetupIntentReference() |
| 124 | + { |
| 125 | + if (isset($this->data['object']) && 'setup_intent' === $this->data['object']) { |
| 126 | + return $this->data['id']; |
| 127 | + } |
| 128 | + |
| 129 | + return null; |
| 130 | + } |
| 131 | + |
| 132 | + /** |
| 133 | + * Get the payment intent reference. |
| 134 | + * |
| 135 | + * @return string|null |
| 136 | + */ |
| 137 | + public function getPaymentMethod() |
| 138 | + { |
| 139 | + if (isset($this->data['object']) && 'setup_intent' === $this->data['object']) { |
| 140 | + return $this->data['payment_method']; |
| 141 | + } |
| 142 | + |
| 143 | + return null; |
| 144 | + } |
| 145 | +} |
0 commit comments