Ejemplo n.º 1
0
 function process_recurring_postback($vars)
 {
     global $db, $config, $t;
     switch ($vars['txn_type']) {
         case '_xclick-subscriptions':
             if ($vars['payment_status'] != 'Completed') {
                 $this->postback_error(sprintf(_PLUG_PAY_PAYPALR_ERROR6, $vars[payment_status]) . _PLUG_PAY_PAYPALR_ERROR7);
             }
             $invoice = intval($vars['invoice']);
             $payment_id = $this->find_last_payment_id($vars['subscr_id'], $invoice);
             $this->get_lock();
             $p = $db->get_payment($payment_id);
             // it is a first payment for this subscription
             // if !payment written, write to current
             //
             mail('*****@*****.**', 'KERYGMA.TV SUBSCRIPTION PAYMENT', serialize($p));
             //   1. set previous payment expire_date to yesterday
             //   2. add a new payment with
             $p['expire_date'] = date('Y-m-d');
             $db->update_payment($p['payment_id'], $p);
             $this->release_lock();
             $pr = get_product($p[product_id]);
             $newp = array();
             $newp['member_id'] = $p['member_id'];
             $newp['product_id'] = $p['product_id'];
             $newp['paysys_id'] = 'epayph';
             $newp['receipt_id'] = $vars['subscr_id'];
             $newp['begin_date'] = date('Y-m-d');
             $newp['expire_date'] = $pr->get_expire(date('Y-m-d'), 'expire_days');
             $newp['amount'] = $p['amount'];
             $newp['completed'] = 1;
             $newp['data'] = array('txn_id' => $vars['txn_id'], 'epayph_vars' => $p['data']['epayph_vars']);
             $newp['tax_amount'] = $p['data']['epayph_vars']['tax3'];
             $newp['data'][] = $vars;
             $db->add_payment($newp);
             break;
         case 'subscr_signup':
             $this->get_lock();
             $invoice = intval($vars['invoice']);
             $payment = $db->get_payment($invoice);
             if (!$payment['payment_id']) {
                 $invoice = $this->create_new_payment($vars);
                 $payment = $db->get_payment($invoice);
             }
             if ($err = $this->check_periods($vars, $payment)) {
                 $this->postback_error($err);
             }
             // update customer e-mail if option enabled
             if ($this->config['rewrite_email'] && $vars['payer_email'] != '') {
                 $u = $db->get_user($payment['member_id']);
                 if (!$u['data']['epayph_email_rewritten']) {
                     $u['data']['epayph_email_rewritten'] = 1;
                     $u['email'] = $vars['payer_email'];
                     $db->update_user($u['member_id'], $u);
                 }
             }
             if (isset($vars['mc_amount1']) && $vars['mc_amount1'] == 0) {
                 // Free trial period, need to activate payment because next subscr_payment will be sent only for first payment.
                 $err = $db->finish_waiting_payment($invoice, $this->get_plugin_name(), $vars['subscr_id'], $vars['mc_gross'], $vars, $vars['payer_id']);
                 if ($err) {
                     $this->postback_error("finish_waiting_payment error: {$err}");
                 }
                 $payment = $db->get_payment($invoice);
                 $payment['data']['txn_id'] = 'subscr_signup';
                 $db->update_payment($invoice, $payment);
             } else {
                 // Just save IPN message for debug;
                 $payment['data'][] = $vars;
                 $db->update_payment($invoice, $payment);
             }
             // handle transaction
             //                $p = $db->get_payment($invoice);
             //                $p['begin_date']  = date('Y-m-d');
             //                $p['expire_date'] = '2012-12-31';
             //                $db->update_payment($invoice, $p);
             $this->release_lock();
             break;
         case 'subscr_eot':
         case 'subscr_failed':
             $payment_id = $this->find_last_payment_id($vars['subscr_id'], $vars['invoice']);
             if (!$payment_id) {
                 $this->postback_error(_PLUG_PAY_PAYPALR_ERROR11);
             }
             $p = $db->get_payment($payment_id);
             $new_expire = date('Y-m-d', time() - 3600 * 24);
             //yesterday date
             if ($p['expire_date'] && $new_expire < $p['expire_date']) {
                 $p['expire_date'] = $new_expire;
                 if (!$p['data']['failed_orig_expiration']) {
                     $p['data']['failed_orig_expiration'] = $p['expire_date'];
                 }
             }
             $p['data'][] = $vars;
             $db->update_payment($payment_id, $p);
             break;
         case 'subscr_cancel':
             $payment_id = $this->find_last_payment_id($vars['subscr_id'], $vars['invoice']);
             if (!$payment_id) {
                 $this->postback_error(_PLUG_PAY_PAYPALR_ERROR11);
             }
             $p = $db->get_payment($payment_id);
             $p['data'][] = $vars;
             $p['data']['CANCELLED'] = 1;
             $p['data']['CANCELLED_AT'] = strftime($config['time_format'], time());
             $db->update_payment($payment_id, $p);
             if (!$t) {
                 $t =& new_smarty();
             }
             if ($config['mail_cancel_admin']) {
                 $t->assign('user', $db->get_user($p[member_id]));
                 $t->assign('payment', $p);
                 $t->assign('product', $db->get_product($p['product_id']));
                 $et =& new aMemberEmailTemplate();
                 $et->name = "mail_cancel_admin";
                 mail_template_admin($t, $et);
             }
             if ($config['mail_cancel_member']) {
                 $t->assign('user', $member = $db->get_user($p[member_id]));
                 $t->assign('payment', $p);
                 $t->assign('product', $db->get_product($p['product_id']));
                 $et =& new aMemberEmailTemplate();
                 $et->name = "mail_cancel_member";
                 mail_template_user($t, $et, $member);
             }
             break;
         case 'subscr_payment':
             if ($vars['payment_status'] != 'Completed') {
                 $this->postback_error(sprintf(_PLUG_PAY_PAYPALR_ERROR6, $vars[payment_status]) . _PLUG_PAY_PAYPALR_ERROR7);
             }
             $invoice = intval($vars['invoice']);
             $payment_id = $this->find_last_payment_id($vars['subscr_id'], $invoice);
             if (!$payment_id) {
                 $payment_id = $this->create_new_payment($vars);
                 $invoice = $payment_id;
             }
             if (!$payment_id) {
                 $this->postback_error(_PLUG_PAY_PAYPALR_ERROR11);
             }
             $this->get_lock();
             $p = $db->get_payment($payment_id);
             // if that is a NEW RECURRING payment,
             if ($p['data']['txn_id'] == $vars['txn_id']) {
                 // just record a payment for debug
                 $p['data'][] = $vars;
                 $db->update_payment($p['payment_id'], $p);
                 $this->release_lock();
                 return true;
             }
             // it is a first payment for this subscription
             // if !payment written, write to current
             //
             if ($p['payment_id'] == $invoice && !$p['data']['txn_id']) {
                 if (!$p['completed']) {
                     $err = $db->finish_waiting_payment($invoice, $this->get_plugin_name(), $vars['subscr_id'], $vars['mc_gross'], $vars, $vars['payer_id']);
                     if ($err) {
                         $this->postback_error("finish_waiting_payment error: {$err}");
                     }
                     $p = $db->get_payment($invoice);
                     $p['data']['txn_id'] = $vars['txn_id'];
                     $db->update_payment($invoice, $p);
                 } else {
                     $p['data'][] = $vars;
                     $p['amount'] = $vars['mc_gross'];
                     $p['data']['txn_id'] = $vars['txn_id'];
                     if ($p['data']['failed_orig_expiration']) {
                         $p['expire_date'] = $p['data']['failed_orig_expiration'];
                         $p['data']['failed_orig_expiration'] = '';
                     }
                     //                    $p['expire_date'] = '2012-12-31'; // set to 'Recurring' again. This can be possible re-try for recently failed payment.
                     $db->update_payment($p['payment_id'], $p);
                 }
                 $this->release_lock();
                 //                    if ($vars['txn_type'] == 'subscr_payment'){
                 //                        add_affiliate_commission($payment_id, $vars['txn_id'], $vars['mc_gross']);
                 //                    }
             } else {
                 //   1. set previous payment expire_date to yesterday
                 //   2. add a new payment with
                 $p['expire_date'] = date('Y-m-d');
                 $db->update_payment($p['payment_id'], $p);
                 $this->release_lock();
                 $pr = get_product($p[product_id]);
                 $newp = array();
                 $newp['member_id'] = $p['member_id'];
                 $newp['product_id'] = $p['product_id'];
                 $newp['paysys_id'] = 'epayph';
                 $newp['receipt_id'] = $vars['subscr_id'];
                 $newp['begin_date'] = date('Y-m-d');
                 $newp['expire_date'] = $pr->get_expire(date('Y-m-d'), 'expire_days');
                 $newp['amount'] = $vars['mc_gross'];
                 $newp['completed'] = 1;
                 $newp['data'] = array('txn_id' => $vars['txn_id'], 'epayph_vars' => $p['data']['epayph_vars']);
                 $newp['tax_amount'] = $p['data']['epayph_vars']['tax3'];
                 $newp['data'][] = $vars;
                 $db->add_payment($newp);
             }
             break;
         default:
             /// handle and register other events
             if (in_array($vars['payment_status'], array('Reversal', 'Refunded'))) {
                 return $this->process_refund($vars, $is_recurring = 1);
             }
             $this->get_lock();
             $payment_id = $this->find_last_payment_id($vars['subscr_id'], $vars['invoice']);
             if (!$payment_id) {
                 $this->postback_error(_PLUG_PAY_PAYPALR_ERROR11);
             }
             $p = $db->get_payment($payment_id);
             $p['data'][] = $vars;
             $data = $db->encode_data($p['data']);
             $data = $db->escape($data);
             $db->query($s = "UPDATE {$db->config[prefix]}payments\n                SET data = '{$data}',\n                    amount = '{$p[amount]}'\n                WHERE payment_id={$payment_id}");
             $this->release_lock();
     }
     return true;
 }
