/** * Get vault payment token entity * * @param \Braintree\Transaction $transaction * @param OrderPaymentInterface $payment * @return PaymentTokenInterface|null */ protected function getVaultPaymentToken(Transaction $transaction, OrderPaymentInterface $payment) { // Check token existing in gateway response $token = $transaction->creditCardDetails->token; if (empty($token)) { return null; } $order = $payment->getOrder(); /** @var PaymentTokenInterface $paymentToken */ $paymentToken = $this->paymentTokenFactory->create(); $paymentToken->setGatewayToken($token); $paymentToken->setCustomerId($order->getCustomerId()); $paymentToken->setPaymentMethodCode($payment->getMethod()); $paymentToken->setCreatedAt($order->getCreatedAt()); $paymentToken->setTokenDetails($this->convertDetailsToJSON(['type' => $this->getCreditCardType($transaction->creditCardDetails->cardType), 'maskedCC' => $transaction->creditCardDetails->last4, 'expirationDate' => $transaction->creditCardDetails->expirationDate])); return $paymentToken; }
/** * Loads a specified payment token. * * @param int $entityId The payment token entity ID. * @return \Magento\Vault\Api\Data\PaymentTokenInterface Payment token interface. */ public function getById($entityId) { $tokenModel = $this->paymentTokenFactory->create(); $this->resourceModel->load($tokenModel, $entityId); return $tokenModel; }
/** * @inheritdoc */ public function getById($entityId) { return $this->tokenFactory->create(); }
/** * Get payment token by public hash. * * @param string $hash Public hash. * @param int $customerId Customer ID. * @return PaymentTokenInterface|null Payment token interface. */ public function getByPublicHash($hash, $customerId) { $tokenData = $this->paymentTokenResourceModel->getByPublicHash($hash, $customerId); $tokenModel = !empty($tokenData) ? $this->paymentTokenFactory->create(['data' => $tokenData]) : null; return $tokenModel; }