当前位置: 首页>>代码示例>>PHP>>正文


PHP Paypal::validateIPN方法代码示例

本文整理汇总了PHP中Paypal::validateIPN方法的典型用法代码示例。如果您正苦于以下问题:PHP Paypal::validateIPN方法的具体用法?PHP Paypal::validateIPN怎么用?PHP Paypal::validateIPN使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Paypal的用法示例。


在下文中一共展示了Paypal::validateIPN方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: action_registrationPaypalIPN

 public function action_registrationPaypalIPN()
 {
     $config = Kohana::config('ecmproject');
     $data = array();
     Kohana::$log->add(Log::DEBUG, "REQUEST_URI: " . $_SERVER['REQUEST_URI']);
     $p = new Paypal();
     $emailAddr = "";
     $passes = array();
     $currentRegs = array();
     try {
         $p->validateIPN();
         $data = $_POST;
         $total_items = 1;
         if (isset($data['num_cart_items'])) {
             $total_items = $data['num_cart_items'];
         } else {
             while (isset($data['item_number' . $total_items + 1])) {
                 $total_items++;
             }
         }
         foreach (range(1, $total_items) as $count) {
             if (!isset($data['item_number' . $count]) || strpos($data['item_number' . $count], "|") === FALSE) {
                 Kohana::$log->add(Log::ERROR, "[PAYPAL] unable to find item {$count} - " . var_export($_POST, 1));
                 break;
             }
             list($reg_id, $pass_id) = explode('|', $data['item_number' . $count]);
             Kohana::$log->add(Log::NOTICE, "[PAYPAL] Starting {$count} - {$reg_id}/{$pass_id}");
             $reg = ORM::Factory('registration');
             $ret = $reg->with('convention')->with('account')->where('registrations.id', '=', $reg_id)->find();
             if (!$reg->loaded()) {
                 Kohana::$log->add(Log::ERROR, "[PAYPAL] processing {$count} - Unable to load {$reg_id}");
                 continue;
             }
             /* To make sure they paid the right one */
             if ($reg->pass_id != $pass_id) {
                 $passes[$pass_id] = ORM::Factory('Pass', $pass_id);
                 $reg->convention_id = $passes[$pass_id]->convention_id;
                 $reg->convention = ORM::Factory('Convention', $reg->convention_id);
                 $reg->pass_id = $pass_id;
                 $reg->pass = $passes[$pass_id];
             } else {
                 if (!isset($passes[$pass_id])) {
                     $passes[$pass_id] = ORM::Factory('Pass', $pass_id);
                 }
             }
             $payment = ORM::Factory('payment');
             $payment->payer_id = $data['payer_id'];
             $payment->reg_id = $reg_id;
             $payment->type = 'paypal';
             $payment->mc_gross = $data['mc_gross_' . $count];
             $payment->payment_date = strtotime($data['payment_date']);
             /* Fixme - Should be normalized. Payment_Model::paypal_to_status($data['payment_status']); */
             $payment->payment_status = $data['payment_status'];
             $payment->txn_id = $data['txn_id'];
             $payment->receipt_id = "????-????-????-????";
             $payment->mod_time = time();
             $payment->payment_type = 'paypal';
             $payment->save();
             Kohana::$log->add(Log::NOTICE, "[PAYPAL] Finished {$count} - {$reg_id}/{$pass_id}");
             if (strtolower($data['payment_status']) == 'completed') {
                 //Normalize.
                 $payment = floatval($payment->mc_gross);
                 $pass_price = floatval($passes[$pass_id]->price);
                 if ($payment >= $pass_price) {
                     $reg->status = Model_Registration::STATUS_PAID;
                     $data['name'] = $reg->gname . ' ' . $reg->sname;
                     $emailAddr = $reg->account->email;
                     $currentRegs[$reg->convention->id][$reg->convention->name][] = $reg;
                 } else {
                     $reg->status = Model_Registration::STATUS_NOT_ENOUGH;
                 }
             } else {
                 if ($reg->status == Model_Registration::STATUS_UNPROCESSED) {
                     $reg->status = Model_Registration::STATUS_PROCESSING;
                 }
             }
             $reg->save();
         }
     } catch (Exception $e) {
         Kohana::$log->add(Log::ERROR, "[PAYPAL] Error doing stuff: {$e}");
         exit;
     }
     $messageIdOffset = 0;
     foreach (array_keys($currentRegs) as $id) {
         $messageIdOffset++;
         if ($emailAddr && count($currentRegs[$id])) {
             $data['registrations'] = $currentRegs[$id];
             try {
                 $view = new View('convention/reg_success--' . $id, $data);
             } catch (Kohana_View_Exception $e) {
                 Kohana::$log->add(Log::ERROR, "[PAYPAL] convention/reg_success--{$id} was not found: {$e}");
                 $view = new View('convention/reg_success', $data);
             }
             $email = Email::factory($config['registration_subject']);
             $email->from($config['outgoing_email_address'], $config['outgoing_email_name']);
             $email->message($view->render(), 'text/html');
             $email->to($emailAddr);
             $email->send();
         }
     }
//.........这里部分代码省略.........
开发者ID:halkeye,项目名称:ecmproject,代码行数:101,代码来源:paypal.php


注:本文中的Paypal::validateIPN方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。