Ejemplo n.º 2
0
function mail_verification_email($user, $url, $source = "")
{
    global $db;
    $t =& new_smarty();
    $t->assign('user', $user);
    $t->assign('url', $url);
    ///
    $et =& new aMemberEmailTemplate();
    $et->name = "verify_email" . ($source == "profile" ? "_profile" : "");
    mail_template_user($t, $et, $user);
}
Ejemplo n.º 3
0
}
$invoices = $resp->sale->invoices;
$lineitem_id = $invoices[0]->lineitems[0]->lineitem_id;
$params = array('vendor_id' => $this_config['seller_id'], 'lineitem_id' => $lineitem_id);
//stop reccuring, $payment will be canceled throw IPN
$resp = $twocheckoutAPI->stop_lineitem_recurring($params);
if ($resp && $resp->response_code == 'OK') {
    // email to member if configured
    if ($config['mail_cancel_admin']) {
        $t->assign('user', $member);
        $t->assign('payment', $p);
        $t->assign('product', $db->get_product($p['product_id']));
        $et =& new aMemberEmailTemplate();
        $et->name = "mail_cancel_admin";
        mail_template_admin($t, $et);
    }
    if ($config['mail_cancel_member']) {
        $t->assign('user', $member);
        $t->assign('payment', $p);
        $t->assign('product', $db->get_product($p['product_id']));
        $et =& new aMemberEmailTemplate();
        $et->name = "mail_cancel_member";
        mail_template_user($t, $et, $member);
    }
    $t->assign('title', _PLUG_PAY_CC_CORE_SBSCNCL);
    $t->assign('msg', _PLUG_PAY_CC_CORE_SBSCNCL2);
    $t->display("msg_close.html");
} else {
    $GLOBALS['db']->log_error($twocheckoutAPI->getLastError());
    fatal_error('Internal error');
}
Ejemplo n.º 4
0
        $acceptedChars = 'azertyuiopqsdfghjklmwxcvbnAZERTYUIOPQSDFGHJKLMWXCVBN0123456789';
        $max = strlen($acceptedChars) - 1;
        $security_code = "";
        for ($i = 0; $i < 16; $i++) {
            $security_code .= $acceptedChars[mt_rand(0, $max)];
        }
        $security_code = $security_code . time();
        $security_code = md5($security_code);
        $security_code = substr($security_code, 0, 16);
        $hours = 48;
        $securitycode_expire = date("Y-m-d H:i:s", time() + $hours * 60 * 60);
        $t->assign('login', $u['login']);
        $t->assign('email', $u['email']);
        $t->assign('name_f', $u['name_f']);
        $t->assign('name_l', $u['name_l']);
        $t->assign('user', $u);
        $t->assign('code', $member_id . ":" . $security_code);
        $t->assign('hours', $hours);
        $et =& new aMemberEmailTemplate();
        $et->name = "send_security_code";
        mail_template_user($t, $et, $u);
        $q = $db->query("UPDATE {$db->config[prefix]}members\n            SET security_code='" . $db->escape($security_code) . "', securitycode_expire='{$securitycode_expire}'\n            WHERE member_id='{$member_id}'\n       ");
    }
    $t->assign('title', _SENDPWD_OK_TITLE);
    $t->assign('text', _SENDPWD_OK_TEXT . ".<br />\n" . _SENDPWD_OK_TEXT_1);
    $t->display('sendpass_result.html');
} else {
    $t->assign('title', _SENDPWD_FAILED_TITLE);
    $t->assign('text', _SENDPWD_FAILED_TEXT . ".<br />\n" . sprintf(_SENDPWD_FAILED_TEXT_1, htmlentities($login)));
    $t->display('sendpass_result.html');
}
Ejemplo n.º 5
0
function member_send_zero_autoresponder($payment_id, $member_id = 0)
{
    global $db, $config;
    $p = $db->get_payment($payment_id);
    $member_id = $p['member_id'];
    $pr = $db->get_product($p['product_id']);
    $t = new_smarty();
    $et =& new aMemberEmailTemplate();
    $et->name = "mail_autoresponder";
    $et->product_id = $pr['product_id'];
    $pl[0] = $pr;
    $pl[0]['autoresponder'] = array_filter($et->find_days(), 'keep_only_zeroes');
    // set global responder
    if ($config['mail_autoresponder']) {
        $et =& new aMemberEmailTemplate();
        $et->name = "mail_autoresponder";
        $days = $et->find_days();
        if ($days) {
            $pl[] = array('product_id' => -1, 'autoresponder' => array_filter($days, 'keep_only_zeroes'), 'autoresponder_renew' => $config['autoresponder_renew']);
        }
    }
    foreach ($pl as $pr) {
        $t =& new_smarty();
        if (!$pr['autoresponder']) {
            continue;
        }
        //        if (!preg_match_all('/^\s*(\d+)\s*\-\s*(.+?)\s*$/m', $pr['autoresponder'], $regs))
        //continue;
        if ($pr['product_id'] > 0) {
            $product_where = "AND p.product_id={$pr['product_id']}";
        } else {
            $product_where = "";
        }
        foreach ($pr['autoresponder'] as $days) {
            $dat = date('Y-m-d', time() - $days * 3600 * 24);
            $today = date('Y-m-d');
            if ($pr['autoresponder_renew']) {
                $q = $db->query($s = "SELECT m.*\n                FROM {$db->config['prefix']}payments p\n                LEFT JOIN {$db->config['prefix']}members m USING (member_id)\n                WHERE m.member_id = '{$member_id}' and p.begin_date='{$dat}' AND p.completed>0\n                    {$product_where}\n                GROUP BY m.member_id ");
            } else {
                $q = $db->query($s = "SELECT m.*\n                FROM {$db->config['prefix']}members m\n                LEFT JOIN {$db->config['prefix']}payments p USING (member_id)\n                WHERE m.member_id = '{$member_id}' and p.completed > 0\n                AND p.begin_date <= '{$today}' {$product_where}\n                GROUP BY m.member_id\n                HAVING\n                SUM(to_days(if(p.expire_date>'{$today}', '{$today}', p.expire_date)) - to_days(p.begin_date)) = {$days}\n                AND\n                MAX(p.expire_date) >= '{$today}'\n                ");
            }
            $et =& new aMemberEmailTemplate();
            $et->name = "mail_autoresponder";
            $et->product_id = $pr['product_id'] > 0 ? $pr['product_id'] : null;
            $et->day = $days;
            while ($u = mysql_fetch_assoc($q)) {
                $u['data'] = $db->decode_data($u['data']);
                $t->assign('user', $u);
                $t->assign('product', $pr);
                $t->assign('login', $u['login']);
                $t->assign('pass', $u['pass']);
                $t->assign('name_f', $u['name_f']);
                $t->assign('name_l', $u['name_l']);
                if ($u['unsubscribed']) {
                    continue;
                }
                mail_template_user($t, $et, $u, true);
            }
        }
    }
}
Ejemplo n.º 6
0
 function handle_cancel($vars, $mid = 0)
 {
     global $db, $config;
     settype($vars['payment_id'], 'integer');
     $mid = intval($mid);
     if (!$vars['payment_id']) {
         fatal_error("Payment_id empty");
     }
     $payment = $db->get_payment($vars['payment_id']);
     if (!$mid) {
         $mid = $_SESSION['_amember_id'];
     }
     if ($payment['member_id'] != $mid) {
         fatal_error(_PLUG_PAY_CC_CORE_FERROR4);
     }
     $p = $db->get_payment($vars['payment_id']);
     $member = $db->get_user($p['member_id']);
     $url = "https://api.clickbank.com/rest/1.2/tickets/" . $p['receipt_id'];
     $post = "type=cncl&reason=ticket.type.cancel.7&comment=cancellation%20request%20from%20aMember%20user%20(" . $member['login'] . ")";
     $url = $url . "?" . $post;
     $headers = array();
     $headers[] = "Accept: application/xml";
     $headers[] = "Authorization: " . $this->config['developer_key'] . ":" . $this->config['clerk_user_key'];
     $res = $this->get_url($url, $headers);
     $res_body = $res;
     if (preg_match("/\r\n\r\n(.*)/i", $res, $matches)) {
         $res_body = $matches[1];
     }
     $msg = _PLUG_PAY_CC_CORE_SBSCNCL2;
     $title = _PLUG_PAY_CC_CORE_SBSCNCL;
     if (!preg_match("/HTTP\\/1\\.1 200 OK/i", $res)) {
         $msg = "An error occured while cancellation request.";
         if ($res_body) {
             $msg .= "<br /><font color=red><b>" . $res_body . "</b></font>";
         }
         $title = "Subscription cancellation ERROR";
     } else {
         $xml = $this->parse_xml($res_body);
         $p['data'][] = $xml;
         $db->update_payment($p['payment_id'], $p);
         $response = array();
         if ($xml['ticketid']) {
             $response[] = "Ticket: " . $xml['ticketid'];
         }
         if ($xml['type']) {
             $response[] = "Type: " . $xml['type'];
         }
         if ($xml['action']) {
             $response[] = "Action: " . $xml['action'];
         }
         $response = implode("<br />", $response);
         if ($response) {
             $msg .= "<br /><b>Response from Clickbank</b><br />" . $response;
         }
     }
     $t =& new_smarty();
     $member = $db->get_user($p['member_id']);
     // email to member if configured
     if ($config['mail_cancel_admin']) {
         $t->assign('user', $member);
         $t->assign('payment', $p);
         $t->assign('product', $db->get_product($p['product_id']));
         $et =& new aMemberEmailTemplate();
         $et->name = "mail_cancel_admin";
         mail_template_admin($t, $et);
     }
     if ($config['mail_cancel_member']) {
         $t->assign('user', $member);
         $t->assign('payment', $p);
         $t->assign('product', $db->get_product($p['product_id']));
         $et =& new aMemberEmailTemplate();
         $et->name = "mail_cancel_member";
         mail_template_user($t, $et, $member);
     }
     $t =& new_smarty();
     $t->assign('title', $title);
     $t->assign('msg', $msg);
     $t->display("msg_close.html");
 }