OpenCart 🇺🇦

Схема

public mixed checkoutReturn ( )

Аргументы

Аргумент Возможный тип Описание
У метода нет аргументов

Описание

Метод пока еще не документирован.

Исходный код

$this->language->load('payment/pp_express');
/**
 * Get the details
 */
$this->load->model('payment/pp_express');
$this->load->model('checkout/order');

$data = array(
	'METHOD' => 'GetExpressCheckoutDetails',
	'TOKEN' => $this->session->data['paypal']['token'],
);

$result = $this->model_payment_pp_express->call($data);
$this->session->data['paypal']['payerid'] = $result['PAYERID'];
$this->session->data['paypal']['result'] = $result;

$order_id = $this->session->data['order_id'];

$paypal_data = array(
	'TOKEN' => $this->session->data['paypal']['token'],
	'PAYERID' => $this->session->data['paypal']['payerid'],
	'METHOD' => 'DoExpressCheckoutPayment',
	'PAYMENTREQUEST_0_NOTIFYURL' => $this->url->link('payment/pp_express/ipn', '', 'SSL'),
	'RETURNFMFDETAILS' => 1,
);

$paypal_data = array_merge($paypal_data, $this->model_payment_pp_express->paymentRequestInfo());

$result = $this->model_payment_pp_express->call($paypal_data);

