/** * Initialize a payment token where $token is a 24 digit globally unique id * provided by QBMS with a predetermined structure used to infer * certain information about the payment method. The WalletEntryID is * structured as follows: * * + 1 digit wallet entry type (1 - Credit Card, 2 - Check) * + 2 digit brand type (01 - Visa, 02 - MasterCard, 03 - Amex, 04 - Discover, 05 - DinersClub, 06 - JCB, 00 - Check) * + 17 digit random number * + Last 4 digits of the credit card or check account number. * * @since 1.0 * @param string $token the QBMS Wallet entry ID value * @param array $data associated data */ public function __construct($token, $data) { $data['type'] = $this->get_type_from_token($token); $data['last_four'] = $this->get_last_four_from_token($token); if ('credit_card' == $data['type']) { $data['card_type'] = $this->get_card_type_from_token($token); } parent::__construct($token, $data); }
/** * Construct the token * * @since 2.0.0 * @param string $payment_profile_id payment profile (token) ID * @param array $data accepts order, billing_hash, and payment_hash elements */ public function __construct($payment_profile_id, $data) { $this->set_customer_profile_id($data['customer_profile_id']); // add payment-specific info to token from $order->payment if set if (isset($data['order']) && $data['order'] instanceof WC_Order) { $data = array_merge($data, $this->parse_data_from_order($data['order'])); } // TODO: it's tough to understand when & how class members are set here vs. those in the $data array -- look to refactor this @MR if (empty($data['billing_hash'])) { $data['billing_hash'] = $this->calculate_billing_hash($data); } else { $this->set_billing_hash($data['billing_hash']); } if (empty($data['payment_hash'])) { $data['payment_hash'] = $this->calculate_payment_hash($data); } else { $this->set_payment_hash($data['payment_hash']); } // no need to save these with the token unset($data['order']); unset($data['billing']); parent::__construct($payment_profile_id, $data); }