Esempio n. 1
1
 /**
  * Return the paid amount converted from cents (or currency equivalent) to a decimal value
  * @return float
  */
 function getFloatAmount()
 {
     $currency = VadsApi::findCurrencyByNumCode($this->get('currency'));
     return $currency->convertAmountToFloat($this->get('amount'));
 }
Esempio n. 2
1
	/**
	 * Check PayZen response, save order and empty cart (if payment success) when server notification is received from payment platform.
	 *
	 * @param string $return_context session id
	 * @param int    $virtuemart_order_id virtuemart order primary key concerned by payment
	 * @param string $new_status new order status
	 * @return
	 */
	function plgVmOnPaymentNotification () {
		// platform params and payment data
		$data = JRequest::get ('post');

		$this->logInfo ('plgVmOnPaymentNotification START ', 'error');
		if (!array_key_exists ('vads_order_id', $data) || !isset($data['vads_order_id'])) {
			$this->logInfo ('plgVmOnPaymentNotification -- Another method was selected, do nothing : ', 'error');

			return NULL; // Another method was selected, do nothing
		}

		// Retrieve order info from database
		if (!class_exists ('VirtueMartModelOrders')) {
			require(JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'orders.php');
		}

		$virtuemart_order_id = VirtueMartModelOrders::getOrderIdByOrderNumber ($data['vads_order_id']);
		// Order not found
		/*
			  if (!$virtuemart_order_id) {
			  $this->logInfo('plgVmOnPaymentNotification -- payment check attempted on non existing order : ' . $resp->get('order_id'), 'error');

			  $response .= '<span style="display:none">OK-';
			  $response .= $data['vads_hash'];
			  $response .= "=Impossible de retrouver la commande\n";
			  $response .= '</span>';

			  die($response);
			  }
			 */

		// Payment params
		$payment_data = $this->getDataByOrderId ($virtuemart_order_id);
		/*
			  if (!$payment_data || !($payment = $this->getPaymentMethod($payment_data->payment_method_id))) {
			  $this->logInfo('plgVmOnPaymentNotification -- payment data not found: exit ', 'ERROR');

			  $response .= '<span style="display:none">OK-';
			  $response .= $data['vads_hash'];
			  $response .= "=Méthode de paiement introuvable\n";
			  $response .= '</span>';

			  die($response);
			  }
			 */
		$method = $this->getVmPluginMethod ($payment_data->virtuemart_paymentmethod_id);
		if (!$this->selectedThisElement ($method->payment_element)) {
			return FALSE;
		}

		$this->_debug = $method->debug;
		$custom = $this->_name . '_custom';
		$return_context = $payment_data->$custom;

		// Load API
		if (!class_exists ('VadsApi')) {
			require(JPATH_VMPAYMENTPLUGIN . DS . 'payzen' . DS . 'payzen_api.php');
		}

		$api = new VadsApi();
		$resp = $api->getResponse (
			$data, $method->ctx_mode, $method->key_test, $method->key_prod
		);

		if (!$resp->isAuthentified ()) {
			$this->logInfo ('plgVmOnPaymentNotification -- suspect request sent to plgVmOnPaymentNotification, IP : ' . $_SERVER['REMOTE_ADDR'], 'error');

			die($resp->getOutputForGateway ('auth_fail'));
		}

		$order = VirtueMartModelOrders::getOrder ($virtuemart_order_id);
		$order_status_code = $order['items'][0]->order_status;

		// Order not processed yet
		if ($order_status_code == 'P') {
			if ($resp->isAcceptedPayment ()) {
				$currency = $api->findCurrencyByNumCode ($resp->get ('currency'))->alpha3;
				$amount = ($resp->get ('amount') / 100) . ' ' . $currency;

				$new_status = $method->order_success_status;

				$this->logInfo ('plgVmOnPaymentNotification -- payment process OK, ' . $amount . ' paid for order ' . $resp->get ('order_id') . ', new status ' . $new_status, 'message');
				echo ($resp->getOutputForGateway ('payment_ok'));
			}
			else {
				$new_status = $method->order_failure_status;

				$this->logInfo ('plgVmOnPaymentNotification -- payment process error ' . $resp->message . ', new status ' . $new_status, 'ERROR');
				echo ($resp->getOutputForGateway ('payment_ko'));
			}

			// Save platform response
			$this->managePaymentResponse ($virtuemart_order_id, $resp, $new_status, $return_context);
		}
		else {
			// Order already processed
			if ($resp->isAcceptedPayment ()) {
				echo ($resp->getOutputForGateway ('payment_ok_already_done'));
			}
			else {
				echo ($resp->getOutputForGateway ('payment_ko_on_order_ok'));
			}
		}

		die();
	}