Example #1
0
function paymentwall_link($params)
{
    init_paymentwall_config($params);
    $product = null;
    $recurring = getRecurringBillingValues($params['invoiceid']);
    $code = '';
    $hasTrial = false;
    $subscriptionProduct = false;
    if ($recurring) {
        $subscriptionProduct = get_subscription_product($params, $recurring, $hasTrial);
    }
    $onetimeProduct = get_one_time_product($params);
    if ($subscriptionProduct && (!$params['forceOneTime'] || $params['forceSubscription'])) {
        $subscriptionWidget = new Paymentwall_Widget($params['clientdetails']['userid'], $params['widget'], array($subscriptionProduct), array_merge(array('integration_module' => 'whmcs', 'test_mode' => $params['isTest'] == 'on' ? 1 : 0, 'hide_post_trial_good' => $hasTrial ? 1 : 0), get_user_profile_data($params)));
        $code .= get_widget_code($subscriptionWidget, $params, 'subscribe');
    }
    if (!$params['forceSubscription'] && $recurring || !$recurring) {
        $onetimeWidget = new Paymentwall_Widget($params['clientdetails']['userid'], $params['widget'], array($onetimeProduct), array_merge(array('integration_module' => 'whmcs', 'test_mode' => $params['isTest'] == 'on' ? 1 : 0), get_user_profile_data($params)));
        $code .= get_widget_code($onetimeWidget, $params, 'check_out');
    }
    $code .= '<br><span style="font-size: 11px; color: #AAAAAA">Secure payments by <a href="https://www.paymentwall.com">Paymentwall Inc</a>.<span>';
    return $code;
}
Example #2
0
/**
 ** Builds the payment link for WHMCS users to be redirected to GoCardless
 **/
