File "class-kp-create-hpp.php"

Full Path: /home/siazco/grocery.siazco.se/wp-content/plugins/klarna-payments-for-woocommerce/classes/requests/post/class-kp-create-hpp.php
File size: 1.39 KB
MIME-type: text/x-php
Charset: utf-8

<?php
/**
 * Class for the request to create a HPP order.
 *
 * @package WC_Klarna_Payments/Classes/Requests/POST
 */

defined( 'ABSPATH' ) || exit;

/**
 * KP_Create_HPP class.
 */
class KP_Create_HPP extends KP_Requests_Post {
	/**
	 * Class constructor.
	 *
	 * @param array $arguments The request arguments.
	 */
	public function __construct( $arguments ) {
		parent::__construct( $arguments );

		$this->log_title      = 'Create HPP';
		$this->request_filter = 'wc_klarna_payments_create_hpp_args';
		$this->endpoint       = 'hpp/v1/sessions';
	}

	/**
	 * Get the body for the request.
	 *
	 * @return array
	 */
	protected function get_body() {
		$base_url    = $this->config['base_url'];
		$session_id  = $this->arguments['session_id'];
		$order       = wc_get_order( $this->arguments['order_id'] );
		$success_url = add_query_arg(
			array(
				'sid'                 => '{{session_id}}',
				'authorization_token' => '{{authorization_token}}',
			),
			$order->get_checkout_order_received_url()
		);

		return array(
			'payment_session_url' => "{$base_url}payments/v1/sessions/$session_id",
			'merchant_urls'       => array(
				'success' => $success_url,
				'cancel'  => wc_get_checkout_url(), // TODO - Handle messages?
				'back'    => wc_get_checkout_url(),
				'failure' => wc_get_checkout_url(), // TODO - Handle messages?
				'error'   => wc_get_checkout_url(), // TODO - Handle messages?
			),
		);
	}
}