![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/job-board.corals.io/Corals/modules/Payment/Stripe/Message/ |
<?php /** * Stripe Response. */ namespace Corals\Modules\Payment\Stripe\Message; use Corals\Modules\Payment\Common\Message\AbstractResponse; use Corals\Modules\Payment\Common\Message\RequestInterface; /** * Stripe Response. * * This is the response class for all Stripe requests. * * @see \Corals\Modules\Payment\Stripe\Gateway */ class Response extends AbstractResponse { /** * Request id * * @var string URL */ protected $requestId = null; /** * @var array */ protected $headers = []; public function __construct(RequestInterface $request, $data, $headers = []) { $this->request = $request; $this->data = json_decode($data, true); $this->headers = $headers; } /** * Is the transaction successful? * * @return bool */ public function isSuccessful() { return !isset($this->data['error']); } /** * Get the charge reference from the response of FetchChargeRequest. * * @return array|null *@see \Corals\Modules\Payment\Stripe\Message\Response::getTransactionReference() * @deprecated 2.3.3:3.0.0 duplicate of \Corals\Modules\Payment\Stripe\Message\Response::getTransactionReference() */ public function getChargeReference() { if (isset($this->data['object']) && $this->data['object'] == 'charge') { return $this->data['id']; } if (isset($this->data['object']) && 'payment_intent' === $this->data['object']) { $charges = $this->data['charges']; if (!empty($charges)) { return $charges['data'][0]['id']; } } return null; } /** * Get the transaction reference. * * @return string|null */ public function getTransactionReference() { if (isset($this->data['object']) && 'charge' === $this->data['object']) { return $this->data['id']; } if (isset($this->data['error']) && isset($this->data['error']['charge'])) { return $this->data['error']['charge']; } return null; } /** * Get the balance transaction reference. * * @return string|null */ public function getBalanceTransactionReference() { if (isset($this->data['object']) && 'charge' === $this->data['object']) { return $this->data['balance_transaction']; } if (isset($this->data['object']) && 'balance_transaction' === $this->data['object']) { return $this->data['id']; } if (isset($this->data['error']) && isset($this->data['error']['charge'])) { return $this->data['error']['charge']; } return null; } /** * Get a customer reference, for createCustomer requests. * * @return string|null */ public function getCustomerReference() { if (isset($this->data['object']) && 'customer' === $this->data['object']) { return $this->data['id']; } if (isset($this->data['object']) && 'card' === $this->data['object']) { if (!empty($this->data['customer'])) { return $this->data['customer']; } } return null; } /** * Get a card reference, for createCard or createCustomer requests. * * @return string|null */ public function getCardReference() { if (isset($this->data['object']) && 'customer' === $this->data['object']) { if (isset($this->data['default_source']) && !empty($this->data['default_source'])) { return $this->data['default_source']; } if (isset($this->data['default_card']) && !empty($this->data['default_card'])) { return $this->data['default_card']; } if (!empty($this->data['id'])) { return $this->data['id']; } } if (isset($this->data['object']) && 'card' === $this->data['object']) { if (!empty($this->data['id'])) { return $this->data['id']; } } if (isset($this->data['object']) && 'charge' === $this->data['object']) { if (!empty($this->data['source'])) { if (!empty($this->data['source']['id'])) { return $this->data['source']['id']; } } } return null; } /** * Get a token, for createCard requests. * * @return string|null */ public function getToken() { if (isset($this->data['object']) && 'token' === $this->data['object']) { return $this->data['id']; } return null; } public function getPaymentTokenReference() { if (isset($this->data['object']) && 'payment_intent' === $this->data['object']) { return json_encode(['payment_intent_id' => $this->data['id'], 'status' => $this->data['status'], 'next_action' => $this->data['next_action'], 'client_secret' => $this->data['client_secret']]); } return null; } /** * Get the card data from the response. * * @return array|null */ public function getCard() { if (isset($this->data['card'])) { return $this->data['card']; } return null; } /** * Get the card data from the response of purchaseRequest. * * @return array|null */ public function getSource() { if (isset($this->data['source']) && $this->data['source']['object'] == 'card') { return $this->data['source']; } return null; } /** * Get the subscription reference from the response of CreateSubscriptionRequest. * * @return array|null */ public function getSubscriptionReference() { if (isset($this->data['object']) && $this->data['object'] == 'subscription') { return $this->data['id']; } return null; } /** * Get the event reference from the response of FetchEventRequest. * * @return array|null */ public function getEventReference() { if (isset($this->data['object']) && $this->data['object'] == 'event') { return $this->data['id']; } return null; } /** * Get the invoice reference from the response of FetchInvoiceRequest. * * @return array|null */ public function getInvoiceReference() { if (isset($this->data['object']) && $this->data['object'] == 'invoice') { return $this->data['id']; } return null; } /** * Get the transfer reference from the response of CreateTransferRequest, * UpdateTransferRequest, and FetchTransferRequest. * * @return array|null */ public function getTransferReference() { if (isset($this->data['object']) && $this->data['object'] == 'transfer') { return $this->data['id']; } return null; } /** * Get the transfer reference from the response of CreateTransferReversalRequest, * UpdateTransferReversalRequest, and FetchTransferReversalRequest. * * @return array|null */ public function getTransferReversalReference() { if (isset($this->data['object']) && $this->data['object'] == 'transfer_reversal') { return $this->data['id']; } return null; } /** * Get the list object from a result * * @return array|null */ public function getList() { if (isset($this->data['object']) && $this->data['object'] == 'list') { return $this->data['data']; } return null; } /** * Get the subscription plan from the response of CreateSubscriptionRequest. * * @return array|null */ public function getPlan() { if (isset($this->data['plan'])) { return $this->data['plan']; } elseif (array_key_exists('object', $this->data) && $this->data['object'] == 'plan') { return $this->data; } return null; } /** * Get plan id * * @return string|null */ public function getPlanId() { $plan = $this->getPlan(); if ($plan && array_key_exists('id', $plan)) { return $plan['id']; } return null; } /** * Get invoice-item reference * * @return string|null */ public function getInvoiceItemReference() { if (isset($this->data['object']) && $this->data['object'] == 'invoiceitem') { return $this->data['id']; } return null; } /** * Get the error message from the response. * * Returns null if the request was successful. * * @return string|null */ public function getMessage() { if (!$this->isSuccessful() && isset($this->data['error']) && isset($this->data['error']['message'])) { return $this->data['error']['message']; } return null; } /** * Get the error message from the response. * * Returns null if the request was successful. * * @return string|null */ public function getCode() { if (!$this->isSuccessful() && isset($this->data['error']) && isset($this->data['error']['code'])) { return $this->data['error']['code']; } return null; } /** * @return string|null */ public function getRequestId() { if (isset($this->headers['Request-Id'])) { return $this->headers['Request-Id'][0]; } return null; } /** * Get a CurrentPeriodEnd reference, for Subscription requests. * * @return string|null */ public function getCurrentPeriodEndReference() { if (isset($this->data['object']) && 'subscription' === $this->data['object']) { return $this->data['current_period_end']; } return null; } }