CustomerDataBuilder.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Braintree\Gateway\Request;
  7. use Magento\Payment\Gateway\Request\BuilderInterface;
  8. use Magento\Braintree\Gateway\SubjectReader;
  9. /**
  10. * Class CustomerDataBuilder
  11. */
  12. class CustomerDataBuilder implements BuilderInterface
  13. {
  14. /**
  15. * Customer block name
  16. */
  17. const CUSTOMER = 'customer';
  18. /**
  19. * The first name value must be less than or equal to 255 characters.
  20. */
  21. const FIRST_NAME = 'firstName';
  22. /**
  23. * The last name value must be less than or equal to 255 characters.
  24. */
  25. const LAST_NAME = 'lastName';
  26. /**
  27. * The customer’s company. 255 character maximum.
  28. */
  29. const COMPANY = 'company';
  30. /**
  31. * The customer’s email address, comprised of ASCII characters.
  32. */
  33. const EMAIL = 'email';
  34. /**
  35. * Phone number. Phone must be 10-14 characters and can
  36. * only contain numbers, dashes, parentheses and periods.
  37. */
  38. const PHONE = 'phone';
  39. /**
  40. * @var SubjectReader
  41. */
  42. private $subjectReader;
  43. /**
  44. * Constructor
  45. *
  46. * @param SubjectReader $subjectReader
  47. */
  48. public function __construct(SubjectReader $subjectReader)
  49. {
  50. $this->subjectReader = $subjectReader;
  51. }
  52. /**
  53. * @inheritdoc
  54. */
  55. public function build(array $buildSubject)
  56. {
  57. $paymentDO = $this->subjectReader->readPayment($buildSubject);
  58. $order = $paymentDO->getOrder();
  59. $billingAddress = $order->getBillingAddress();
  60. return [
  61. self::CUSTOMER => [
  62. self::FIRST_NAME => $billingAddress->getFirstname(),
  63. self::LAST_NAME => $billingAddress->getLastname(),
  64. self::COMPANY => $billingAddress->getCompany(),
  65. self::PHONE => $billingAddress->getTelephone(),
  66. self::EMAIL => $billingAddress->getEmail(),
  67. ]
  68. ];
  69. }
  70. }