You are here

protected function AcceptJs::buildCustomerPaymentProfile in Commerce Authorize.Net 8

Creates a new customer payment profile in Authorize.net CIM.

Parameters

\Drupal\commerce_payment\Entity\PaymentMethodInterface $payment_method: The payment method.

array $payment_details: The gateway-specific payment details.

string $customer_id: The remote customer ID, if available.

Return value

\CommerceGuys\AuthNet\DataTypes\PaymentProfile The payment profile data type.

1 call to AcceptJs::buildCustomerPaymentProfile()
AcceptJs::doCreatePaymentMethod in src/Plugin/Commerce/PaymentGateway/AcceptJs.php
Creates the payment method on the gateway.

File

src/Plugin/Commerce/PaymentGateway/AcceptJs.php, line 751

Class

AcceptJs
Provides the Accept.js payment gateway.

Namespace

Drupal\commerce_authnet\Plugin\Commerce\PaymentGateway

Code

protected function buildCustomerPaymentProfile(PaymentMethodInterface $payment_method, array $payment_details, $customer_id = NULL) {
  $payment = new OpaqueData([
    'dataDescriptor' => $payment_details['data_descriptor'],
    'dataValue' => $payment_details['data_value'],
  ]);
  $payment_profile = new PaymentProfile([
    // @todo how to allow customizing this.
    'customerType' => 'individual',
  ]);
  if ($billing_profile = $payment_method
    ->getBillingProfile()) {

    /** @var \Drupal\address\AddressInterface $address */
    $address = $billing_profile
      ->get('address')
      ->first();
    $bill_to = array_filter([
      // @todo how to allow customizing this.
      'firstName' => $address
        ->getGivenName(),
      'lastName' => $address
        ->getFamilyName(),
      'company' => $address
        ->getOrganization(),
      'address' => substr($address
        ->getAddressLine1() . ' ' . $address
        ->getAddressLine2(), 0, 60),
      'country' => $address
        ->getCountryCode(),
      'city' => $address
        ->getLocality(),
      'state' => $address
        ->getAdministrativeArea(),
      'zip' => $address
        ->getPostalCode(),
    ]);
    $payment_profile
      ->addBillTo(new BillTo($bill_to));
  }
  $payment_profile
    ->addPayment($payment);
  return $payment_profile;
}