Skip to content

Commit ce97a97

Browse files
committed
catch error during createOrder
1 parent 40db948 commit ce97a97

2 files changed

Lines changed: 32 additions & 9 deletions

File tree

src/Controller/ProxyController.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function createOrder(): void
9393
false
9494
);
9595

96-
if ($response->id) {
96+
if ($response && $response->id) {
9797
PayPalSession::storePayPalOrderId($response->id);
9898
}
9999

@@ -165,6 +165,9 @@ public function createGooglePayOrder(): void
165165
false
166166
);
167167

168+
if (!$response) {
169+
return;
170+
}
168171
if ($response->id) {
169172
PayPalSession::storePayPalOrderId($response->id);
170173
}
@@ -198,7 +201,7 @@ public function createGooglePayOrder(): void
198201
/** @var array $userInvoiceAddress */
199202
$userInvoiceAddress = $user->getInvoiceAddress();
200203
// add PayPal-Address as Delivery-Address
201-
if (($response !== null) && !empty($response->purchase_units[0]->shipping)) {
204+
if (!empty($response->purchase_units[0]->shipping)) {
202205
$response->purchase_units[0]->shipping->address = $shippingAddress;
203206
$response->purchase_units[0]->shipping->name->full_name = $data['shippingAddress']['name'] ?? '';
204207
$deliveryAddress = PayPalAddressResponseToOxidAddress::mapUserDeliveryAddress($response);
@@ -547,6 +550,11 @@ public function createApplepayOrder()
547550
null,
548551
false
549552
);
553+
554+
if (!$response) {
555+
return;
556+
}
557+
550558
if ($response->id) {
551559
PayPalSession::storePayPalOrderId($response->id);
552560
}

src/Service/Payment.php

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function doCreatePayPalOrder(
113113
string $returnUrl = null,
114114
string $cancelUrl = null,
115115
bool $setProvidedAddress = true
116-
): Order {
116+
): ?Order {
117117
//TODO return value
118118
$this->setPaymentExecutionError(self::PAYMENT_ERROR_NONE);
119119

@@ -133,7 +133,7 @@ public function doCreatePayPalOrder(
133133
$setProvidedAddress
134134
);
135135

136-
$response = [];
136+
$response = null;
137137

138138
try {
139139
$response = $orderService->createOrder(
@@ -172,8 +172,13 @@ public function doCreatePatchedOrder(
172172
false
173173
);
174174

175-
$paypalOrderId = $response->id ?: '';
176-
$status = $response->status ?: '';
175+
$paypalOrderId = '';
176+
$status = '';
177+
178+
if ($response) {
179+
$paypalOrderId = $response->id ?: '';
180+
$status = $response->status ?: '';
181+
}
177182

178183
// patch the order only if paypalOrderId exists
179184
if ($paypalOrderId) {
@@ -583,7 +588,10 @@ public function doExecuteStandardPayment(
583588
false
584589
);
585590

586-
$orderId = $response->id ?: '';
591+
$orderId = '';
592+
if ($response) {
593+
$orderId = $response->id ?: '';
594+
}
587595

588596
if (!$orderId) {
589597
$this->setPaymentExecutionError(self::PAYMENT_ERROR_GENERIC);
@@ -632,7 +640,11 @@ public function doCreateUAPMOrder(EshopModelBasket $basket): string
632640
false
633641
);
634642

635-
return $response->id ?: '';
643+
$result = '';
644+
if ($response) {
645+
$result = $response->id ?: '';
646+
}
647+
return $result;
636648
}
637649

638650
public function doExecutePuiPayment(
@@ -642,6 +654,7 @@ public function doExecutePuiPayment(
642654
): bool {
643655
$this->setPaymentExecutionError(self::PAYMENT_ERROR_NONE);
644656

657+
$payPalOrderId = '';
645658
try {
646659
$result = $this->doCreatePayPalOrder(
647660
$basket,
@@ -652,7 +665,9 @@ public function doExecutePuiPayment(
652665
$payPalClientMetadataId,
653666
Constants::PAYPAL_PARTNER_ATTRIBUTION_ID_PPCP
654667
);
655-
$payPalOrderId = $result->id;
668+
if ($result) {
669+
$payPalOrderId = $result->id;
670+
}
656671
} catch (Exception $exception) {
657672
$this->setPaymentExecutionError(self::PAYMENT_ERROR_PUI_GENERIC);
658673
$this->logger->log('error', 'Error on pui order creation call.', [$exception]);

0 commit comments

Comments
 (0)