e order. * * @param int $order_id The WC order ID. * @return array */ public function process_payment($order_id) { $wc_order = wc_get_order($order_id); $wc_order->update_status('pending', __('Awaiting for the buyer to complete the payment.', 'woocommerce-paypal-payments')); $purchase_unit = $this->purchase_unit_factory->from_wc_order($wc_order); $amount = $purchase_unit->amount()->to_array(); $request_body = array('intent' => 'CAPTURE', 'purchase_units' => array(array('reference_id' => $purchase_unit->reference_id(), 'amount' => array('currency_code' => $amount['currency_code'], 'value' => $amount['value']), 'custom_id' => $purchase_unit->custom_id(), 'invoice_id' => $purchase_unit->invoice_id()))); try { $response = $this->orders_endpoint->create($request_body); $body = json_decode($response['body']); $request_body = array('payment_source' => array('multibanco' => array('country_code' => $wc_order->get_billing_country(), 'name' => $wc_order->get_billing_first_name() . ' ' . $wc_order->get_billing_last_name(), 'experience_context' => $this->experience_context_builder->with_order_return_urls($wc_order)->build()->with_locale('en-PT')->to_array())), 'processing_instruction' => 'ORDER_COMPLETE_ON_PAYMENT_APPROVAL'); $response = $this->orders_endpoint->confirm_payment_source($request_body, $body->id); $body = json_decode($response['body']); $payer_action = ''; foreach ($body->links as $link) { if ($link->rel === 'payer-action') { $payer_action = $link->href; } } WC()->cart->empty_cart(); $wc_order->update_meta_data(PayPalGateway::ORDER_ID_META_KEY, $body->id); $wc_order->save_meta_data(); return array('result' => 'success', 'redirect' => esc_url($payer_action)); } catch (RuntimeException $exception) { $wc_order->update_status('failed', $exception->getMessage()); return array('result' => 'failure', 'redirect' => wc_get_checkout_url()); } } /** * Process refund. * * If the gateway declares 'refunds' support, this will allow it to refund. * a passed in amount. * * @param int $order_id Order ID. * @param float $amount Refund amount. * @param string $reason Refund reason. * @return boolean True or false based on success, or a WP_Error object. */ public function process_refund($order_id, $amount = null, $reason = '') { $order = wc_get_order($order_id); if (!is_a($order, \WC_Order::class)) { return \false; } return $this->refund_processor->process($order, (float) $amount, (string) $reason); } /** * Return transaction url for this gateway and given order. * * @param \WC_Order $order WC order to get transaction url by. * * @return string */ public function get_transaction_url($order): string { $this->view_transaction_url = $this->transaction_url_provider->get_transaction_url_base($order); return parent::get_transaction_url($order); } /** * Initialize APM gateway defaults from centralized definition. */ private function init_apm_defaults(): void { $defaults = PaymentMethodsDefinition::get_apm_defaults()[self::ID]; $this->method_title = $defaults['method_title']; $this->method_description = $defaults['method_description']; } /** * Load saved settings and override defaults. */ private function init_apm_settings(): void { $defaults = PaymentMethodsDefinition::get_apm_defaults()[self::ID]; $this->title = $this->get_option('title', $defaults['title']); $this->description = $this->get_option('description', $defaults['description']); } }