De winkelwagen is leeg
? $data['redirectUrl'] : '', 'webhookUrl' => isset($data['webhookUrl']) ? $data['webhookUrl'] : '', 'method' => isset($data['method']) ? $data['method'] : '', 'issuer' => isset($data['issuer']) ? $data['issuer'] : '', 'locale' => isset($data['locale']) ? $data['locale'] : '', 'dueDate' => isset($data['dueDate']) ? $data['dueDate'] : '', 'metadata' => isset($data['metadata']) ? $data['metadata'] : '', ]; $this->logger->debug($apiCallLog); // Try as simple payment $paymentObject = $this->apiHelper->getApiClient( $apiKey )->payments->create($data); } catch (ApiException $e) { $this->handleMollieOutage($e); $message = $e->getMessage(); $this->logger->debug($message); throw $e; } return $paymentObject; } /** * @param $molliePaymentType * @param $orderId * @param MollieOrder|MolliePayment $paymentObject * @param \WC_Order $order * @param $customer_id * @param $test_mode * * @return mixed|Payment|MollieOrder * @throws ApiException */ protected function processPaymentForMollie( $molliePaymentType, $orderId, $paymentObject, $order, $customer_id, $apiKey ) { // // PROCESS REGULAR PAYMENT AS MOLLIE ORDER // if ($molliePaymentType === self::PAYMENT_METHOD_TYPE_ORDER) { $this->logger->debug( "{$this->gateway->id}: Create Mollie payment object for order {$orderId}", [true] ); list($paymentObject, $molliePaymentType) = $this->processAsMollieOrder( $paymentObject, $order, $customer_id, $apiKey ); } // // PROCESS REGULAR PAYMENT AS MOLLIE PAYMENT // if ($molliePaymentType === self::PAYMENT_METHOD_TYPE_PAYMENT) { $this->logger->debug( 'Creating payment object: type Payment, creating a Payment.' ); $paymentObject = $this->processAsMolliePayment( $order, $customer_id, $apiKey ); } return $paymentObject; } /** * @param $order * @param $payment */ protected function saveMollieInfo($order, $payment) { // Get correct Mollie Payment Object $payment_object = $this->paymentFactory->getPaymentObject($payment); // Set active Mollie payment $payment_object->setActiveMolliePayment($order->get_id()); // Get Mollie Customer ID $mollie_customer_id = $payment_object->getMollieCustomerIdFromPaymentObject($payment_object->data()->id); // Set Mollie customer $this->dataHelper->setUserMollieCustomerId($order->get_customer_id(), $mollie_customer_id); } /** * @param \WC_Order $order * @param string $new_status * @param string $note * @param bool $restore_stock */ public function updateOrderStatus(\WC_Order $order, $new_status, $note = '', $restore_stock = true) { $order->update_status($new_status, $note); switch ($new_status) { case SharedDataDictionary::STATUS_ON_HOLD: if ($restore_stock === true) { if (!$order->get_meta('_order_stock_reduced', true)) { // Reduce order stock wc_reduce_stock_levels($order->get_id()); $this->logger->debug(__METHOD__ . ": Stock for order {$order->get_id()} reduced."); } } break; case SharedDataDictionary::STATUS_PENDING: case SharedDataDictionary::STATUS_FAILED: case SharedDataDictionary::STATUS_CANCELLED: if ($order->get_meta('_order_stock_reduced', true)) { // Restore order stock $this->dataHelper->restoreOrderStock($order); $this->logger->debug(__METHOD__ . " Stock for order {$order->get_id()} restored."); } break; } } /** * @param $orderId */ protected function noValidMandateForSubsSwitchFailure($orderId): void { $this->logger->debug( $this->gateway->id . ': Subscription switch failed, no valid mandate for order #' . $orderId ); $this->notice->addNotice( 'error', __( 'Subscription switch failed, no valid mandate found. Place a completely new order to change your subscription.', 'mollie-payments-for-woocommerce' ) ); throw new ApiException( __('Failed switching subscriptions, no valid mandate.', 'mollie-payments-for-woocommerce') ); } protected function subsSwitchCompleted($order): array { $order->payment_complete(); $order->add_order_note( sprintf( __( 'Order completed internally because of an existing valid mandate at Mollie.', 'mollie-payments-for-woocommerce' ) ) ); $this->logger->debug($this->gateway->id . ': Subscription switch completed, valid mandate for order #' . $order->get_id()); return [ 'result' => 'success', 'redirect' => $this->gateway->get_return_url($order), ]; } /** * @param $order * @param string|null $customerId * @param $apiKey * @return bool * @throws ApiException */ protected function processValidMandate($order, ?string $customerId, $apiKey): bool { $paymentObject = $this->paymentFactory->getPaymentObject( self::PAYMENT_METHOD_TYPE_PAYMENT ); $paymentRequestData = $paymentObject->getPaymentRequestData($order, $customerId); $data = array_filter($paymentRequestData); $data = apply_filters('woocommerce_' . $this->gateway->id . '_args', $data, $order); $mandates = $this->apiHelper->getApiClient($apiKey)->customers->get($customerId)->mandates(); $validMandate = false; foreach ($mandates as $mandate) { if ($mandate->status === 'valid') { $validMandate = true; $data['method'] = $mandate->method; break; } } return $validMandate; } protected function processSubscriptionSwitch(WC_Order $order, int $orderId, ?string $customerId, ?string $apiKey) { // // PROCESS SUBSCRIPTION SWITCH - If this is a subscription switch and customer has a valid mandate, process the order internally // try { $this->logger->debug($this->gateway->id . ': Subscription switch started, fetching mandate(s) for order #' . $orderId); $validMandate = $this->processValidMandate($order, $customerId, $apiKey); if ($validMandate) { return $this->subsSwitchCompleted($order); } else { $this->noValidMandateForSubsSwitchFailure($orderId); } } catch (ApiException $e) { if ($e->getField()) { throw $e; } } return ['result' => 'failure']; } /** * @param $orderId * @param $e * @param $paymentMethodId */ protected function reportPaymentCreationFailure($orderId, $e, $paymentMethodId): void { $this->logger->debug( $paymentMethodId . ': Failed to create Mollie payment object for order ' . $orderId . ': ' . $e->getMessage( ) ); /* translators: Placeholder 1: Payment method title */ $message = sprintf(__('Could not create %s payment.', 'mollie-payments-for-woocommerce'), $paymentMethodId); if (defined('WP_DEBUG') && WP_DEBUG) { $message .= 'hii ' . $e->getMessage(); } $this->notice->addNotice('error', $message); } /** * @param $orderId * @param $apiKey * @param string|null $customerId * @param $paymentObject * @param $order * @throws ApiException */ protected function saveSubscriptionMandateData( $orderId, $apiKey, ?string $customerId, $paymentObject, $order ): void { $dataHelper = $this->dataHelper; if ($dataHelper->isSubscription($orderId)) { $mandates = $this->apiHelper->getApiClient($apiKey)->customers->get($customerId)->mandates(); if (!isset($mandates[0])) { return; } // madates are sorted by date, so the first one is the newest $mandate = $mandates[0]; $customerId = $mandate->customerId; $mandateId = $mandate->id; $this->logger->debug( "Mollie Subscription in the order: customer id {$customerId} and mandate id {$mandateId} " ); do_action($this->pluginId . '_after_mandate_created', $paymentObject, $order, $customerId, $mandateId); } } /** * @param $paymentObject * @param $order * @param $initialOrderStatus */ protected function updatePaymentStatusForDelayedMethods($paymentObject, $order, $initialOrderStatus): void { // Update initial order status for payment methods where the payment status will be delivered after a couple of days. // See: https://www.mollie.com/nl/docs/status#expiry-times-per-payment-method // Status is only updated if the new status is not the same as the default order status (pending) if (($paymentObject->method === Constants::BANKTRANSFER) || ($paymentObject->method === Constants::DIRECTDEBIT)) { // Don't change the status of the order if it's Partially Paid // This adds support for WooCommerce Deposits (by Webtomizer) // See https://github.com/mollie/WooCommerce/issues/138 $order_status = $order->get_status(); if ($order_status !== 'wc-partially-paid ') { $this->updateOrderStatus( $order, $initialOrderStatus, __('Awaiting payment confirmation.', 'mollie-payments-for-woocommerce') . "\n" ); } } } /** * @param $paymentObject * @param $orderId * @param $order */ protected function reportPaymentSuccess($paymentObject, $orderId, $order, $paymentMethod): void { $paymentMethodTitle = $paymentMethod->getProperty('id'); $this->logger->debug( $paymentMethodTitle . ': Mollie payment object ' . $paymentObject->id . ' (' . $paymentObject->mode . ') created for order ' . $orderId ); $order->add_order_note( sprintf( /* translators: Placeholder 1: Payment method title, placeholder 2: payment ID */ __('%1$s payment started (%2$s).', 'mollie-payments-for-woocommerce'), $paymentMethodTitle, $paymentObject->id . ($paymentObject->mode === 'test' ? (' - ' . __( 'test mode', 'mollie-payments-for-woocommerce' )) : '') ) ); $this->logger->debug( "For order " . $orderId . " redirect user to Mollie Checkout URL: " . $paymentObject->getCheckoutUrl() ); } /** * @param $order * @param $orderId * @return bool */ protected function needsSubscriptionSwitch($order, $orderId): bool { return ('0.00' === $order->get_total()) && ($this->dataHelper->isWcSubscription($orderId) === true) && 0 !== $order->get_user_id() && (wcs_order_contains_switch($order)); } /** * @param $exception * @return string[] */ protected function paymentObjectFailure($exception): array { $this->logger->debug($exception->getMessage()); return ['result' => 'failure']; } /** * @return mixed|void|null */ protected function processInitialOrderStatus($paymentMethod) { $initialOrderStatus = $paymentMethod->getInitialOrderStatus(); // Overwrite plugin-wide $initialOrderStatus = apply_filters( $this->pluginId . '_initial_order_status', $initialOrderStatus ); // Overwrite gateway-wide return apply_filters( $this->pluginId . '_initial_order_status_' . $paymentMethod->getProperty('id'), $initialOrderStatus ); } /** * Check if the exception is an outage, if so bail, log and inform user * @param ApiException $e * @return void * @throws ApiException */ public function handleMollieOutage(ApiException $e): void { $isMollieOutage = $this->apiHelper->isMollieOutageException($e); if ($isMollieOutage) { $this->logger->debug( "Creating payment object: type Order failed due to a Mollie outage, stopping process. Check Mollie status at https://status.mollie.com/. {$e->getMessage()}" ); throw new ApiException( __( 'Payment failed due to: Mollie is out of service. Please try again later.', 'mollie-payments-for-woocommerce' ) ); } } }
De winkelwagen is leeg
Resultaat 1–12 van de 692 resultaten wordt getoond