Example #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;
 }
Example #2
0
function mail_rebill_failed_admin($user, $payment_id, $product, $error, $new_expire)
{
    global $db;
    $t =& new_smarty();
    $t->assign('user', $user);
    $t->assign('payment', $db->get_payment($payment_id));
    $t->assign('product', $product->config);
    $t->assign('error', $error);
    $t->assign('new_expire', $new_expire);
    ///
    $et =& new aMemberEmailTemplate();
    $et->name = "cc_rebill_failed_admin";
    mail_template_admin($t, $et);
}
Example #3
0
function member_lock_by_ip($member_id)
{
    global $db, $config;
    $m = $db->get_user($member_id);
    if ($m['data']['is_locked'] < 0) {
        return;
    }
    // auto-lock disabled
    if ($config['max_ip_actions'] != 1) {
        // email admin
        $t =& new_smarty();
        $t->assign("user", $m);
        $et =& new aMemberEmailTemplate();
        $et->name = "max_ip_actions";
        mail_template_admin($t, $et);
    }
    if ($config['max_ip_actions'] != 2) {
        // disable customer
        $m['data']['is_locked'] = 1;
        $db->update_user($member_id, $m);
    }
}
Example #4
0
    fatal_error('Internal error');
}
$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');
 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");
 }