Не зарегистрирован
Вход
Забыли пароль?
Регистрация
Подписаться
Сэкономьте время — перед вопросом на форуме узнайте, как найти ответ быстрее
По техническим проблемам необходимо обращаться в Консультационный центр

Поиск по форуму: 

Приглашаем в блог Amiro.CMS. Регулярные обзоры, опыт, решения, практикумы.
Форум  ->   Разработка плагинов, вопросы по API  ->  Платежный драйвер банковской картой- страница с сообщением об успешном заказе


Показать все сообщения в этой ветке


Добавлено: 18.04.17 11:04:51  



Регистрация: 19.01.15
Сообщений: 102


Обратиться по имени

Платежный драйвер выглядит так:

<?php
/**
* @copyright chto to
* @version chto to
* @package   chto to
* @size chto to
* @since   chto to
*/
?>
<?php


/**
 * Example pay driver
 * 
 * How to create your own pay driver:
 * 
 * <ol>
 * <li>Copy the directory "_local/eshop/pay_drivers/example" to another, i.e. "_local/eshop/pay_drivers/my_driver"</li>
 * <li>Open driver.php in your path and:
 * <ul>
 * <li>Rename driver class name to your name (MyDriver_PaymentSystemDriver). Naming rule: all words delimeted by _ should be started from uppercase letter. Not _ allowed in driver name.</li>
 * <li>In some cases you should to check or add some fields when printing payment button on checkout page. You can manipulate with $aData array in getPayButton method for it. The same for pay system button with autoredirect but the method is getPayButtonParams</li>
 * <li>User will come back to the site from payment system by special URL and system already has the checks for setting correct order status. If you want to make your manual checking do it in payProcess method.</li>
 * <li>For payment system background requests for order approving there is payCallback method. You need to override this method with you own check of payment data.</li>
 * <li>If get or post field are differ from order_id, id or item_number you need to override getProcessOrder method that will return valid order id from POST and GET request.</li>
 * </ul>
 * </li>
 * <li>Open driver.tpl and modify sets:
 * <ul>
 * <li>settings_form - part of form that will be insertted to driver form when you open your driver for editing.</li>
 * <li>checkout_form - button that will be shown on checkout page after the list of items. ##hiddens## field is required.</li>
 * <li>pay_form - form that will be submitted to payment system. In most cases this form is made with autoredirect.</li>
 * <li>Also modify path to driver.lng.</li>
 * </ul>
 * </li>
 * <li>Captions for drivers you can set in driver.lng.</li>
 * <li>After all these steps install your driver in Settings/Pay drivers page of admin panel and edit parameters. Then include your diver for the payment in option "Allowed payment drivers" of Catalog : Orders setting.</li>
 * </ol>
 * 
 * @package Driver_PaymentSystem
 */
class Bankname_PaymentSystemDriver extends AMI_PaymentSystemDriver{

	protected $driverName = 'bankname';

