Commit e808becb authored by Jonathan Sacksick's avatar Jonathan Sacksick Committed by Jonathan Sacksick
Browse files

Issue #3128719 by jsacksick, liquidcms: Payment method billing profile is not...

Issue #3128719 by jsacksick, liquidcms: Payment method billing profile is not copied to the order for admin payments.
parent 1c625d98
Loading
Loading
Loading
Loading
+23 −4
Original line number Diff line number Diff line
@@ -341,11 +341,30 @@ class PaymentAddForm extends FormBase implements ContainerInjectionInterface {
      $order = $payment->getOrder();
      $order->set('payment_gateway', $payment->getPaymentGateway());
      if ($payment->getPaymentMethod()) {
        $order->set('payment_method', $payment->getPaymentMethod());
        $payment_method = $payment->getPaymentMethod();
        $order->set('payment_method', $payment_method);

        // Copy the billing information to the order.
        $payment_method_profile = $payment_method->getBillingProfile();
        if ($payment_method_profile) {
          $billing_profile = $order->getBillingProfile();
          if (!$billing_profile) {
            $billing_profile = $this->entityTypeManager->getStorage('profile')->create([
              'type' => 'customer',
              'uid' => 0,
            ]);
          }
          $billing_profile->populateFromProfile($payment_method_profile);
          // The data field is not copied by default but needs to be.
          // For example, both profiles need to have an address_book_profile_id.
          $billing_profile->populateFromProfile($payment_method_profile, ['data']);
          $billing_profile->save();
          $order->setBillingProfile($billing_profile);
        }
      }
      $this->entityTypeManager->getStorage('commerce_order')->save($order);
      $order->save();
      $this->messenger()->addMessage($this->t('Payment saved.'));
      $form_state->setRedirect('entity.commerce_payment.collection', ['commerce_order' => $this->order->id()]);
      $form_state->setRedirect('entity.commerce_payment.collection', ['commerce_order' => $order->id()]);
    }
  }

+5 −0
Original line number Diff line number Diff line
@@ -171,10 +171,15 @@ class DefaultPaymentAdminTest extends CommerceBrowserTestBase {
    $this->assertSession()->addressEquals($this->paymentUri);
    $this->assertSession()->elementContains('css', 'table tbody tr td:nth-child(2)', 'Completed');

    $this->order = $this->reloadEntity($this->order);
    \Drupal::entityTypeManager()->getStorage('commerce_payment')->resetCache([1]);
    /** @var \Drupal\commerce_payment\Entity\PaymentInterface $payment */
    $payment = Payment::load(1);
    $this->assertEquals($this->order->id(), $payment->getOrderId());
    $billing_profile = $this->order->getBillingProfile();
    $this->assertNotEmpty($billing_profile);
    $this->assertEquals($payment->getPaymentMethod()->id(), $this->order->get('payment_method')->target_id);
    $this->assertEquals($billing_profile->get('address')->first()->toArray(), $payment->getPaymentMethod()->getBillingProfile()->get('address')->first()->toArray());
    $this->assertEquals('100.00', $payment->getAmount()->getNumber());
    $this->assertNotEmpty($payment->getCompletedTime());
    $this->assertEquals('A', $payment->getAvsResponseCode());