Es kommt drauf an, was du eingestellt hast.
Entweder „Bestellung an Paypal übertragen: Ja“ - das heißt hier konkret, dass die Bestellung vor der Weiterleitung an Paypal angelegt wird oder „Bestellung an Paypal übertragen: Nein“ dann wird erst bei erfolgreicher Zahlung die Bestellung abgeschlossen.
$patchOrderNumber = $this->settingsService->get('order_number_prefix') . $orderNumber;
/** @var PaymentOrderNumberPatch $paymentPatch */
$paymentPatch = new PaymentOrderNumberPatch($patchOrderNumber);
try {
$this->paymentResource->patch($paymentId, [$paymentPatch]);
} catch (RequestException $exception) {
$this->handleError(ErrorCodes::COMMUNICATION_FAILURE, $exception);
return;
}
}
$payerId = $request->getParam('PayerID');
/** @var OrderDataService $orderDataService */
$orderDataService = $this->get('paypal_unified.order_data_service');
try {
// execute the payment to the PayPal API
$executionResponse = $this->paymentResource->execute($payerId, $paymentId);
/** @var RelatedResource $relatedResource */
$relatedResource = $response->getTransactions()->getRelatedResources()->getResources()[0];
//Use TXN-ID instead of the PaymentId
$relatedResourceId = $relatedResource->getId();
if (!$orderDataService->applyTransactionId($orderNumber, $relatedResourceId)) {
$this->handleError(ErrorCodes::NO_ORDER_TO_PROCESS);
return;
}
// apply the payment status if its completed by PayPal
$paymentState = $relatedResource->getState();
if ($paymentState === PaymentStatus::PAYMENT_COMPLETED) {
$this->savePaymentStatus($relatedResourceId, $paymentId, PaymentStatus::PAYMENT_STATUS_PAID);
$orderDataService->setClearedDate($orderNumber);
}
// Save payment instructions from PayPal to database.
// if the instruction is of type MANUAL_BANK_TRANSFER the instructions are not required,
// since they don't have to be displayed on the invoice document