plas71k

Ioncube - decoded file

Nov 17th, 2012
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 30.13 KB | None | 0 0
  1. <?php
  2. function zstripe_config()
  3. {
  4.     global $version;
  5.     $configarray = array(
  6.         "FriendlyName" => array(
  7.             "Type" => "System",
  8.             "Value" => "zStripe(Stripe.com)"
  9.         ),
  10.         "version" => array(
  11.             "FriendlyName" => "Version",
  12.             "Type" => "dropdown",
  13.             "Options" => $version
  14.         ),
  15.         "StripeLibPath" => array(
  16.             "FriendlyName" => "FULL ABSOLUTE Path to Stripe lib",
  17.             "Type" => "text",
  18.             "Size" => "50"
  19.         ),
  20.         "keySecretTest" => array(
  21.             "FriendlyName" => "Secret Test API Key",
  22.             "Type" => "text",
  23.             "Size" => "40"
  24.         ),
  25.         "keySecretLive" => array(
  26.             "FriendlyName" => "Secret Live API Key",
  27.             "Type" => "text",
  28.             "Size" => "40"
  29.         ),
  30.         "testmode" => array(
  31.             "FriendlyName" => "Test Mode",
  32.             "Type" => "yesno",
  33.             "Description" => "Select this to use test mode"
  34.         ),
  35.         "storelocal" => array(
  36.             "FriendlyName" => "Store card details locally?",
  37.             "Type" => "yesno",
  38.             "Description" => "Store client card details locally"
  39.         ),
  40.         "zstripe_licenseKey" => array(
  41.             "FriendlyName" => "License Key",
  42.             "Type" => "text",
  43.             "Size" => "40"
  44.         )
  45.     );
  46.     return $configarray;
  47. }
  48.  
  49. function zstripe_capture($params)
  50. {
  51.     $path .= ":capture:";
  52.     zstripe_checkzLicense($params);
  53.     if (is_file($params['StripeLibPath'])) {
  54.         include_once($params['StripeLibPath']);
  55.     } else if (is_file($params['StripeLibPath'] . "/Stripe.php")) {
  56.         include_once($params['StripeLibPath'] . "/Stripe.php");
  57.     } else if (is_file($params['StripeLibPath'] . "/lib/Stripe.php")) {
  58.         include_once($params['StripeLibPath'] . "/lib/Stripe.php");
  59.     } else {
  60.         throw new Exception("Stripe library not found!");
  61.     }
  62.     if ($params['testmode']) {
  63.         $gateway_Key = $params['keySecretTest'];
  64.     } else {
  65.         $gateway_Key = $params['keySecretLive'];
  66.     }
  67.     Stripe::setapikey($gateway_Key);
  68.     $invoiceid    = $params['invoiceid'];
  69.     $amount       = $params['amount'];
  70.     $amountcents  = zstripe_getMoneyAsCents($amount);
  71.     $currency     = $params['currency'];
  72.     $firstname    = $params['clientdetails']['firstname'];
  73.     $lastname     = $params['clientdetails']['lastname'];
  74.     $email        = $params['clientdetails']['email'];
  75.     $address1     = $params['clientdetails']['address1'];
  76.     $address2     = $params['clientdetails']['address2'];
  77.     $city         = $params['clientdetails']['city'];
  78.     $state        = $params['clientdetails']['state'];
  79.     $postcode     = $params['clientdetails']['postcode'];
  80.     $country      = $params['clientdetails']['country'];
  81.     $phone        = $params['clientdetails']['phonenumber'];
  82.     $cardtype     = $params['cardtype'];
  83.     $cardnumber   = $params['cardnum'];
  84.     $cardexpiry   = $params['cardexp'];
  85.     $cardstart    = $params['cardstart'];
  86.     $cardissuenum = $params['cardissuenum'];
  87.     if (2 < strlen($params['gatewayid'])) {
  88.         $path .= ":e0:";
  89.         $charge = array(
  90.             amount => $amountcents,
  91.             "usd",
  92.             customer => $params['gatewayid'],
  93.             description => "Invoice #" . $invoiceid
  94.         );
  95.     } else if (1 < strlen($params['cccvv'])) {
  96.         $charge = array(
  97.             amount => $amountcents,
  98.             "usd",
  99.             card => array(
  100.                 "name" => $params['clientdetails']['firstname'] . " " . $params['clientdetails']['lastname'],
  101.                 "number" => $params['cardnum'],
  102.                 "exp_month" => substr($params['cardexp'], 0, 2),
  103.                 "exp_year" => "20" . substr($params['cardexp'], 2, 2),
  104.                 "cvc" => $params['cccvv'],
  105.                 "address_line1" => $params['clientdetails']['address1'],
  106.                 "address_line2" => $params['clientdetails']['address2'],
  107.                 "address_zip" => $params['clientdetails']['postcode'],
  108.                 "address_state" => $params['clientdetails']['state']
  109.             ),
  110.             description => "Invoice #" . $invoiceid
  111.         );
  112.     } else {
  113.         $charge = array(
  114.             amount => $amountcents,
  115.             "usd",
  116.             card => array(
  117.                 "name" => $params['clientdetails']['firstname'] . " " . $params['clientdetails']['lastname'],
  118.                 "number" => $params['cardnum'],
  119.                 "exp_month" => substr($params['cardexp'], 0, 2),
  120.                 "exp_year" => "20" . substr($params['cardexp'], 2, 2),
  121.                 "address_line1" => $params['clientdetails']['address1'],
  122.                 "address_line2" => $params['clientdetails']['address2'],
  123.                 "address_zip" => $params['clientdetails']['postcode'],
  124.                 "address_state" => $params['clientdetails']['state']
  125.             ),
  126.             description => "Invoice #" . $invoiceid
  127.         );
  128.     }
  129.     try {
  130.         $path .= ":e1:";
  131.         global $chargeObj;
  132.         $chargeObj = Stripe_Charge::create($charge);
  133.     }
  134.     catch (Stripe_CardError $err) {
  135.         $path .= ":e2:";
  136.         return array(
  137.             "status" => "failed",
  138.             "rawdata" => array(
  139.                 "ERRORMSG" => $err->getMessage(),
  140.                 "PATH" => $path
  141.             )
  142.         );
  143.     }
  144.     catch (Stripe_Error $err) {
  145.         $path .= ":e3:";
  146.         return array(
  147.             "status" => "failed",
  148.             "rawdata" => array(
  149.                 "ERRORMSG" => $err->getMessage(),
  150.                 "PATH" => $path
  151.             )
  152.         );
  153.     }
  154.     if ($chargeObj->type) {
  155.         $path .= ":e4:";
  156.         return array(
  157.             "status" => "failed",
  158.             "rawdata" => array(
  159.                 "ERRORTYPE" => $chargeObj->type,
  160.                 "ERRORMSG" => $chargeObj->message,
  161.                 "PATH" => $path
  162.             )
  163.         );
  164.     }
  165.     if ($chargeObj->paid == "0") {
  166.         $path .= ":e5:";
  167.         return array(
  168.             "status" => "failed",
  169.             "rawdata" => array(
  170.                 "ERRORCODE" => $chargeObj->code,
  171.                 "ERRORMSG" => $chargeObj->message,
  172.                 "ERRORPARAM" => $chargeObj->param,
  173.                 "ERRORTYPE" => $chargeObj->type,
  174.                 "PATH" => $path,
  175.                 "PAID" => $chargeObj->paid
  176.             )
  177.         );
  178.     }
  179.     $path .= ":e6:";
  180.     return array(
  181.         "status" => "success",
  182.         "transid" => $chargeObj->id,
  183.         "fee" => $chargeObj->fee * 0.01,
  184.         "rawdata" => array(
  185.             "TRANSACTIONID" => $chargeObj->id,
  186.             "AMOUNT" => $chargeObj->amount,
  187.             "DESCRIPTION" => $chargeObj->description,
  188.             "FEE" => $chargeObj->fee,
  189.             "PAID" => $chargeObj->paid,
  190.             "CREATED" => $chargeObj->created,
  191.             "payment_gross" => $chargeObj->amount,
  192.             "payment_fee" => $chargeObj->fee * 0.01,
  193.             "payer_id" => $params['gatewayid'],
  194.             "LIVEMODE" => $chargeObj->livemode,
  195.             "PATH" => $path
  196.         )
  197.     );
  198. }
  199.  
  200. function zstripe_refund($params)
  201. {
  202.     $path .= ":refund:";
  203.     zstripe_checkzLicense($params);
  204.     if (is_file($params['StripeLibPath'])) {
  205.         include_once($params['StripeLibPath']);
  206.     } else if (is_file($params['StripeLibPath'] . "/Stripe.php")) {
  207.         include_once($params['StripeLibPath'] . "/Stripe.php");
  208.     } else if (is_file($params['StripeLibPath'] . "/lib/Stripe.php")) {
  209.         include_once($params['StripeLibPath'] . "/lib/Stripe.php");
  210.     } else {
  211.         throw new Exception("Stripe library not found!");
  212.     }
  213.     if ($params['testmode']) {
  214.         $gateway_Key = $params['keySecretTest'];
  215.     } else {
  216.         $gateway_Key = $params['keySecretLive'];
  217.     }
  218.     Stripe::setapikey($gateway_Key);
  219.     $transid     = $params['transid'];
  220.     $amount      = $params['amount'];
  221.     $amountcents = zstripe_getMoneyAsCents($amount);
  222.     $currency    = $params['currency'];
  223.     try {
  224.         $path .= ":f1:";
  225.         global $chargeObj;
  226.         $chargeObj = Stripe_Charge::retrieve($transid);
  227.     }
  228.     catch (Stripe_CardError $err) {
  229.         $path .= ":f2:";
  230.         return array(
  231.             "status" => "failed",
  232.             "rawdata" => array(
  233.                 "ERRORMSG" => $err->getMessage(),
  234.                 "PATH" => $path
  235.             )
  236.         );
  237.     }
  238.     catch (Stripe_Error $err) {
  239.         $path .= ":f3:";
  240.         return array(
  241.             "status" => "failed",
  242.             "rawdata" => array(
  243.                 "ERRORMSG" => $err->getMessage(),
  244.                 "PATH" => $path
  245.             )
  246.         );
  247.     }
  248.     if ($chargeObj->type) {
  249.         $path .= ":f4:";
  250.         return array(
  251.             "status" => "failed",
  252.             "rawdata" => array(
  253.                 "ERRORTYPE" => $chargeObj->type,
  254.                 "ERRORMSG" => $chargeObj->message,
  255.                 "PATH" => $path
  256.             )
  257.         );
  258.     }
  259.     if ($chargeObj->refunded == "1") {
  260.         $path .= ":f5:";
  261.         return array(
  262.             "status" => "declined",
  263.             "rawdata" => array(
  264.                 "TRANSACTIONID" => $chargeObj->id,
  265.                 "REFUNDED" => $chargeObj->refunded,
  266.                 "ERRORMSG" => "Charge already refunded",
  267.                 "PATH" => $path
  268.             )
  269.         );
  270.     }
  271.     if ($amountcents == 0) {
  272.         $amountcents = $chargeObj->amount;
  273.     }
  274.     try {
  275.         $path .= ":f6:";
  276.         global $chargeObj;
  277.         $refundObj = $chargeObj->refund(array(
  278.             amount => $amountcents
  279.         ));
  280.     }
  281.     catch (Stripe_CardError $err) {
  282.         $path .= ":f7:";
  283.         return array(
  284.             "status" => "failed",
  285.             "rawdata" => array(
  286.                 "ERRORMSG" => $err->getMessage(),
  287.                 "PATH" => $path
  288.             )
  289.         );
  290.     }
  291.     catch (Stripe_Error $err) {
  292.         $path .= ":f8:";
  293.         return array(
  294.             "status" => "failed",
  295.             "rawdata" => array(
  296.                 "ERRORMSG" => $err->getMessage(),
  297.                 "PATH" => $path
  298.             )
  299.         );
  300.     }
  301.     if ($refundObj->type) {
  302.         $path .= ":f9:";
  303.         return array(
  304.             "status" => "failed",
  305.             "rawdata" => array(
  306.                 "ERRORTYPE" => $refundObj->type,
  307.                 "ERRORMSG" => $refundObj->message,
  308.                 "PATH" => $path
  309.             )
  310.         );
  311.     }
  312.     if (!$refundObj->type) {
  313.         $path .= ":f10:";
  314.         return array(
  315.             "status" => "success",
  316.             "transid" => $refundObj->id,
  317.             "fees" => $refundObj->fee * 0.01,
  318.             "rawdata" => array(
  319.                 "TRANSACTIONID" => $refundObj->id,
  320.                 "AMOUNT" => $refundObj->amount,
  321.                 "DESCRIPTION" => $refundObj->description,
  322.                 "FEE" => $refundObj->fee,
  323.                 "PAID" => $refundObj->paid,
  324.                 "CREATED" => $refundObj->created,
  325.                 "payment_gross" => $refundObj->amount,
  326.                 "payment_fee" => $refundObj->fee * 0.01,
  327.                 "payer_id" => $params['gatewayid'],
  328.                 "LIVEMODE" => $refundObj->livemode,
  329.                 "REFUNDED" => $refundObj->refunded,
  330.                 "PATH" => $path
  331.             )
  332.         );
  333.     }
  334.     $path .= ":f11:";
  335.     return array(
  336.         "status" => "failed",
  337.         "rawdata" => array(
  338.             "TYPE" => $refundObj->type,
  339.             "MESSAGE" => $refundObj->message,
  340.             "PATH" => $path
  341.         )
  342.     );
  343. }
  344.  
  345. function zstripe_check_license($licensekey, $localkey = "")
  346. {
  347.     $whmcsurl             = "http://www.zignut.com/order/";
  348.     $licensing_secret_key = "7718c416";
  349.     $check_token          = time() . md5(mt_rand(1000000000, 1e+010) . $licensekey);
  350.     $checkdate            = date("Ymd");
  351.     $usersip              = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : $_SERVER['LOCAL_ADDR'];
  352.     $localkeydays         = 5;
  353.     $allowcheckfaildays   = 5;
  354.     $localkeyvalid        = false;
  355.     if ($localkey) {
  356.         $localkey  = str_replace("\n", "", $localkey);
  357.         $localdata = substr($localkey, 0, strlen($localkey) - 32);
  358.         $md5hash   = substr($localkey, strlen($localkey) - 32);
  359.         if ($md5hash == md5($localdata . $licensing_secret_key)) {
  360.             $localdata         = strrev($localdata);
  361.             $md5hash           = substr($localdata, 0, 32);
  362.             $localdata         = substr($localdata, 32);
  363.             $localdata         = base64_decode($localdata);
  364.             $localkeyresults   = unserialize($localdata);
  365.             $originalcheckdate = $localkeyresults['checkdate'];
  366.             if ($md5hash == md5($originalcheckdate . $licensing_secret_key)) {
  367.                 $localexpiry = date("Ymd", mktime(0, 0, 0, date("m"), date("d") - $localkeydays, date("Y")));
  368.                 if ($localexpiry < $originalcheckdate) {
  369.                     $localkeyvalid = true;
  370.                     $results       = $localkeyresults;
  371.                     $validdomains  = explode(",", $results['validdo' . __FILE__]);
  372.                     if (!in_array($_SERVER['SERVER_NAME'], $validdomains)) {
  373.                         $localkeyvalid             = false;
  374.                         $localkeyresults['status'] = "Invalid";
  375.                         $results                   = array();
  376.                     }
  377.                     $validips = explode(",", $results['validip']);
  378.                     if (!in_array($usersip, $validips)) {
  379.                         $localkeyvalid             = false;
  380.                         $localkeyresults['status'] = "Invalid";
  381.                         $results                   = array();
  382.                     }
  383.                     if ($results['validdirectory'] != dirname("C:\\dezender\\waraxe-ioncube.php")) {
  384.                         $localkeyvalid             = false;
  385.                         $localkeyresults['status'] = "Invalid";
  386.                         $results                   = array();
  387.                     }
  388.                 }
  389.             }
  390.         }
  391.     }
  392.     if (!$localkeyvalid) {
  393.         $postfields['licensekey']    = $licensekey;
  394.         $postfields['do' . __FILE__] = $_SERVER['SERVER_NAME'];
  395.         $postfields['ip']            = $usersip;
  396.         $postfields['dir']           = dirname("C:\\dezender\\waraxe-ioncube.php");
  397.         if ($check_token) {
  398.             $postfields['check_token'] = $check_token;
  399.         }
  400.         if (function_exists("curl_exec")) {
  401.             $ch = curl_init();
  402.             curl_setopt($ch, CURLOPT_URL, $whmcsurl . "modules/servers/licensing/verify.php");
  403.             curl_setopt($ch, CURLOPT_POST, 1);
  404.             curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
  405.             curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  406.             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  407.             $data = curl_exec($ch);
  408.             curl_close($ch);
  409.         } else {
  410.             $fp = fsockopen($whmcsurl, 80, $errno, $errstr, 5);
  411.             if ($fp) {
  412.                 $querystring = "";
  413.                 foreach ($postfields as $k => $v) {
  414.                     $querystring .= "{$k}=" . urlencode($v) . "&";
  415.                 }
  416.                 $header = "POST " . $whmcsurl . "modules/servers/licensing/verify.php HTTP/1.0\r\n";
  417.                 $header .= "Host: " . $whmcsurl . "\r\n";
  418.                 $header .= "Content-type: application/x-www-form-urlencoded\r\n";
  419.                 $header .= "Content-length: " . @strlen($querystring) . "\r\n";
  420.                 $header .= "Connection: close\r\n\r\n";
  421.                 $header .= $querystring;
  422.                 $data = "";
  423.                 @stream_set_timeout($fp, 20);
  424.                 @fputs($fp, $header);
  425.                 $status = @socket_get_status($fp);
  426.                 while (!feof($fp) && $status) {
  427.                     $data .= @fgets($fp, 1024);
  428.                     $status = @socket_get_status($fp);
  429.                 }
  430.                 @fclose($fp);
  431.             }
  432.         }
  433.         if (!$data) {
  434.             $localexpiry = date("Ymd", mktime(0, 0, 0, date("m"), date("d") - ($localkeydays + $allowcheckfaildays), date("Y")));
  435.             if ($localexpiry < $originalcheckdate) {
  436.                 $results = $localkeyresults;
  437.             } else {
  438.                 $results['status']      = "Invalid";
  439.                 $results['description'] = "Remote Check Failed";
  440.                 return $results;
  441.             }
  442.         } else {
  443.             preg_match_all("/<(.*?)>([^<]+)<\\/\\1>/i", $data, $matches);
  444.             $results = array();
  445.             foreach ($matches[1] as $k => $v) {
  446.                 $results[$v] = $matches[2][$k];
  447.             }
  448.         }
  449.         if ($results['md5hash'] && $results['md5hash'] != md5($licensing_secret_key . $check_token)) {
  450.             $results['status']      = "Invalid";
  451.             $results['description'] = "MD5 Checksum Verification Failed";
  452.             return $results;
  453.         }
  454.         if ($results['status'] == "Active") {
  455.             $results['checkdate'] = $checkdate;
  456.             $data_encoded         = serialize($results);
  457.             $data_encoded         = base64_encode($data_encoded);
  458.             $data_encoded         = md5($checkdate . $licensing_secret_key) . $data_encoded;
  459.             $data_encoded         = strrev($data_encoded);
  460.             $data_encoded         = $data_encoded . md5($data_encoded . $licensing_secret_key);
  461.             $data_encoded         = wordwrap($data_encoded, 80, "\n", true);
  462.             $results['localkey']  = $data_encoded;
  463.         }
  464.         $results['remotecheck'] = true;
  465.     }
  466.     unset($postfields);
  467.     unset($data);
  468.     unset($matches);
  469.     unset($whmcsurl);
  470.     unset($licensing_secret_key);
  471.     unset($checkdate);
  472.     unset($usersip);
  473.     unset($localkeydays);
  474.     unset($allowcheckfaildays);
  475.     unset($md5hash);
  476.     return $results;
  477. }
  478.  
  479. function zstripe_checkzLicense($params)
  480. {
  481.     $licensekey = $params['zstripe_licenseKey'];
  482.     $localkey   = file_get_contents("zstripeLicense.txt");
  483.     $results    = zstripe_check_license($licensekey, $localkey);
  484.     if ($results['status'] == "Active") {
  485.         if ($results['localkey']) {
  486.             $localkeydata = $results['localkey'];
  487.             $localkeyFile = fopen("zstripeLicense.txt", "w");
  488.             fwrite($localkeyFile, $localkeydata);
  489.             fclose($localkeyFile);
  490.         }
  491.     } else if ($results['status'] == "Invalid") {
  492.         echo "There is a problem with validating the Payment Gateway License, please check your gateway log";
  493.         return array(
  494.             "status" => "failed",
  495.             "rawdata" => array(
  496.                 "TYPE" => "License Error",
  497.                 "MESSAGE" => "INVALID license, please visit http://zignut.com or contact [email protected]"
  498.             )
  499.         );
  500.     } else if ($results['status'] == "Expired") {
  501.         echo "There is a problem with validating the Payment Gateway License, please check your gateway log";
  502.         return array(
  503.             "status" => "failed",
  504.             "rawdata" => array(
  505.                 "TYPE" => "License Error",
  506.                 "MESSAGE" => "EXPIRED license, please visit http://zignut.com or contact [email protected]"
  507.             )
  508.         );
  509.     } else if ($results['status'] == "Suspended") {
  510.         echo "There is a problem with validating the Payment Gateway License, please check your gateway log";
  511.         return array(
  512.             "status" => "failed",
  513.             "rawdata" => array(
  514.                 "TYPE" => "License Error",
  515.                 "MESSAGE" => "SUSPENDED license, please visit http://zignut.com or contact [email protected]"
  516.             )
  517.         );
  518.     } else {
  519.         echo "There is a problem with validating the Payment Gateway License, please check your gateway log";
  520.         return array(
  521.             "status" => "failed",
  522.             "rawdata" => array(
  523.                 "TYPE" => "License Error",
  524.                 "MESSAGE" => "An unknown error occurred verifying your license(Maybe file permissions on the file?)"
  525.             )
  526.         );
  527.     }
  528. }
  529.  
  530. function zstripe_getMoneyAsCents($value)
  531. {
  532.     $value = preg_replace("/\\,/i", "", $value);
  533.     $value = preg_replace("/([^0-9\\.\\-])/i", "", $value);
  534.     if (!is_numeric($value)) {
  535.         return 0;
  536.     }
  537.     $value = ( double ) $value;
  538.     return round($value, 2) * 100;
  539. }
  540.  
  541. global $version;
  542. $version = "1.34.114";
  543. global $debug;
  544. $debug = "";
  545. print "zStripe " . $version . "\n";
  546. print "To use debug mode:\n";
  547. print " php zstripe.php debug 'TEST_SECRET_KEY' 'PATH_TO_STRIPE_LIB' \n\n";
  548. if (1 < $argc && $argv[1] == "debug") {
  549.     if ($argc < 3) {
  550.         print "No TEST_SECRET_KEY given.\n";
  551.         exit();
  552.     } else {
  553.         $params                               = array(
  554.             "testmode" => "true",
  555.             "keySecretTest" => $argv[2],
  556.             "storelocal" => "false"
  557.         );
  558.         $params['clientdetails']['firstname'] = "Zignut";
  559.         $params['clientdetails']['lastname']  = "Zignut";
  560.         if ($argc < 4) {
  561.             print "Stripe lib Path not supplied.\n";
  562.             exit();
  563.         } else {
  564.             $params['StripeLibPath']          = $argv[3];
  565.             $params['clientdetails']['email'] = "[email protected]";
  566.             $params['cardnum']                = "4242424242424242";
  567.             $params['cardexp']                = "1213";
  568.             $params['cardissuenum']           = "123";
  569.             $params['debug']                  = "true";
  570.             $params['gatewayid']              = "";
  571.             $debug                            = "true";
  572.         }
  573.     }
  574. }
  575. $path = "";
  576. if ($debug) {
  577.     print "DEBUG MODE ON " . $debug . "\n";
  578.     zstripe_storeremote($params);
  579.     exit();
  580. } else {
  581.     if ($params['storelocal']) {
  582.         return 1;
  583.     }
  584.     function zstripe_storeremote($params)
  585.     {
  586.         $debug = $params['debug'];
  587.         $path .= ":storeremote:";
  588.         if ($debug == "true") {
  589.         } else {
  590.             zstripe_checkzLicense($params);
  591.         }
  592.         if (is_file($params['StripeLibPath'])) {
  593.             include_once($params['StripeLibPath']);
  594.         } else if (is_file($params['StripeLibPath'] . "/Stripe.php")) {
  595.             include_once($params['StripeLibPath'] . "/Stripe.php");
  596.         } else {
  597.             include_once($params['StripeLibPath'] . "/lib/Stripe.php");
  598.             throw new Exception("Stripe library not found!");
  599.         }
  600.         if ($params['testmode']) {
  601.             $gateway_Key = $params['keySecretTest'];
  602.         } else {
  603.             $gateway_Key = $params['keySecretLive'];
  604.         }
  605.         Stripe::setapikey($gateway_Key);
  606.         if ($params['cardnum'] == "" && $params['gatewayid']) {
  607.             $path .= ":delete:";
  608.             return array(
  609.                 "status" => "success",
  610.                 "rawdata" => array(
  611.                     "CUSTOMERID" => $params['gatewayid'],
  612.                     "DELETED" => "Stripe doesn't support deleting card data, only customers.  And deleting customer data has proven to be problematic so it has been disabled.  Card information will still be removed from WHMCS.",
  613.                     "PATH" => $path
  614.                 )
  615.             );
  616.         } else {
  617.             try {
  618.             }
  619.             catch (Stripe_CardError $err) {
  620.                 $path .= ":a1:";
  621.                 return array(
  622.                     "status" => "failed",
  623.                     "rawdata" => array(
  624.                         "ERRORMSG" => $err->getMessage(),
  625.                         "PATH" => $path
  626.                     )
  627.                 );
  628.             }
  629.             catch (Stripe_Error $err) {
  630.                 $path .= ":a2:";
  631.                 return array(
  632.                     "status" => "failed",
  633.                     "rawdata" => array(
  634.                         "ERRORMSG" => $err->getMessage(),
  635.                         "PATH" => $path
  636.                     )
  637.                 );
  638.             }
  639.             if ($customerObj->type) {
  640.                 $path .= ":a3:";
  641.                 return array(
  642.                     "status" => "failed",
  643.                     "rawdata" => array(
  644.                         "ERRORTYPE" => $customerObj->type,
  645.                         "ERRORMSG" => $customerObj->message,
  646.                         "PATH" => $path
  647.                     )
  648.                 );
  649.             }
  650.             try {
  651.                 $returnObj = $customerObj->delete();
  652.             }
  653.             catch (Stripe_CardError $err) {
  654.                 $path .= ":a4:";
  655.                 return array(
  656.                     "status" => "failed",
  657.                     "rawdata" => array(
  658.                         "ERRORMSG" => $err->getMessage(),
  659.                         "PATH" => $path
  660.                     )
  661.                 );
  662.             }
  663.             catch (Stripe_Error $err) {
  664.                 $path .= ":a5:";
  665.                 return array(
  666.                     "status" => "failed",
  667.                     "rawdata" => array(
  668.                         "ERRORMSG" => $err->getMessage(),
  669.                         "PATH" => $path
  670.                     )
  671.                 );
  672.             }
  673.             if ($returnObj->type) {
  674.                 $path .= ":a6:";
  675.                 return array(
  676.                     "status" => "failed",
  677.                     "rawdata" => array(
  678.                         "ERRORTYPE" => $returnObj->type,
  679.                         "ERRORMSG" => $returnObj->message,
  680.                         "PATH" => $path
  681.                     )
  682.                 );
  683.             }
  684.             $path .= ":a7:";
  685.             return array(
  686.                 "status" => "success",
  687.                 "rawdata" => array(
  688.                     "CUSTOMERID" => $returnObj->id,
  689.                     "DELETED" => $returnObj->deleted,
  690.                     "PATH" => $path
  691.                 )
  692.             );
  693.         }
  694.         if ($params['gatewayid'] == "") {
  695.             $path .= ":create:";
  696.             try {
  697.                 global $returnObj;
  698.                 if (1 < strlen($params['cccvv'])) {
  699.                     $returnObj = Stripe_Customer::create(array(
  700.                         "description" => $params['clientdetails']['email'],
  701.                         "card" => array(
  702.                             "name" => $params['clientdetails']['firstname'] . " " . $params['clientdetails']['lastname'],
  703.                             "number" => $params['cardnum'],
  704.                             "exp_month" => substr($params['cardexp'], 0, 2),
  705.                             "exp_year" => "20" . substr($params['cardexp'], 2, 2),
  706.                             "cvc" => $params['cccvv'],
  707.                             "address_line1" => $params['clientdetails']['address1'],
  708.                             "address_line2" => $params['clientdetails']['address2'],
  709.                             "address_zip" => $params['clientdetails']['postcode'],
  710.                             "address_state" => $params['clientdetails']['state']
  711.                         ),
  712.                         "email" => $params['clientdetails']['email']
  713.                     ));
  714.                 } else {
  715.                     $returnObj = Stripe_Customer::create(array(
  716.                         "description" => $params['clientdetails']['email'],
  717.                         "card" => array(
  718.                             "name" => $params['clientdetails']['firstname'] . " " . $params['clientdetails']['lastname'],
  719.                             "number" => $params['cardnum'],
  720.                             "exp_month" => substr($params['cardexp'], 0, 2),
  721.                             "exp_year" => "20" . substr($params['cardexp'], 2, 2),
  722.                             "address_line1" => $params['clientdetails']['address1'],
  723.                             "address_line2" => $params['clientdetails']['address2'],
  724.                             "address_zip" => $params['clientdetails']['postcode'],
  725.                             "address_state" => $params['clientdetails']['state']
  726.                         ),
  727.                         "email" => $params['clientdetails']['email']
  728.                     ));
  729.                 }
  730.             }
  731.             catch (Stripe_CardError $err) {
  732.                 $path .= ":b1:";
  733.                 return array(
  734.                     "status" => "failed",
  735.                     "rawdata" => array(
  736.                         "ERRORMSG" => $err->getMessage(),
  737.                         "PATH" => $path
  738.                     )
  739.                 );
  740.             }
  741.             catch (Stripe_Error $err) {
  742.                 $path .= ":b2:";
  743.                 return array(
  744.                     "status" => "failed",
  745.                     "rawdata" => array(
  746.                         "ERRORMSG" => $err->getMessage(),
  747.                         "PATH" => $path
  748.                     )
  749.                 );
  750.             }
  751.             if ($returnObj->type) {
  752.                 $path .= ":b3:";
  753.                 return array(
  754.                     "status" => "failed",
  755.                     "rawdata" => array(
  756.                         "ERRORTYPE" => $returnObj->type,
  757.                         "ERRORMSG" => $returnObj->message,
  758.                         "PATH" => $path
  759.                     )
  760.                 );
  761.             }
  762.             $path .= ":b4:";
  763.             return array(
  764.                 "status" => "success",
  765.                 "gatewayid" => $returnObj->id,
  766.                 "rawdata" => array(
  767.                     "CREATED" => $returnObj->created,
  768.                     "CUSTOMERID" => $returnObj->id,
  769.                     "LIVEMODE" => $returnObj->livemode,
  770.                     "CUSTOMEREMAIL" => $returnObj->description,
  771.                     "PATH" => $path
  772.                 )
  773.             );
  774.         }
  775.         if ($params['cardnum'] != "" && $params['gatewayid'] != "") {
  776.             $path .= ":update:";
  777.             try {
  778.                 global $customerObj;
  779.                 $customerObj = Stripe_Customer::retrieve($params['gatewayid']);
  780.             }
  781.             catch (Stripe_CardError $err) {
  782.                 $path .= ":c1:";
  783.                 return array(
  784.                     "status" => "failed",
  785.                     "rawdata" => array(
  786.                         "ERRORMSG" => $err->getMessage(),
  787.                         "PATH" => $path
  788.                     )
  789.                 );
  790.             }
  791.  //=================================PAYMENT==========================================//
Add Comment
Please, Sign In to add comment