Help for payment plugin

Discussion in 'aMember Pro v.4' started by fmagusto, Feb 7, 2012.

  1. fmagusto

    fmagusto Guest

    I try to make a plugin Payment and i have this error
    Subscriptions terms in the IPN does not match subscription terms in our Invoice

    xception Am_Exception_Paysystem_TransactionInvalid
    Am_Paysystem_Transaction_Incoming->validate [ library/Am/Paysystem/Transaction/Abstract.php : 46 ]
    Am_Paysystem_Transaction_Abstract->process [ library/Am/Paysystem/Transaction/Incoming.php : 228 ]
    Am_Paysystem_Transaction_Incoming->process [ library/Am/Paysystem/Abstract.php : 444 ]
    Am_Paysystem_Abstract->directAction [ application/default/plugins/payment/swreg.php : 139 ]
    Am_Paysystem_Swreg->directAction [ application/default/controllers/DirectController.php : 35 ]
    DirectController->__call [ library/Am/Controller.php : 118 ]
    Am_Controller->dispatch [ library/Zend/Controller/Dispatcher/Standard.php : 295 ]
    Zend_Controller_Dispatcher_Standard->dispatch [ library/Zend/Controller/Front.php : 954 ]
    Zend_Controller_Front->dispatch [ library/Am/App.php : 1374 ]
    Am_App->run [ index.php : 41 ]
  2. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Check public function validateTerms in your Am_Paysystem_Transaction_Incoming child class.
    Above function should check incomming IPN message payment terms, and return true if everything is correct.

  3. fmagusto

    fmagusto Guest

    My validate term is empty :

    public function validateTerms() {
    // compare our invoice payment settings, and what payment system handled
    // if there is difference, it is possible that redirect url was modified
    // before payment
    //$invoice->first_total=$invoice->first_total*100;
    //return ($this->request->get('montant') == $this->invoice->first_total);
    return true;
    }
  4. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Please copy full plugin code here.
  5. fmagusto

    fmagusto Guest

    Ok this is

    <?php
    class Am_Paysystem_Swreg2 extends Am_Paysystem_Abstract
    {
    const PLUGIN_STATUS = self::STATUS_DEV;
    const PLUGIN_REVISION = '0.2';

    const URL = "xxxxxxxxxxxxxxx/cgi-bin/modulev2.cgi";
    const TESTING_URL = "xxxxxxxxxxxxxxxxxxx/cgi-bin/modulev2.cgi";
    const MODE_LIVE = 'live';
    const MODE_SANDBOX = 'sandbox';
    const MODE_TEST = 'test';


    protected $defaultTitle = 'Paybox';
    protected $defaultDescription = 'Carte bancaire sécurisée';
    public function _initSetupForm(Am_Form_Setup $form) {
    $s = $form->addSelect("testing")
    ->setLabel("test Mode Enabled");
    $s->addOption("Live account", self::MODE_LIVE);
    $s->addOption("Sandbox account", self::MODE_SANDBOX);
    // $s->addOption("Account in test mode", self::MODE_TEST);
    }
    public function getSupportedCurrencies()
    {
    return array(
    'EUR');
    }
    public function init()
    {
    parent::init();
    $this->getDi()->billingPlanTable->customFields()
    ->add(new Am_CustomFieldText('plimus_contract_id', "Nombre de paiement 1 pour 1 fois, et 3 pour Fois",
    "(les autres ne sont pas progammés, mais à voir pour mettre 2 fois par exemple"));
    }
    public function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result)
    {

    $a = new Am_Paysystem_Action_Redirect((($this->getConfig('testing')==self::MODE_SANDBOX) ? self::TESTING_URL : self::URL));
    $a->contract_id = $invoice->getItem(0)->getBillingPlanData("plimus_contract_id");
    $a->custom1 = $invoice->public_id;
    $a->member_id = $invoice->user_id;
    $a->invoice_id = $invoice->invoice_id;

    if ($a->contract_id > 1){
    $prixpaybox = ($invoice->first_total*100);
    $a->PBX_CMD = "custom1=$a->custom1&prix=$prixpaybox&r=$a->member_id&pr=$invoice->first_total&o=$a->invoice_id&ret=http://xxxxxxxx/amember&nom=$a->Nom";

    $now = time();
    $dans_1_mois = mktime(0,0,0,date("m" ) + 1 ,date("d" ) ,date("Y" ));
    $dans_2_mois = mktime(0,0,0,date("m" ) + 2 ,date("d" ) ,date("Y" ));
    $date1 = date("d/m/Y", $dans_1_mois);
    $date2 = date("d/m/Y", $dans_2_mois);

    $a->PBX_2MONT1 = $prixpaybox;
    $a->PBX_DATE1 = $date1;
    $a->PBX_2MONT2 = $prixpaybox ;
    $a->PBX_DATE2 = $date2;

    }else {
    $prixpaybox=$invoice->first_total*100;
    $a->PBX_CMD = "custom1=$a->custom1&prix=$prixpaybox&r=$a->member_id&pr=$prixpaybox&o=$a->invoice_id&ret=http://xxxxxxx/amember&nom=$a->Nom";
    }
    $o = $invoice->invoice_id;
    $a->currency = $this->getCurrencyCode();
    $a->Nom= $invoice->getFirstName();
    $a->Prenom = $invoice->getLastName();
    $a->PBX_PORTEUR = $invoice->getEmail();
    $a->PBX_MODE = "1";
    $a->PBX_SITE = "5864408";
    $a->PBX_RANG = "01";
    $a->PBX_IDENTIFIANT = "58644081";
    $a->PBX_TOTAL = $prixpaybox;
    $a->PBX_WAIT = "0";
    $a->PBX_DEVISE = "978";
    $a->PBX_RETOUR = "montant:M;ref:R;auto:A;trans:T;numabo:B,datefin:D";
    $a->PBX_EFFECTUE = "http://xxxxxx/amember/payment/swreg2/ipn";
    $a->PBX_REFUSE = "http://xxxxxxxx/amember/content/p/id/3/";
    $a->PBX_ANNULE = "http://xxxxxxx/amember/signup";
    $a->filterEmpty();
    $result->setAction($a);
    }

    public function getRecurringType()
    {
    return self::REPORTS_NOT_RECURRING;
    }
    public function getReadme()
    {
    $ipn = $this->getPluginUrl('ipn');
    $refund = $this->getPluginUrl('refund');
    return <<<CUT
    Swreg2 payment plugin installation
    1. In Swreg2 control panel, create a bundle product and enable
    variable pricing for it.
    2. In Swreg2 control panel, set
    Keygen routine URL to
    $ipn
    Refund reporting URL to
    $refund
    4. Configure Swreg2 plugin at aMember CP -> Setup -> Swreg2

    CUT;
    }
    public function createTransaction(Am_Request $request, Zend_Controller_Response_Http $response, array $invokeArgs)
    {
    return new Am_Paysystem_Transaction_Swreg2_Order($this, $request, $response, $invokeArgs);
    }

    function getCurrencyCode()
    {
    return strtoupper($this->invoice->currency);
    }
    public function directAction(Am_Request $request, Zend_Controller_Response_Http $response, array $invokeArgs) {
    echo "<softshop></softshop>"; ob_flush();
    if ($request->getActionName() == 'refund')
    return $this->refundAction($request, $response, $invokeArgs);
    else
    parent::directAction($request, $response, $invokeArgs);
    }
    public function refundAction(Am_Request $request, Zend_Controller_Response_Http $response, array $invokeArgs)
    {
    $log = $this->logRequest($request);
    $transaction = new Am_Paysystem_Transaction_Swreg2_Refund($this, $request, $response, $invokeArgs);
    $transaction->setInvoiceLog($log);
    try {
    $transaction->process();
    } catch (Exception $e) {
    throw $e;
    $this->getDi()->errorLogTable->logException($e);
    throw Am_Exception_InputError(___("Error happened during transaction handling. Please contact website administrator"));
    }
    $log->setInvoice($transaction->getInvoice())->update();
    }
    }
    abstract class Am_Paysystem_Transaction_Swreg2 extends Am_Paysystem_Transaction_Incoming
    {
    public function validateSource()
    {
    $this->_checkIp($this->plugin->getConfig('ip'));
    if ($this->plugin->getConfig('product_id') != $this->request->get('pc'))
    throw new Am_Exception_Paysystem_TransactionInvalid("Wrong [pc] passed, this transaction is not related to aMember?");
    return true;
    }
    public function validateStatus()
    {
    return true;
    }
    public function validateTerms()
    {
    return true;
    }
    }
    class Am_Paysystem_Transaction_Swreg2_Order extends Am_Paysystem_Transaction_Swreg2
    {
    public function findInvoiceId(){
    return $this->request->getFiltered('r');
    }

    public function getUniqId() {
    return $this->request->get("o");
    }

    public function validateSource() {
    // there must be some code to validate if IPN came from payment system, and not from a "hacker"
    return true;
    }
    public function validateStatus() {
    // there must be code to check post variables and confirm that the post indicates successful payment transaction
    return true;
    }

    public function processValidated()
    {
    $this->invoice->addPayment($this);
    }
    public function validateTerms()
    {
    return $this->request->get('pp') == $this->invoice->first_total;
    }
    }
    class Am_Paysystem_Transaction_Swreg2_Refund extends Am_Paysystem_Transaction_Swreg2
    {
    public function findInvoiceId()
    {
    $invoice = Am_Di::getInstance()->invoiceTable->findByReceiptIdAndPlugin($this->getReceiptId(), $this->plugin->getId());
    if ($invoice) return $invoice->public_id;
    }
    public function getUniqId()
    {
    return $this->request->get('order_no');
    }
    public function processValidated()
    {
    $this->invoice->addRefund($this, $this->getReceiptId());
    echo "<softshop></softshop>";
    }
    public function validateSource()
    {
    return true;
    }
    }
  6. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Please check debug info that you've included in your first message:
    Am_Paysystem_Abstract->directAction [ application/default/plugins/payment/swreg.php : 139 ]
    Am_Paysystem_Swreg->directAction [ application/default/controllers/DirectController.php : 35 ]
    As you can see IPN action was handled by swreg.php (I believe by original SWREG plugin).
    Your plugin class have this name
    class Am_Paysystem_Swreg2
    So I guess you have that plugin in
    application/default/plugins/payment/swreg2.php correct?
    What is url where IPN messages where received? You should have this info in Error log for each log message.

Share This Page