TokenFormatter.php 924 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Braintree\Model\InstantPurchase\PayPal;
  7. use Magento\InstantPurchase\PaymentMethodIntegration\PaymentTokenFormatterInterface;
  8. use Magento\Vault\Api\Data\PaymentTokenInterface;
  9. /**
  10. * Braintree PayPal token formatter.
  11. */
  12. class TokenFormatter implements PaymentTokenFormatterInterface
  13. {
  14. /**
  15. * @inheritdoc
  16. */
  17. public function formatPaymentToken(PaymentTokenInterface $paymentToken): string
  18. {
  19. $details = json_decode($paymentToken->getTokenDetails() ?: '{}', true);
  20. if (!isset($details['payerEmail'])) {
  21. throw new \InvalidArgumentException('Invalid Braintree PayPal token details.');
  22. }
  23. $formatted = sprintf(
  24. '%s: %s',
  25. __('PayPal'),
  26. $details['payerEmail']
  27. );
  28. return $formatted;
  29. }
  30. }