Charge.php
3 years ago
Create_Customer.php
4 years ago
Create_Customer_Card.php
4 years ago
Create_PayOrder.php
2 years ago
Create_Payment.php
2 years ago
Get_Customer.php
3 years ago
Get_Gift_Card.php
2 years ago
Refund.php
4 years ago
Search_Orders.php
10 months ago
Get_Customer.php
58 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WooCommerce\Square\Gateway\API\Responses; |
| 4 | |
| 5 | use WooCommerce\Square\Framework\PaymentGateway\Payment_Gateway_Helper; |
| 6 | use WooCommerce\Square\Framework\PaymentGateway\Api\Payment_Gateway_API_Get_Tokenized_Payment_Methods_Response; |
| 7 | use WooCommerce\Square\Framework\PaymentGateway\PaymentTokens\Payment_Gateway_Payment_Token; |
| 8 | |
| 9 | defined( 'ABSPATH' ) || exit; |
| 10 | |
| 11 | /** |
| 12 | * Get customer response. |
| 13 | * |
| 14 | * @since 2.0.0 |
| 15 | * |
| 16 | * @method \Square\Models\RetrieveCustomerResponse|array get_data() |
| 17 | */ |
| 18 | class Get_Customer extends \WooCommerce\Square\Gateway\API\Response implements Payment_Gateway_API_Get_Tokenized_Payment_Methods_Response { |
| 19 | /** |
| 20 | * Returns any payment tokens. |
| 21 | * |
| 22 | * @since 1.0.0 |
| 23 | * |
| 24 | * @return Payment_Gateway_Payment_Token[] |
| 25 | */ |
| 26 | public function get_payment_tokens() { |
| 27 | |
| 28 | $cards = $this->get_data() instanceof \Square\Models\RetrieveCustomerResponse ? $this->get_data()->getCustomer()->getCards() : array(); |
| 29 | $tokens = array(); |
| 30 | |
| 31 | if ( is_array( $cards ) ) { |
| 32 | |
| 33 | foreach ( $cards as $card ) { |
| 34 | |
| 35 | if ( 'SQUARE_GIFT_CARD' === $card->getCardBrand() ) { |
| 36 | continue; |
| 37 | } |
| 38 | |
| 39 | $token_id = $card->getId(); |
| 40 | $card_type = 'AMERICAN_EXPRESS' === $card->getCardBrand() ? Payment_Gateway_Helper::CARD_TYPE_AMEX : $card->getCardBrand(); |
| 41 | |
| 42 | $tokens[ $token_id ] = new Payment_Gateway_Payment_Token( |
| 43 | $token_id, |
| 44 | array( |
| 45 | 'type' => 'credit_card', |
| 46 | 'card_type' => $card_type, |
| 47 | 'last_four' => $card->getLast4(), |
| 48 | 'exp_month' => $card->getExpMonth(), |
| 49 | 'exp_year' => $card->getExpYear(), |
| 50 | ) |
| 51 | ); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | return $tokens; |
| 56 | } |
| 57 | } |
| 58 |