function gocardless_link($params)
{
    # get global config params
    global $CONFIG;
    # create GoCardless database if it hasn't already been created
    gocardless_createdb();
    # check the invoice, to see if it has a record with a valid resource ID. If it does, the invoice is pending payment.
    # we will return a message on the invoice to prevent duplicate payment attempts
    $aGC = mysql_fetch_assoc(select_query('mod_gocardless', 'id,payment_failed', array('invoiceid' => $params['invoiceid'], 'resource_id' => array('sqltype' => 'NEQ', 'value' => ''))));
    if ($aGC['id']) {
        if ($aGC['payment_failed'] == 0) {
            # Pending Payment Found - Prevent Duplicate Payment with a Msg
            return '<strong>Your payment is currently pending and will be processed within 3-5 days.</strong>';
        } else {
            # display a message to the user suggesting that a payment against the invoice has failed
            return '<strong>One or more payment attempts have failed against this invoice. Please contact our support department.</strong>';
        }
    }
    # get relevant invoice data
    $aRecurrings = getRecurringBillingValues($params['invoiceid']);
    $recurringcycleunit = strtolower(substr($aRecurrings['recurringcycleunits'], 0, -1));
    # check a number of conditions to see if it is possible to setup a preauth
    if ($params['oneoffonly'] == 'on' || $aRecurrings === false || $aRecurrings['recurringamount'] <= 0) {
        $noPreauth = false;
        #MOD
    } else {
        $noPreauth = false;
    }
    # set appropriate GoCardless API details
    gocardless_set_account_details($params);
    # set user array based on params parsed to $link
    $aUser = array('first_name' => $params['clientdetails']['firstname'], 'last_name' => $params['clientdetails']['lastname'], 'email' => $params['clientdetails']['email'], 'billing_address1' => $params['clientdetails']['address1'], 'billing_address2' => $params['clientdetails']['address2'], 'billing_town' => $params['clientdetails']['city'], 'billing_county' => $params['clientdetails']['state'], 'billing_postcode' => $params['clientdetails']['postcode']);
    $invoice_item_query = select_query('tblinvoiceitems', 'relid', array('invoiceid' => $params['invoiceid'], 'type' => 'Hosting'));
    while ($invoice_item = mysql_fetch_assoc($invoice_item_query)) {
        $package_query = select_query('tblhosting', 'subscriptionid', array('id' => $invoice_item['relid']));
        $package = mysql_fetch_assoc($package_query);
        if (!empty($package['subscriptionid'])) {
            $preauthExists = true;
        }
    }
    if ($preauthExists) {
        # The customer already has a pre-auth, but it's yet to be charged so
        # let's not let them set up another...
        return (GoCardless::$environment == 'sandbox' ? '<strong style="color: #FF0000; font-size: 16px;">SANDBOX MODE</strong><br />' : null) . '<strong>Automatic payments via Direct Debit or another payment method are already configured for this invoice. You will receive an email once you have been billed.</strong>';
    } elseif ($noPreauth) {
        # if one of the $noPreauth conditions have been met, display a one time payment button
        # we are making a one off payment, display the appropriate code
        # Button title
        $title = 'Pay Now with GoCardless';
        # create GoCardless one off payment URL using the GoCardless library
        $url = GoCardless::new_bill_url(array('amount' => $params['amount'], 'name' => "Invoice #" . $params['invoiceid'], 'user' => $aUser, 'state' => $params['invoiceid'] . ':' . $params['amount']));
        # return one time payment button code
        $sButton = (GoCardless::$environment == 'sandbox' ? '<strong style="color: #FF0000; font-size: 16px;">SANDBOX MODE</strong><br />' : null) . '<a href="' . $url . '" onclick="window.location=\'' . $url . '\';" style="text-decoration: none"><input onclick="window.location=\'' . $url . '\';" type="button" value="' . $title . '" /></a>';
    } else {
        # we are setting up a preauth (description friendly name), display the appropriate code
        # get the invoice from the database because we need the invoice creation date
        $aInvoice = mysql_fetch_assoc(select_query('tblinvoices', 'date', array('id' => $params['invoiceid'])));
        # GoCardless only supports months in the billing period so
        # if WHMCS is sending a year value we need to address this
        if ($recurringcycleunit == 'year') {
            $recurringcycleunit = 'month';
            $aRecurrings['recurringcycleperiod'] = $aRecurrings['recurringcycleperiod'] * 12;
        }
        $pre_auth_maximum = 5000;
        # Always create a £5000 pre-auth
        # Button title
        $title = 'Create Subscription with GoCardless';
        # create GoCardless preauth URL using the GoCardless library
        $url = GoCardless::new_pre_authorization_url(array('max_amount' => $pre_auth_maximum, 'setup_fee' => $aRecurrings['firstpaymentamount'] > $aRecurrings['recurringamount'] ? $aRecurrings['firstpaymentamount'] - $aRecurrings['recurringamount'] : 0, 'name' => "Direct Debit payments to " . $CONFIG['CompanyName'], 'interval_length' => '1', 'interval_unit' => 'day', 'start_at' => date_format(date_create($aInvoice['date'] . ' -2 days'), 'Y-m-d\\TH:i:sO'), 'user' => $aUser, 'state' => $params['invoiceid'] . ':' . $aRecurrings['recurringamount']));
        # return the recurring preauth button code
        $sButton = (GoCardless::$environment == 'sandbox' ? '<strong style="color: #FF0000; font-size: 16px;">SANDBOX MODE</strong><br />' : null) . 'When you get to GoCardless you will see an agreement for the <b>maximum possible amount</b> we\'ll ever need to charge you in a single invoice for this order, with a frequency of the shortest item\'s billing cycle. But rest assured we will never charge you more than the actual amount due.
            <br /><a onclick="window.location=\'' . $url . '\';" href="' . $url . '" style="text-decoration: none"><input type="button" onclick="window.location=\'' . $url . '\';" value="' . $title . '" /></a>';
    }
    # return the formatted button
    return $sButton;
}
Example #3
0
 function tco_reoccuring_request()
 {
     global $whmcs;
     $whmcs->load_function("gateway");
     $whmcs->load_function("client");
     $whmcs->load_function("invoice");
     $GATEWAY = getGatewayVariables("tco");
     $invoiceid = $description = (int) $_POST['invoiceid'];
     $vendorid = $GATEWAY['vendornumber'];
     $apiusername = $GATEWAY['apiusername'];
     $apipassword = $GATEWAY['apipassword'];
     $demomode = $GATEWAY['demomode'];
     $recurrings = getRecurringBillingValues($invoiceid);
     if (!$recurrings) {
         $url = "../../viewinvoice.php?id=" . $invoiceid;
         header("Location:" . $url);
         exit;
     }
     $primaryserviceid = $recurrings['primaryserviceid'];
     $first_payment_amount = $recurrings['firstpaymentamount'] ? $recurrings['firstpaymentamount'] : $recurrings['recurringamount'];
     $recurring_amount = $recurrings['recurringamount'];
     if ($recurrings['recurringcycleunits'] == "Months") {
         $billing_cycle = $recurrings['recurringcycleperiod'] . " Month";
     } else {
         if ($recurrings['recurringcycleunits'] == "Years") {
             $billing_cycle = $recurrings['recurringcycleperiod'] . " Year";
         }
     }
     $billing_duration = "Forever";
     $startup_fee = $first_payment_amount - $recurring_amount;
     $url = "https://www.2checkout.com/api/products/create_product";
     $name = "Recurring Subscription for Invoice #" . $invoiceid;
     if ($demomode = "on") {
         $query_string = "name=" . $name . "&price=" . $recurring_amount . "&startup_fee=" . $startup_fee . "&demo=Y&recurring=1&recurrence=" . $billing_cycle . "&duration=" . $billing_duration . "&description=" . $description;
     } else {
         $query_string = "name=" . $name . "&price=" . $recurring_amount . "&startup_fee=" . $startup_fee . "&recurring=1&recurrence=" . $billing_cycle . "&duration=" . $billing_duration . "&description=" . $description;
     }
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_USERPWD, $apiusername . ":" . $apipassword);
     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
     curl_setopt($ch, CURLOPT_HEADER, 0);
     curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/json"));
     $response = curl_exec($ch);
     curl_close($ch);
     if (!function_exists("json_decode")) {
         exit("JSON Module Required in PHP Build for 2CheckOut Gateway");
     }
     $response = json_decode($response, true);
     if (!count($response['errors']) && $response['response_code'] == "OK") {
         logTransaction("2Checkout Recurring", print_r($response, true), "Ok");
         $product_id = $response['product_id'];
         $assigned_product_id = $response['assigned_product_id'];
         $purchaseroutine = !$GATEWAY['purchaseroutine'] ? "s" : "";
         $result = select_query("tblinvoices", "userid", array("id" => $invoiceid));
         $data = mysql_fetch_array($result);
         $userid = $data[0];
         $clientsdetails = getClientsDetails($userid);
         $currency = getCurrency($userid);
         global $CONFIG;
         $lang = $clientsdetails['language'];
         if (!$lang) {
             $lang = $CONFIG['Language'];
         }
         $lang = strtolower($lang);
         if ($lang == "chinese") {
             $lang = "zh";
         } else {
             if ($lang == "danish") {
                 $lang = "da";
             } else {
                 if ($lang == "dutch") {
                     $lang = "nl";
                 } else {
                     if ($lang == "french") {
                         $lang = "fr";
                     } else {
                         if ($lang == "german") {
                             $lang = "gr";
                         } else {
                             if ($lang == "greek") {
                                 $lang = "el";
                             } else {
                                 if ($lang == "italian") {
                                     $lang = "it";
                                 } else {
                                     if ($lang == "japanese") {
                                         $lang = "jp";
                                     } else {
                                         if ($lang == "norwegian") {
                                             $lang = "no";
                                         } else {
                                             if ($lang == "portuguese") {
                                                 $lang = "pt";
                                             } else {
                                                 if ($lang == "slovenian") {
                                                     $lang = "sl";
                                                 } else {
                                                     if ($lang == "spanish") {
                                                         $lang = "es_la";
                                                     } else {
                                                         if ($lang == "swedish") {
                                                             $lang = "sv";
                                                         } else {
                                                             if ($lang == "english") {
                                                                 $lang = "en";
                                                             } else {
                                                                 $lang = "";
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         if ($lang) {
             $lang = "&lang=" . $lang;
         }
         if ($clientsdetails['country'] != "US" || $clientsdetails['country'] != "CA") {
             $clientsdetails['state'] = "XX";
         }
         $url = "https://www.2checkout.com/checkout/" . $purchaseroutine . "purchase?sid=" . $vendorid . "&quantity=1&product_id=" . $assigned_product_id . "&tco_currency=" . $currency['code'] . "&merchant_order_id=" . $primaryserviceid . "&card_holder_name=" . $clientsdetails['firstname'] . " " . $clientsdetails['lastname'] . "&street_address=" . $clientsdetails['address1'] . "&city=" . $clientsdetails['city'] . "&state=" . $clientsdetails['state'] . "&zip=" . $clientsdetails['postcode'] . "&country=" . $clientsdetails['country'] . "&email=" . $clientsdetails['email'] . "&phone=" . $clientsdetails['phonenumber'] . $lang;
         header("Location:" . $url);
         exit;
         return null;
     }
     $apierror = "Errors => " . print_r($response, true);
     logTransaction("2Checkout Recurring", $apierror, "Error");
     $url = "../../viewinvoice.php?id=" . $invoiceid . "&paymentfailed=true";
     header("Location:" . $url);
     exit;
 }
Example #4
0
function paypal_link($params)
{
    global $CONFIG;
    $invoiceid = $params['invoiceid'];
    $paypalemails = $params['email'];
    $paypalemails = explode(",", $paypalemails);
    $paypalemail = trim($paypalemails[0]);
    $recurrings = getRecurringBillingValues($invoiceid);
    $primaryserviceid = $recurrings['primaryserviceid'];
    $firstpaymentamount = $recurrings['firstpaymentamount'];
    $firstcycleperiod = $recurrings['firstcycleperiod'];
    $firstcycleunits = strtoupper(substr($recurrings['firstcycleunits'], 0, 1));
    $recurringamount = $recurrings['recurringamount'];
    $recurringcycleperiod = $recurrings['recurringcycleperiod'];
    $recurringcycleunits = strtoupper(substr($recurrings['recurringcycleunits'], 0, 1));
    if ($params['clientdetails']['country'] == "US" || $params['clientdetails']['country'] == "CA") {
        $phonenumber = preg_replace("/[^0-9]/", "", $params['clientdetails']['phonenumber']);
        $phone1 = substr($phonenumber, 0, 3);
        $phone2 = substr($phonenumber, 3, 3);
        $phone3 = substr($phonenumber, 6);
    } else {
        $phone1 = $params['clientdetails']['phonecc'];
        $phone2 = $params['clientdetails']['phonenumber'];
    }
    $subnotpossible = false;
    if (!$recurrings) {
        $subnotpossible = true;
    }
    if ($recurrings['overdue']) {
        $subnotpossible = true;
    }
    if ($params['forceonetime']) {
        $subnotpossible = true;
    }
    if ($recurringamount <= 0) {
        $subnotpossible = true;
    }
    if (90 < $firstcycleperiod && $firstcycleunits == "D") {
        $subnotpossible = true;
    }
    if (24 < $firstcycleperiod && $firstcycleunits == "M") {
        $subnotpossible = true;
    }
    if (5 < $firstcycleperiod && $firstcycleunits == "Y") {
        $subnotpossible = true;
    }
    $code = "<table><tr>";
    if (!$subnotpossible) {
        $code .= "<td><form action=\"https://www.paypal.com/cgi-bin/webscr\" method=\"post\" name=\"paymentfrm\">\n<input type=\"hidden\" name=\"cmd\" value=\"_xclick-subscriptions\">\n<input type=\"hidden\" name=\"business\" value=\"" . $paypalemail . "\">\n<input type=\"hidden\" name=\"item_name\" value=\"" . $params['description'] . "\">\n<input type=\"hidden\" name=\"no_shipping\" value=\"" . ($params['requireshipping'] ? "2" : "1") . "\">\n<input type=\"hidden\" name=\"address_override\" value=\"" . ($params['overrideaddress'] ? "1" : "0") . "\">\n<input type=\"hidden\" name=\"first_name\" value=\"" . $params['clientdetails']['firstname'] . "\">\n<input type=\"hidden\" name=\"last_name\" value=\"" . $params['clientdetails']['lastname'] . "\">\n<input type=\"hidden\" name=\"address1\" value=\"" . $params['clientdetails']['address1'] . "\">\n<input type=\"hidden\" name=\"city\" value=\"" . $params['clientdetails']['city'] . "\">\n<input type=\"hidden\" name=\"state\" value=\"" . $params['clientdetails']['state'] . "\">\n<input type=\"hidden\" name=\"zip\" value=\"" . $params['clientdetails']['postcode'] . "\">\n<input type=\"hidden\" name=\"country\" value=\"" . $params['clientdetails']['country'] . "\">\n<input type=\"hidden\" name=\"night_phone_a\" value=\"" . $phone1 . "\">\n<input type=\"hidden\" name=\"night_phone_b\" value=\"" . $phone2 . "\">";
        if ($phone3) {
            $code .= "<input type=\"hidden\" name=\"night_phone_c\" value=\"" . $phone3 . "\">";
        }
        $code .= "<input type=\"hidden\" name=\"no_note\" value=\"1\">\n<input type=\"hidden\" name=\"currency_code\" value=\"" . $params['currency'] . "\">\n<input type=\"hidden\" name=\"bn\" value=\"WHMCS_ST\">";
        if ($firstpaymentamount) {
            $code .= "\n<input type=\"hidden\" name=\"a1\" value=\"" . $firstpaymentamount . "\">\n<input type=\"hidden\" name=\"p1\" value=\"" . $firstcycleperiod . "\">\n<input type=\"hidden\" name=\"t1\" value=\"" . $firstcycleunits . "\">";
        }
        $code .= "\n<input type=\"hidden\" name=\"a3\" value=\"" . $recurringamount . "\">\n<input type=\"hidden\" name=\"p3\" value=\"" . $recurringcycleperiod . "\">\n<input type=\"hidden\" name=\"t3\" value=\"" . $recurringcycleunits . "\">\n<input type=\"hidden\" name=\"src\" value=\"1\">\n<input type=\"hidden\" name=\"sra\" value=\"1\">\n<input type=\"hidden\" name=\"charset\" value=\"" . $CONFIG['Charset'] . "\">\n<input type=\"hidden\" name=\"custom\" value=\"" . $primaryserviceid . "\">\n<input type=\"hidden\" name=\"return\" value=\"" . $params['returnurl'] . "&paymentsuccess=true\">\n<input type=\"hidden\" name=\"cancel_return\" value=\"" . $params['returnurl'] . "&paymentfailed=true\">\n<input type=\"hidden\" name=\"notify_url\" value=\"" . $params['systemurl'] . "/modules/gateways/callback/paypal.php\">\n<input type=\"hidden\" name=\"rm\" value=\"2\">";
        if (!$firstpaymentamount && $params['modifysubscriptions']) {
            $code .= "\n<input type=\"hidden\" name=\"modify\" value=\"1\">";
        }
        $code .= "\n<input type=\"image\" src=\"https://www.paypal.com/en_US/i/btn/x-click-but20.gif\" border=\"0\" name=\"submit\" alt=\"Subscribe with PayPal for Automatic Payments\">\n</form></td>";
    }
    if (!$subnotpossible && $params['forcesubscriptions'] && !$params['forceonetime']) {
    } else {
        $code .= "<td><form action=\"https://www.paypal.com/cgi-bin/webscr\" method=\"post\">\n<input type=\"hidden\" name=\"cmd\" value=\"_xclick\">\n<input type=\"hidden\" name=\"business\" value=\"" . $paypalemail . "\">";
        if ($params['style']) {
            $code .= "<input type=\"hidden\" name=\"page_style\" value=\"" . $params['style'] . "\">";
        }
        $code .= "<input type=\"hidden\" name=\"item_name\" value=\"" . $params['description'] . "\">\n<input type=\"hidden\" name=\"amount\" value=\"" . $params['amount'] . "\">\n<input type=\"hidden\" name=\"tax\" value=\"0.00\">\n<input type=\"hidden\" name=\"no_note\" value=\"1\">\n<input type=\"hidden\" name=\"no_shipping\" value=\"" . ($params['requireshipping'] ? "2" : "1") . "\">\n<input type=\"hidden\" name=\"address_override\" value=\"" . ($params['overrideaddress'] ? "1" : "0") . "\">\n<input type=\"hidden\" name=\"first_name\" value=\"" . $params['clientdetails']['firstname'] . "\">\n<input type=\"hidden\" name=\"last_name\" value=\"" . $params['clientdetails']['lastname'] . "\">\n<input type=\"hidden\" name=\"address1\" value=\"" . $params['clientdetails']['address1'] . "\">\n<input type=\"hidden\" name=\"city\" value=\"" . $params['clientdetails']['city'] . "\">\n<input type=\"hidden\" name=\"state\" value=\"" . $params['clientdetails']['state'] . "\">\n<input type=\"hidden\" name=\"zip\" value=\"" . $params['clientdetails']['postcode'] . "\">\n<input type=\"hidden\" name=\"country\" value=\"" . $params['clientdetails']['country'] . "\">\n<input type=\"hidden\" name=\"night_phone_a\" value=\"" . $phone1 . "\">\n<input type=\"hidden\" name=\"night_phone_b\" value=\"" . $phone2 . "\">";
        if ($phone3) {
            $code .= "<input type=\"hidden\" name=\"night_phone_c\" value=\"" . $phone3 . "\">";
        }
        $code .= "<input type=\"hidden\" name=\"charset\" value=\"" . $CONFIG['Charset'] . "\">\n<input type=\"hidden\" name=\"currency_code\" value=\"" . $params['currency'] . "\">\n<input type=\"hidden\" name=\"custom\" value=\"" . $params['invoiceid'] . "\">\n<input type=\"hidden\" name=\"return\" value=\"" . $params['returnurl'] . "&paymentsuccess=true\">\n<input type=\"hidden\" name=\"cancel_return\" value=\"" . $params['returnurl'] . "&paymentfailed=true\">\n<input type=\"hidden\" name=\"notify_url\" value=\"" . $params['systemurl'] . "/modules/gateways/callback/paypal.php\">\n<input type=\"hidden\" name=\"bn\" value=\"WHMCS_ST\">\n<input type=\"hidden\" name=\"rm\" value=\"2\">\n<input type=\"image\" src=\"https://www.paypal.com/en_US/i/btn/x-click-but03.gif\" border=\"0\" name=\"submit\" alt=\"Make a one time payment with PayPal\">\n</form></td>";
    }
    $code .= "</tr></table>";
    return $code;
}