duandie5707 2014-12-13 18:47
浏览 122

Prestashop支付模块

I am currently writing a Prestashop Payment module which uses the Paypal Adaptive Payments SDK. When I try to install my module, I get the following error:

[PrestaShop] Fatal error in module Configuration:
Cannot redeclare class Configuration

here is my code. the paypal sdk is installed correctly and working.

config.xml

<?xml version="1.0" encoding="UTF-8" ?>
     <module>
     <name>MyPayments</name>
     <displayName><![CDATA[My module]]></displayName>
     <version><![CDATA[1.0]]></version>
     <description><![CDATA[Description of my module.]]></description>
     <author></author>
     <tab><![CDATA[payments_gateways]]></tab>
     <confirmUninstall>Are you sure you want to uninstall? You will lose all your settings!</confirmUninstall>
     <is_configurable>0</is_configurable>
     <need_instance>0</need_instance>
     <limited_countries></limited_countries>
</module>

mypayments.php

<?php
if (!defined('_PS_VERSION_'))
  exit;

//include paypal adaptive payments sdk lib  
require(_PS_MODULE_DIR_.'/mypayments/samples/PPBootStrap.php');

class MyPayments extends PaymentModule { 

    public function __construct() {

        $this->name = 'mypayments';
        $this->tab = 'payments_gateways';
        $this->version = '0.1';
        $this->need_instance = 0;
        $this->ps_versions_compliancy = array('min' => '1.5', 'max' => '1.6');
        $this->bootstrap = true;

        parent::__construct();

        #$this->page = basename(__FILE__, '.php');
        $this->displayName = $this->l('Adaptive Payments');
        $this->description = $this->l('Paypal Adaptive Payments');

        $this->confirmUninstall = $this->l('Are you sure you want to uninstall?');

        if (!Configuration::get('MYMODULE_NAME'))      
          $this->warning = $this->l('No name provided');
    }

    public function install() {
        if (!parent::install()
        OR !$this->registerHook('payment') 
        OR !Configuration::updateValue('MYMODULE_NAME', 'My Payments')
        )
        return false;
        return true;
    }

    public function uninstall() {
        if (!parent::uninstall() ||
            !Configuration::deleteByName('MYMODULE_NAME') 
            )
            return false;
        return true;
    }

//output the current payment method to the choice list of available methods on the checkout pages
    function hookPayment($params){

        if(!$this->active) return;

        global $smarty;

        //checks if all products in cart are valid
        foreach ($params['cart']->getProducts() AS $product)
        if (Validate::isUnsignedInt(ProductDownload::getIdFromIdProduct(intval($product['id_product']))))
            return false;

        //assign smarty paths
        $smarty->assign(array( 
            'this_path' => $this->_path,
            'this_path_ssl' => (Configuration::get('PS_SSL_ENABLED') ? 'https://' :'http://').htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8').__PS_BASE_URI__.'modules/'.$this->name.'/'
            ));

        //return the template file to render the payment option
        return $this->display(__FILE__, 'payment.tpl');  
    }

    public function paypalPayCall($Email1, $Email2, $totalAmount){

        $Email3;

        $Payment1 = $totalAmount/2;
        $Payment2 = $totalAmount/4;
        $Payment3 = $totalAmount/4;


        $payRequest = new PayRequest();

            $receiver = array();
            $receiver[0] = new Receiver();
            $receiver[0]->amount = $Payment1;
            $receiver[0]->email = $Email1;
            $receiver[0]->primary = "true";

            $receiver[1] = new Receiver();
            $receiver[1]->amount = $Payment2;
            $receiver[1]->email = $Email2;

            $receiver[2] = new Receiver();
            $receiver[2]->amount = $Payment3;
            $receiver[2]->email = $Email3;

            $receiverList = new ReceiverList($receiver);
            $payRequest->receiverList = $receiverList;

            $requestEnvelope = new RequestEnvelope("en_US");
            $payRequest->requestEnvelope = $requestEnvelope; 
            $payRequest->actionType = "PAY";
            $payRequest->cancelUrl = "http://www.google.at/";
            $payRequest->returnUrl = dirname(__FILE__)."validation.php";
            $payRequest->currencyCode = "EUR";


        //CONFIGURATION - now sandbox
        $sdkConfig = array(
            "mode" => "sandbox",
            "acct1.UserName" => "xxx",
            "acct1.Password" => "xxx",
            "acct1.Signature" => "xxx",
            "acct1.AppId" => "xxx"
        );

        /* the payment call */
        $adaptivePaymentsService = new AdaptivePaymentsService($sdkConfig);
        $payResponse = $adaptivePaymentsService->Pay($payRequest); 

        //read response
        $response = json_decode($payResponse);
        $payKey = $response->payKey;

        //check if acknowledged
        if (strtoupper($response->responseEnvelope->ack) == 'SUCCESS')
            {
                $payUrl = "https://www.sandbox.paypal.com/webscr?cmd=_ap-payment&paykey=" . $payKey;
                return $payUrl;
            }
            else
            {
                return false;
            }
    }


}
?>

payment.php

<?php

include(dirname(__FILE__).'/../../config/config.inc.php');
include(dirname(__FILE__).'/../../header.php');
include(dirname(__FILE__).'/mypayments.php');

if (!$cookie->isLogged())
    Tools::redirect('authentication.php?back=order.php');

$paypalImgUrl = dirname(__FILE__).'/img/default_logos/default_logo.gif';

//create new instance of my payment class
$myPayments = new MyPayments(); 

//get cart total
$total = floatval(number_format($cart->getOrderTotal(true, 3), 2, '.', ''));

$Email1;
$Email2;

//call method from my payment class
$payUrl = $myPayments->paypalPayCall($Email1, $Email2, $total);

if ($payUrl == false)
{
    echo "<center>Error generating payment link</center>";
}
else
{
    //show link to buy with paypal
    echo '<center><a href="'.$payUrl.'"><img src="'.$paypalImgUrl.'" alt="Pay with Paypal"/></a></center>';
}

include_once(dirname(__FILE__).'/../../footer.php');

?>

validation.php

<?php
//PAYPALS RETURN URL REDIRECTS HERE TO VALIDATE AND PLACE THE ORDER

include(dirname(__FILE__).'/../../config/config.inc.php');
include(dirname(__FILE__).'/../../header.php');
include(dirname(__FILE__).'/mypayments.php');


$total = floatval(number_format($cart->getOrderTotal(true, 3), 2, '.', ''));
$myPayments->validateOrder(intval($cart->id), _PS_OS_PREPARATION_, $total, $myPayments->displayName);
$order = new Order(intval($myPayments->currentOrder));

echo "<center> Thank you! Your order is being processed </center>";

include(dirname(__FILE__).'/../../footer.php');

?>

payment.tpl

<p class="payment_module">

<a href="{$this_path}payment.php" title="{l s='Pay with Paypal' mod='mypayments'}">

<img src="{$this_path}paypal.png" alt="{l s='Pay with Paypal' mod='mypayments'}" />

{l s='Pay with Paypal' mod='mypayments'}

</a>
</p>

Any help is much appreciated!

  • 写回答

1条回答 默认 最新

  • doufu8887 2014-12-15 17:32
    关注

    ...the Paypal SDK had its own Configuration class

    very trivial mistake after all -.-

    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看