if($result['ACK'] == 'Success') {
	//handle order status
	switch($result['PAYMENTINFO_0_PAYMENTSTATUS']) {
		case 'Canceled_Reversal':
			$order_status_id = $this->config->get('pp_express_canceled_reversal_status_id');
			break;
		case 'Completed':
			$order_status_id = $this->config->get('pp_express_completed_status_id');
			break;
		case 'Denied':
			$order_status_id = $this->config->get('pp_express_denied_status_id');
			break;
		case 'Expired':
			$order_status_id = $this->config->get('pp_express_expired_status_id');
			break;
		case 'Failed':
			$order_status_id = $this->config->get('pp_express_failed_status_id');
			break;
		case 'Pending':
			$order_status_id = $this->config->get('pp_express_pending_status_id');
			break;
		case 'Processed':
			$order_status_id = $this->config->get('pp_express_processed_status_id');
			break;
		case 'Refunded':
			$order_status_id = $this->config->get('pp_express_refunded_status_id');
			break;
		case 'Reversed':
			$order_status_id = $this->config->get('pp_express_reversed_status_id');
			break;
		case 'Voided':
			$order_status_id = $this->config->get('pp_express_voided_status_id');
			break;
	}

	$this->model_checkout_order->confirm($order_id, $order_status_id);

	//add order to paypal table
	$paypal_order_data = array(
		'order_id' => $order_id,
		'capture_status' => ($this->config->get('pp_express_method') == 'Sale' ? 'Complete' : 'NotComplete'),
		'currency_code' => $result['PAYMENTINFO_0_CURRENCYCODE'],
		'authorization_id' => $result['PAYMENTINFO_0_TRANSACTIONID'],
		'total' => $result['PAYMENTINFO_0_AMT'],
	);
	$paypal_order_id = $this->model_payment_pp_express->addOrder($paypal_order_data);

	//add transaction to paypal transaction table
	$paypal_transaction_data = array(
		'paypal_order_id' => $paypal_order_id,
		'transaction_id' => $result['PAYMENTINFO_0_TRANSACTIONID'],
		'parent_transaction_id' => '',
		'note' => '',
		'msgsubid' => '',
		'receipt_id' => (isset($result['PAYMENTINFO_0_RECEIPTID']) ? $result['PAYMENTINFO_0_RECEIPTID'] : ''),
		'payment_type' => $result['PAYMENTINFO_0_PAYMENTTYPE'],
		'payment_status' => $result['PAYMENTINFO_0_PAYMENTSTATUS'],
		'pending_reason' => $result['PAYMENTINFO_0_PENDINGREASON'],
		'transaction_entity' => ($this->config->get('pp_express_method') == 'Sale' ? 'payment' : 'auth'),
		'amount' => $result['PAYMENTINFO_0_AMT'],
		'debug_data' => json_encode($result),
	);
	$this->model_payment_pp_express->addTransaction($paypal_transaction_data);

	$recurring_products = $this->cart->getRecurringProducts();

	//loop through any products that are recurring items
	if(!empty($recurring_products)) {

		$this->load->model('checkout/recurring');

		$billing_period = array(
			'day' => 'Day',
			'week' => 'Week',
			'semi_month' => 'SemiMonth',
			'month' => 'Month',
			'year' => 'Year'
		);

		foreach($recurring_products as $item) {
			$data = array(
				'METHOD' => 'CreateRecurringPaymentsProfile',
				'TOKEN' => $this->session->data['paypal']['token'],
				'PROFILESTARTDATE' => gmdate("Y-m-d\TH:i:s\Z", mktime(gmdate("H"), gmdate("i")+5, gmdate("s"), gmdate("m"), gmdate("d"), gmdate("y"))),
				'BILLINGPERIOD' => $billing_period[$item['recurring_frequency']],
				'BILLINGFREQUENCY' => $item['recurring_cycle'],
				'TOTALBILLINGCYCLES' => $item['recurring_duration'],
				'AMT' => $this->currency->format($this->tax->calculate($item['recurring_price'], $item['tax_class_id'], $this->config->get('config_tax')), false, false, false) * $item['quantity'],
				'CURRENCYCODE' => $this->currency->getCode(),
			);

			//trial information
			if($item['recurring_trial'] == 1) {
				$data_trial = array(
					'TRIALBILLINGPERIOD' => $billing_period[$item['recurring_trial_frequency']],
					'TRIALBILLINGFREQUENCY' => $item['recurring_trial_cycle'],
					'TRIALTOTALBILLINGCYCLES' => $item['recurring_trial_duration'],
					'TRIALAMT' => $this->currency->format($this->tax->calculate($item['recurring_trial_price'], $item['tax_class_id'], $this->config->get('config_tax')), false, false, false) * $item['quantity'],
				);

				$trial_amt = $this->currency->format($this->tax->calculate($item['recurring_trial_price'], $item['tax_class_id'], $this->config->get('config_tax')), false, false, false) * $item['quantity'].' '.$this->currency->getCode();
				$trial_text =  sprintf($this->language->get('text_trial'), $trial_amt, $item['recurring_trial_cycle'], $item['recurring_trial_frequency'], $item['recurring_trial_duration']);

				$data = array_merge($data, $data_trial);
			} else {
				$trial_text = '';
			}

			$recurring_amt = $this->currency->format($this->tax->calculate($item['recurring_price'], $item['tax_class_id'], $this->config->get('config_tax')), false, false, false)  * $item['quantity'].' '.$this->currency->getCode();
			$recurring_description = $trial_text.sprintf($this->language->get('text_recurring'), $recurring_amt, $item['recurring_cycle'], $item['recurring_frequency']);

			if($item['recurring_duration'] > 0) {
				$recurring_description .= sprintf($this->language->get('text_length'), $item['recurring_duration']);
			}

			//create new profile and set to pending status as no payment has been made yet.
			$recurring_id = $this->model_checkout_recurring->create($item, $order_id, $recurring_description);

			$data['PROFILEREFERENCE'] = $recurring_id;
			$data['DESC'] = $recurring_description;

			$result = $this->model_payment_pp_express->call($data);

			if(isset($result['PROFILEID'])) {
				$this->model_checkout_recurring->addReference($recurring_id, $result['PROFILEID']);
			} else {
				// there was an error creating the profile, need to log and also alert admin / user


			}
		}
	}

	if(isset($result['REDIRECTREQUIRED']) && $result['REDIRECTREQUIRED'] == true) { //- handle german redirect here
		$this->redirect('https://www.paypal.com/cgi-bin/webscr?cmd=_complete-express-checkout&token='.$this->session->data['paypal']['token']);
	} else {
		$this->redirect($this->url->link('checkout/success'));
	}
} else {

	if ($result['L_ERRORCODE0'] == '10486') {
		if (isset($this->session->data['paypal_redirect_count'])) {

			if ($this->session->data['paypal_redirect_count'] == 2) {
				$this->session->data['paypal_redirect_count'] = 0;
				$this->session->data['error'] = $this->language->get('error_too_many_failures');
				$this->redirect($this->url->link('checkout/checkout', '', 'SSL'));
			} else {
				$this->session->data['paypal_redirect_count']++;
			}
		} else {
			$this->session->data['paypal_redirect_count'] = 1;
		}

		if ($this->config->get('pp_express_test') == 1) {
			$this->redirect('https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=' . $this->session->data['paypal']['token']);
		} else {
			$this->redirect('https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=' . $this->session->data['paypal']['token']);
		}
	}

	$this->language->load('payment/pp_express');

	$this->data['breadcrumbs'] = array();

	$this->data['breadcrumbs'][] = array(
		'href' => $this->url->link('common/home'),
		'text' => $this->language->get('text_home'),
		'separator' => false
	);

	$this->data['breadcrumbs'][] = array(
		'href' => $this->url->link('checkout/cart'),
		'text' => $this->language->get('text_cart'),
		'separator' => $this->language->get('text_separator')
	);

	$this->data['heading_title'] = $this->language->get('error_heading_title');

	$this->data['text_error'] = '<div class="warning">'.$result['L_ERRORCODE0'].' : '.$result['L_LONGMESSAGE0'].'</div>';

	$this->data['button_continue'] = $this->language->get('button_continue');

	$this->data['continue'] = $this->url->link('checkout/cart');

	unset($this->session->data['success']);

	$this->response->addHeader($this->request->server['SERVER_PROTOCOL'] . '/1.1 404 Not Found');

	if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) {
		$this->template = $this->config->get('config_template') . '/template/error/not_found.tpl';
	} else {
		$this->template = 'default/template/error/not_found.tpl';
	}

	$this->children = array(
		'common/column_left',
		'common/column_right',
		'common/content_top',
		'common/content_bottom',
		'common/footer',
		'common/header'
	);

	$this->response->setOutput($this->render());
}