Skip to content
Snippets Groups Projects

Issue #3436134: Check billing profile value before calling get

1 file
+ 15
7
Compare changes
  • Side-by-side
  • Inline
@@ -21,6 +21,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Drupal\address\AddressInterface;
use Drupal\profile\Entity\ProfileInterface;
/**
* Provides the Stripe Checkout payment gateway plugin.
@@ -193,8 +195,9 @@ class CommerceStripeCheckoutCheckout extends OffsitePaymentGatewayBase implement
* {@inheritdoc}
*/
public function setCommerceStripeCheckoutCheckoutData(PaymentInterface $payment) {
$nvp_data = [];
$order = $payment->getOrder();
$billing_profile = $order->getBillingProfile();
$amount = $payment->getAmount();
$configuration = $this->getConfiguration();
@@ -227,14 +230,19 @@ class CommerceStripeCheckoutCheckout extends OffsitePaymentGatewayBase implement
'nonce' => $nonce,
];
$address = $order->getBillingProfile()->get('address')->first();
$address = $billing_profile instanceof ProfileInterface ? $billing_profile->get('address')->first() : NULL;
if ($address instanceof AddressInterface) {
$nvp_data += [
'fname' => $address->getGivenName(),
'lname' => $address->getFamilyName(),
'country' => $address->getCountryCode(),
'city' => $address->getLocality(),
];
}
// The hidden data wich should be transported to CommerceStripeCheckout.ro.
$nvp_data = [
'fname' => $address->getGivenName(),
'lname' => $address->getFamilyName(),
'country' => $address->getCountryCode(),
'city' => $address->getLocality(),
$nvp_data += [
'email' => $order->getEmail(),
'amount' => Calculator::round($amount->getNumber(), 2),
'currency' => $amount->getCurrencyCode(),
Loading