2016-03-03 1 views
0

J'utilise this plugin dans une application CakePHP. Tout semble fonctionner, sauf l'envoi de courriels.CakePHP Paypal IPN Plugin email ne fonctionne pas

J'ai le code suivant dans AppController.php

function afterPaypalNotification($txnId) 
{ 
    //Here is where you can implement code to apply the transaction to your app. 
    //for example, you could now mark an order as paid, a subscription, or give the user premium access. 
    //retrieve the transaction using the txnId passed and apply whatever logic your site needs. 

    $transaction = ClassRegistry::init('PaypalIpn.InstantPaymentNotification')->findById($txnId); 
    $this->log($transaction['InstantPaymentNotification']['id'], 'paypal'); 

    //Tip: be sure to check the payment_status is complete because failure 
    //  are also saved to your database for review. 

    if ($transaction['InstantPaymentNotification']['payment_status'] == 'Completed') 
    { 
     //Yay! We have monies! 
     ClassRegistry::init('PaypalIpn.InstantPaymentNotification')->email(array(
      'id' => $txnId, 
      'subject' => 'Thanks!', 
      'message' => 'Thank you for the transaction!' 
     )); 
    } 
    else 
    { 
     //Oh no, better look at this transaction to determine what to do; like email a decline letter. 
     ClassRegistry::init('PaypalIpn.InstantPaymentNotification')->email(array(
      'id' => $txnId, 
      'subject' => 'Failed!', 
      'message' => 'Please review your transaction' 
     )); 
    } 
} 

Mais les données renvoyées par Paypal est enregistré dans la table instant_payment_notifications mais pour une raison quelconque les e-mails ne sont pas envoyés. Est-ce que quelqu'un a déjà essayé ce plugin et est-ce que la fonctionnalité de messagerie fonctionne? Dois-je activer email.php dans app/Config pour que les e-mails fonctionnent? J'ai lu quelque part sur le site Web de Cake que je n'ai pas besoin de ce fichier pour que les courriels fonctionnent, donc je suppose que ce n'est pas là où le problème est.

Toute aide sera appréciée.

Merci.

Répondre

0

CakePHP 2.5, vous devez utiliser CakeEmail

Créer le fichier /app/Config/email.php avec la classe EmailConfig. Le /app/Config/email.php.default a un exemple de ce fichier.

Ajouter ligne suivante dans /app/Controller/AppController.php avant la déclaration de classe

App::uses('CakeEmail', 'Network/Email'); 

En fonction afterPaypalNotification remplacer

ClassRegistry::init('PaypalIpn.InstantPaymentNotification')->email(array(
    'id' => $txnId, 
    'subject' => 'Thanks!', 
    'message' => 'Thank you for the transaction!' 
)); 

avec (e-mail rapide, pas de style)

CakeEmail::deliver('[email protected]', 'Thanks!', 'Thank you for the transaction!', array('from' => '[email protected]')); 

ou

$Email = new CakeEmail(); 
$Email->template('email_template', 'email_layout') 
    ->emailFormat('html') 
    ->to('[email protected]') 
    ->from('[email protected]') 
    ->viewVars(array('id' => $txnId)) 
    ->send(); 

modèle e-mail va /app/View/Emails/html/email_template.ctp

mises en page Email va /app/View/Layouts/Emails/html/email_layout.ctp