Exemple #1
0
function shutdownAccount(\NinjaImg\Model\ModelOrganisation $organisation, $amount)
{
    $lastMonthDate = date('Y-m-01', strtotime('-1 month'));
    $currency = \NinjaImg\Model\ModelSettings::getInstance()->getCurrency();
    $lastPaymentDate = \NinjaImg\Model\ModelPayment::getLastPaymentDate($organisation->id, $lastMonthDate);
    if (!$lastPaymentDate) {
        $lastPaymentDate = \Pecee\Date::toDateTime();
        savePayment($organisation->id, $amount, $lastMonthDate);
    }
    $lastTryDaysAgo = daysAgo($lastPaymentDate, \Pecee\Date::toDateTime());
    if ($lastTryDaysAgo > MAX_PAYMENT_ATTEMPTS_DAYS) {
        echo sprintf('disabled due to no payment in %s days', MAX_PAYMENT_ATTEMPTS_DAYS);
        mailAdmins('[WARNING] ' . $organisation->name . ' shut down warning', sprintf("Hi bitches!\n\nThe organisation {$organisation->name} has been shut down due to invalid and/or no payment in over %s days.\n\nAmount: {$amount}{$currency}\nDate: {$lastMonthDate}\n\nPlease contact this organisation to take further action.\n\n- The Ninja Robot"));
        // TODO: Send notification to user about shutting down
        $organisation->disabled = true;
        $organisation->update();
    } else {
        $shutdownDays = MAX_PAYMENT_ATTEMPTS_DAYS - $lastTryDaysAgo;
        echo sprintf('%s days before shutting down account', $shutdownDays);
        mailAdmins('[INFO] ' . $organisation->name . ' payment not received', sprintf("Hi bitches!\n\nFailed to charge {$organisation->name} and will be automatically disabled in {$shutdownDays} days.\n\nAmount: {$amount}{$currency}\nDate: {$lastMonthDate}\n\nPlease contact this organisation to take further action.\n\n- The Ninja Robot"));
        // Register try
    }
}
Exemple #2
0
        $payment_no = isset($_POST["InvId"]) ? $modx->db->escape($_POST["InvId"]) : '';
        $payment_orderid = isset($_POST["Shp_item"]) ? $modx->db->escape($_POST["Shp_item"]) : '';
        $payment_signature = isset($_POST["SignatureValue"]) ? $modx->db->escape($_POST["SignatureValue"]) : '';
        $crc = strtoupper($payment_signature);
        $my_crc = strtoupper(md5("{$payment_value}:{$payment_no}:{$mrh_pass2}:Shp_item={$payment_orderid}"));
        // check signature
        if ($my_crc != $crc) {
            echo "bad sign\n";
            exit;
        }
        $pay_val = number_format($payment_value, 2, '.', '');
        //$pay_val = number_format($payment_value,2);
        $crc_start = md5("{$mrh_login}:{$pay_val}:{$payment_no}:{$mrh_pass1}:Shp_item={$payment_orderid}");
        // success
        echo "OK{$payment_no}\n";
        $query_where = "pitem.payid = ppay.id " . "AND pitem.content = '{$payment_orderid}' " . "AND pitem.content = ppay.orderid " . "AND pitem.price = {$payment_value} " . "AND pitem.unit='RKR' " . "AND pitem.state='Y' " . "AND pitem.paid='N' " . "AND ppay.signature='{$crc_start}'";
        $item_res = $modx->db->select("pitem.id, pitem.price, pitem.unit", "{$mod_tab_items} pitem, {$mod_tab_payments} ppay", $query_where);
        if ($modx->db->getRecordCount($item_res) >= 1) {
            $ord_data = array("item_id" => $payment_orderid, "payment_no" => $payment_no);
            savePayment($dbname, $mod_tab_payments, $mod_tab_items, $SHK_mod_table, $ord_data);
        }
        break;
        ####################################################
        # Null
        ####################################################
    ####################################################
    # Null
    ####################################################
    default:
        break;
}
if (!empty($_POST['stripeToken'])) {
    // Set your secret key: remember to change this to your live secret key in production
    // See your keys here https://dashboard.stripe.com/account/apikeys
    \Stripe\Stripe::setApiKey("sk_test_JibAHEWq92eWdNUWUfbmdaAN");
    $amount = intval($_POST['due_amount']);
    // amount in cents
    // Get the credit card details submitted by the form
    $token = $_POST['stripeToken'];
    // Create the charge on Stripe's servers - this will charge the user's card
    try {
        $charge = \Stripe\Charge::create(array("amount" => $amount * 100, "currency" => "usd", "source" => $token, "description" => "Example charge"));
    } catch (\Stripe\Error\Card $e) {
        // The card has been declined
        $error = $e->getMessage();
    }
    if (savePayment($token, $amount, $user)) {
        $success = "Successful charge";
    }
}
function savePayment($token, $amount, $user)
{
    global $db_con;
    global $balance;
    checkBalance($user);
    $balance = $balance + $amount;
    $query = "INSERT INTO `payments`(`transaction_id`, `type`, `description`, `amount` , `user_id` , `balance` , `project_id`, `created_by`)\n\t\t VALUES ( '" . $token . "' , 0, '" . $db_con->escape($_POST['description']) . "' , '" . $amount . "' , 0 , '" . $balance . "' , 0 , '" . $user['user_id'] . "')";
    $db_con->query($query);
    $id = $db_con->insert_id();
    $query1 = "UPDATE `users` SET balance=" . $balance . " WHERE user_id=" . $user['user_id'];
    $db_con->query($query1);
    return $id;