    /**
     * Get checkout button HTML form
     *
     * @param array $aRes Will contain "error" (error description, 'Success by default') and "errno" (error code, 0 by default). "forms" will contain a created form
     * @param array $aData The data list for button generation
     * @param bool $bAutoRedirect If form autosubmit required (directly from checkout page)
     * @return bool true if form is generated, false otherwise
     */
    public function getPayButton(&$aRes, $aData, $bAutoRedirect = false){
		//$aRes['error'] = "Success";
		//$aRes['errno'] = 0;
        // Format fields
        foreach(Array("return", "description") as $fldName){
            $aData[$fldName] = htmlspecialchars($aData[$fldName]);
        }
		$aData['amount'] = str_replace(',', '.', floatval($aData['amount']));
        // Disable to process order using example button
        //$aData["disabled"] = "disabled";
        // Set your fields of $aData here
		#$aData['token'] = md5($aData['merchant_id'].$aData['product_id'].$aData['amount'].$aData['order'].$aData['sw']);
		//$bAutoRedirect = true;
		#$post = $_POST;
		#unset($post['get_type']);
		#$post['action'] = 'askparams';
		
		$aData['hiddens'] = '';
		
		$path_www=dirname(__FILE__).'/';
		$order=sprintf("%06u",$aData['order']);
		// Константы test
		//define("MERCHANT_CERT_ID",	"***");	// Серийный номер сертификата 
		//define("MERCHANT_NAME",		"test shop");	// Название магазина (продавца)
		//define("MERCHANT_ID",		"****");			// ID продавца в системе 
		// Константы web
		define("MERCHANT_CERT_ID",	"****");	// Серийный номер сертификата 
		define("MERCHANT_NAME",		"****");	// Название магазина (продавца)
		define("MERCHANT_ID",		"*****");			// ID продавца в системе 
		
		define("ORDER_ID",			$order);		// Уникальный номер заказа
		define("CURRENCY",			"777");			// ID валюты. 840 - USD
		define("AMOUNT", 			$aData['amount']);			// сумма заказа
		
		require_once($path_www."kkb.utils.php");
		$kkb = new KKBSign();
		$kkb->invert();
		//$kkb->load_private_key($path_www."test_prv.pem", "nissan");	// test
		$kkb->load_private_key($path_www."bab.prv", "****");	// web
		// Шаблон заказа
		$merchant = '<merchant cert_id="%certificate%" name="%merchant_name%"><order order_id="%order_id%" amount="%amount%" currency="%currency%"><department merchant_id="%merchant_id%" amount="%amount%" /></order></merchant>';
		$merchant = preg_replace('/\%certificate\%/', 		MERCHANT_CERT_ID , 	$merchant);
		$merchant = preg_replace('/\%merchant_name\%/', 	MERCHANT_NAME , 	$merchant);
		$merchant = preg_replace('/\%order_id\%/', 			ORDER_ID, 			$merchant);
		$merchant = preg_replace('/\%currency\%/', 			CURRENCY, 			$merchant);
		$merchant = preg_replace('/\%merchant_id\%/', 		MERCHANT_ID, 		$merchant);
		$merchant = preg_replace('/\%amount\%/', 			AMOUNT,				$merchant);

		$merchant_sign = '<merchant_sign type="RSA">'.$kkb->sign64($merchant).'</merchant_sign>';
		$xml = "<document>".$merchant.$merchant_sign."</document>";
		$Base64Content= base64_encode($xml);
		$aData['hiddens'] .= '<input type="hidden" name="Signed_Order_B64" value="'.$Base64Content.'">';
		$aData['hiddens'] .= '<input type="hidden" name="Language" value="rus">';
		$aData['hiddens'] .= '<input type="hidden" name="email" value="'.$aData['email'].'">';
		//$aData['hiddens'] .= '<input type="hidden" name="BackLink" value="http://site.ru/zakaz-ok?action=empty">';//http://site.ru/members/order?action=process&status=ok //http://site.ru/zakaz-ok?action=empty //'.$aData['return'].'
		$aData['hiddens'] .= '<input type="hidden" name="BackLink" value="'.$aData['return'].'">';
		$aData['hiddens'] .= '<input type="hidden" name="PostLink" value="http://site.ru/_local/eshop/pay_drivers/bankname/answer.php">';

        return parent::getPayButton($aRes, $aData, $bAutoRedirect);
    }
    
    /**
     * Get the form that will be autosubmitted to payment system. This step is required for some shooping cart actions.
     *
     * @param array $aData The data list for button generation
     * @param array $aRes Will contain "error" (error description, 'Success by default') and "errno" (error code, 0 by default). "forms" will contain a created form
     * @return bool true if form is generated, false otherwise
     */
    public function getPayButtonParams($aData, &$aRes){
        // Check parameters and set your fields here
		//$aRes['error'] = "Success";
		//$aRes['errno'] = 0;
		//$aData['amount'] = str_replace(',', '.', floatval($aData['amount']));
        return parent::getPayButtonParams($aData, $aRes);
    }

    /**
     * Verify the order from user back link. In success case 'accepted' status will be setup for order.
     *
     * @param array $aGet $_GET data
     * @param array $aPost $_POST data
     * @param array $aRes reserved array reference
     * @param array $aCheckData Data that provided in driver configuration
     * @return bool true if order is correct and false otherwise
     * @see AMI_PaymentSystemDriver::payProcess(...)
     */
    public function payProcess($aGet, $aPost, &$aRes, $aCheckData, $aOrderData){
        // See implplementation of this method in parent class

		#$amount = str_replace(',', '.', floatval($aOrderData['total']));
		#if($aGet['token']!=md5($aCheckData['merchant_id'].$aCheckData['product_id'].$amount.$aGet['order_id'].$aCheckData['sw'])) return false;

		return parent::payProcess($aGet, $aPost, $aRes, $aCheckData, $aOrderData);
    }

    /**
     * Verify the order by payment system background responce. In success case 'confirmed' status will be setup for order.
     *
     * @param array $aGet $_GET data
     * @param array $aPost $_POST data
     * @param array $aRes reserved array reference
     * @param array $aCheckData Data that provided in driver configuration
     * @return int -1 - ignore post, 0 - reject(cancel) order, 1 - confirm order
     * @see AMI_PaymentSystemDriver::payCallback(...)
     */
    public function payCallback($aGet, $aPost, &$aRes, $aCheckData, $aOrderData){
        // See implplementation of this method in parent class
		return parent::payCallback($aGet, $aPost, $aRes, $aCheckData, $aOrderData);
    }

    /**
     * Return real system order id from data that provided by payment system.
     *
     * @param array $aGet $_GET data
     * @param array $aPost $_POST data
     * @param array $aRes reserved array reference
     * @param array $aAdditionalParams reserved array
     * @return int order Id
     * @see AMI_PaymentSystemDriver::getProcessOrder(...)
     */
    public function getProcessOrder($aGet, $aPost, &$aRes, $aAdditionalParams){
        // See implplementation of this method in parent class

        return parent::getProcessOrder($aGet, $aPost, $aRes, $aAdditionalParams);
    }
}





0


Создать новую тему Ответить