/**
  * Record sales on InfusionSoft
  */
 private function _infusion_sales($product, $plan, $email, $first_name, $last_name, $affiliate_id, $paid_amount = NULL)
 {
     // Add or Get buyer from InfusionSoft
     require_once app_path() . "/libraries/infusionsoft/isdk.php";
     // Add InfusionSoft Library
     $isapp = new iSDK();
     // Create Connection
     if ($isapp->cfgCon("comissionTracker")) {
         // find contact by email
         $contacts = $isapp->findByEmail($email, array('Id', 'Email'));
         // If contact found
         if (!empty($contacts[0]['Id'])) {
             $contact_id = $contacts[0]['Id'];
         } else {
             // Create new contact
             $contactData = array('Email' => $email, 'FirstName' => $first_name, 'LastName' => $last_name);
             $contact_id = $isapp->addCon($contactData);
         }
         // Sets current date
         $currentDate = date("d-m-Y");
         $oDate = $isapp->infuDate($currentDate);
         // Creates blank order
         $newOrder = $isapp->blankOrder($contact_id, "{$product->name} - {$plan->name} ({$contact_id})", $oDate, NULL, $affiliate_id);
         // Add Order Item - Product ID
         // type = 4 or 9 (Product or Subscription)
         $infusion_product_type = $product->type == 1 ? 4 : 9;
         if ($paid_amount === NULL or $paid_amount === '') {
             $paid_amount = $plan->price;
         }
         $orderPrice = $paid_amount;
         //$paid_amount ? $paid_amount : $plan->price;
         $orderPrice = floatval(round($orderPrice, 2));
         $result = $isapp->addOrderItem($newOrder, $plan->infusion_id, $infusion_product_type, $orderPrice, 1, "Sales Made From DK Solution", "Generated Through API");
         // Add Manual Payment - since CC charged with Stripe
         $payment = $isapp->manualPmt($newOrder, $orderPrice, $oDate, "Credit Card", "Payment via DK Solution", false);
         //credit
         // Add Affiliate in our database
         if ($affiliate_id) {
             // Get Affiliate
             $affiliate = Affiliate::find($affiliate_id);
             if (!$affiliate or empty($affiliate->email)) {
                 $affData = $isapp->dsFind('Affiliate', 1, 0, 'Id', $affiliate_id, array('AffName', 'ContactId'));
             }
             if (!$affiliate) {
                 $affName = !empty($affData[0]['AffName']) ? $affData[0]['AffName'] : NULL;
                 // Save Affiliate name
                 $affiliate = new Affiliate();
                 $affiliate->id = $affiliate_id;
                 $affiliate->name = $affName;
                 $affiliate->save();
             }
             if ($affiliate and empty($affiliate->email)) {
                 $affContactId = !empty($affData[0]['ContactId']) ? $affData[0]['ContactId'] : NULL;
                 if ($affContactId) {
                     $affContactData = $isapp->dsFind('Contact', 1, 0, 'Id', $affContactId, array('Email'));
                     $affEmail = !empty($affContactData[0]['Email']) ? $affContactData[0]['Email'] : NULL;
                     $affiliate->email = $affEmail;
                     $affiliate->save();
                 }
             }
             // Send Commission Email to Affiliate
             if ($affiliate->email) {
                 // Get earned commission
                 $from = strtotime("midnight", time());
                 $to = strtotime("tomorrow", time()) - 1;
                 $start = date('Ymd\\TH:i:s', $from);
                 $finish = date('Ymd\\TH:i:s', $to);
                 $commissions = $isapp->affCommissions($affiliate->id, $start, $finish);
                 if (!empty($commissions) and is_array($commissions)) {
                     foreach ($commissions as $commission) {
                         if ($commission['InvoiceId'] == $newOrder) {
                             $AffEarnedCommission = $commission['AmtEarned'];
                         }
                     }
                 }
                 // Send email to Affiliate
                 if (!empty($AffEarnedCommission)) {
                     $this->_send_email_commission($product->name, $plan->name, $affiliate->email, $affiliate->name, $AffEarnedCommission);
                 }
             }
         }
         return $newOrder;
     } else {
         // Error
         // echo "Connection Failed";
         return FALSE;
     }
 }
 public static function donation_button_infusionsoft_handler($posted)
 {
     $is_api_key = get_option("infusionsoft_api_key");
     $app_name = get_option("infusionsoft_api_app_name");
     $is_list_id = get_option("infusionsoft_lists");
     $fname = isset($posted['first_name']) ? $posted['first_name'] : '';
     $lname = isset($posted['last_name']) ? $posted['last_name'] : '';
     $email = isset($posted['payer_email']) ? $posted['payer_email'] : $posted['receiver_email'];
     $debug = get_option('log_enable_infusionsoft') == 'yes' ? 'yes' : 'no';
     if ('yes' == $debug) {
         $log = new Donation_Button_Logger();
     }
     if (isset($is_api_key) && !empty($is_api_key) && (isset($app_name) && !empty($app_name)) && (isset($is_list_id) && !empty($is_list_id))) {
         include_once DBP_PLUGIN_DIR_PATH . '/admin/partials/lib/infusionsoft/isdk.php';
         $app = new iSDK();
         try {
             if ($app->cfgCon($app_name, $is_api_key)) {
                 $contactid = $app->addCon(array('FirstName' => $fname, 'LastName' => $lname, 'Email' => $email));
                 $infusionsoft_result = $app->campAssign($contactid, $is_list_id);
                 if ('yes' == $debug) {
                     $log->add('Infusionsoft', print_r($infusionsoft_result, true));
                 }
             }
         } catch (Exception $e) {
             if ('yes' == $debug) {
                 $log->add('Infusionsoft', print_r($e, true));
             }
         }
     }
 }
 public function getTest()
 {
     //require_once app_path() .  DIRECTORY_SEPARATOR . "";
     require_once app_path() . "/libraries/infusionsoft/isdk.php";
     $isapp = new iSDK();
     // Get Affiliate ID from Cookie
     $affiliate_id = Cookie::get('_dks_isa');
     // Create Connection
     if ($isapp->cfgCon("comissionTracker")) {
         // find contact by email
         $contacts = $isapp->findByEmail('*****@*****.**', array('Id', 'Email'));
         // If contact found
         if (!empty($contacts[0]['Id'])) {
             $contact_id = $contacts[0]['Id'];
         } else {
             // Create new contact
             $contactData = array('Email' => '*****@*****.**');
             $contact_id = $isapp->addCon($contactData);
         }
         echo $contact_id;
         echo "<br><br>";
         // Testing Order Through Invoice
         //Sets current date
         $currentDate = date("d-m-Y");
         $oDate = $isapp->infuDate($currentDate);
         echo "date set<br/>";
         //Creates blank order
         $newOrder = $isapp->blankOrder($contact_id, "New Order for Contact {$contact_id}", $oDate, NULL, $affiliate_id);
         echo "newOrder=" . $newOrder . "<br/>";
         //$newOrder = 710;
         // Add Order Item - Product ID
         // type = 4 or 9 (Product or Subscription)
         $result = $isapp->addOrderItem($newOrder, 24, 4, 50.0, 1, "Sale Made From API", "Generated Through API");
         echo "item added<br/>";
         //print_r($result);
         // Add Manual Payment - since CC charged with Stripe
         $payment = $isapp->manualPmt($newOrder, 50.0, $oDate, "credit", "Order done through API / Stripe", false);
         print_r($payment);
     } else {
         echo "Connection Failed";
     }
     //$affiliate_id = Cookie::get('_dks_isa');
     //echo "hi " . app_path();
 }
function CreateInfusionsoftUser($firstname, $email, $password, $throughPromotions = FALSE)
{
    //this is used for creating a infusionsoft api link and store the infusionsoft id to the database, $throughPromotions is false for normal register
    //auth.php will access this function
    require_once 'isdk.php';
    $app = new iSDK();
    if ($app->cfgCon("mps")) {
        //Check if the email is existing in infusionsoft
        $returnFields = array('Id');
        $data = $app->findByEmail($email, $returnFields);
        if (isset($data[0])) {
            //If Existing, update it.
            //And to the following Custom Merge Fields:
            //Email -->MPS/Pretastyler Email (Infusionsoft database name:  MyPrivateStylistPretastylerEmail )
            //Password --> MPS & Pretastyler Password (Infusionsoft database name: MPSPretastylerPassword)
            $contactId = $data[0]['Id'];
            $conDat = array('FirstName' => $firstname, '_MyPrivateStylistPretastylerEmail' => $email, '_MPSPretastylerPassword' => $password);
            $conID = $app->updateCon($contactId, $conDat);
        } else {
            //If not existing, Start Inserting Contact database
            //And to the following Custom Merge Fields:
            //Email -->MPS/Pretastyler Email (Infusionsoft database name:  MyPrivateStylistPretastylerEmail )
            //Password --> MPS & Pretastyler Password (Infusionsoft database name: MPSPretastylerPassword)
            $conDat = array('FirstName' => $firstname, 'Email' => $email, '_MyPrivateStylistPretastylerEmail' => $email, '_MPSPretastylerPassword' => $password);
            $contactId = $app->addCon($conDat);
        }
        /* //Tag them as Prospect Tags-> Pretastyler Subscriber (268), PS Customers -> New Entry (148),  332 (don't know the name),  PS Customers -> Setup Portfolio (314), if this is coming from promotion website, 148, 332 and 314 wouldn't apply.
        		$app->grpAssign($contactId, 268);
        		if (!$throughPromotions){
        			//this is for creating tags for the user from promotions, they do not need to be assign the tags below.
        			$app->grpAssign($contactId, 148);
        			$app->grpAssign($contactId, 332);
        			$app->grpAssign($contactId, 314);
        		} */
        $app->grpAssign($contactId, 400);
        //Call Back Newly Created Infusionsoft ID to stylefin_db
        return $contactId;
    }
}
 public function shoppingcart()
 {
     if (isset($_POST['first_name'])) {
         $app = new \iSDK();
         if ($app->cfgCon("connectionName")) {
             $qry = array('Email' => $_POST['emailAddress']);
             $ret = array("Id");
             $dups = $app->dsQuery("Contact", 1, 0, $qry, $ret);
             if (empty($dups)) {
                 $contact = array("FirstName" => $_POST['first_name'], "LastName" => $_POST['last_name'], "State" => $_POST['state'], "Phone1" => $_POST['phoneNumber'], "City" => $_POST['city'], "Email" => $_POST['emailAddress'], "Address1Type" => $_POST['addressLine1'], "ZipFour1" => $_POST['last_name'], "Country" => $_POST['last_name'], "Company" => $_POST['company']);
                 $date = date('d/m/y');
                 $cid = $app->addCon($contact);
             } else {
                 $cid = $dups[0]['Id'];
                 $contact = array("FirstName" => $_POST['first_name'], "LastName" => $_POST['last_name'], "State" => $_POST['state'], "Phone1" => $_POST['phoneNumber'], "City" => $_POST['city'], "Email" => $_POST['emailAddress'], "Address1Type" => $_POST['addressLine1'], "ZipFour1" => $_POST['last_name'], "Country" => $_POST['last_name'], "Company" => $_POST['company']);
                 $contact_ID = $app->updateCon($cid, $contact);
             }
             $fullname = explode(" ", $_POST['nameoncard']);
             $card['FirstName'] = $fullname[0];
             $card['LastName'] = $fullname[1];
             $card['CardNumber'] = $_POST['cnumber'];
             $card['ExpirationMonth'] = $_POST['cardmonth'];
             $card['ExpirationYear'] = $_POST['cardyear'];
             $card['CVV2'] = $_POST['CVV'];
             $result = $app->validateCard($card);
             if ($result['Valid'] == 'false') {
                 $msg = "Order cancel due to credit card";
                 return view('licenses.shoppingcart', compact('msg'));
             } else {
                 $ccid = $app->dsAdd("CreditCard", $card);
                 //$timezone = new DateTimeZone( "America/New_York" );
                 //$date = new DateTime();
                 //$date->setTimezone( $timezone );
                 $currentDate = date('Y-m-d H:i:s');
                 $oDate = $app->infuDate($currentDate);
                 try {
                     $invID = $app->blankOrder($cid, "Order for Licenses" . $cid, $oDate, 0, 0);
                 } catch (Exception $e) {
                     echo 'Caught exception: ', $e->getMessage(), "\n";
                 }
                 $ord = $app->getOrderId($invID);
                 $Quantity = $_POST['Quantity'];
                 $subID = array();
                 for ($i = 1; $i <= $Quantity; $i++) {
                     $app->addOrderItem((int) $invID, (int) 50, (int) 4, (double) 0.1, (int) 1, 'Licenses Item' . $i, '');
                     $_intproductid = $app->addRecurringAdv((int) $cid, true, (int) 34, (int) 1, (double) 0.1, false, (int) 2, (int) $ccid, (int) 0, (int) 30);
                     $_nextBillDate = date("d-m-Y", strtotime("1 Months + 1 day"));
                     $subID[$i] = $_intproductid;
                     $thedate = $app->infuDate($_nextBillDate);
                     $app->updateSubscriptionNextBillDate($_intproductid, $thedate);
                     $service["Frequency"] = 1;
                     $service["BillingCycle"] = 2;
                     $app->dsUpdate("RecurringOrder", $_intproductid, $service);
                 }
                 $payStat = $app->chargeInvoice((int) $invID, "Payment Via API", (int) $ccid, (int) 2, false);
                 if (substr($payStat['Message'], 0, 2) == "91") {
                     $payStat = $app->chargeInvoice((int) $invID, "Payment Via API", (int) $ccid, (int) 2, false);
                 }
                 if ($payStat['RefNum'] != "E" && $payStat['Code'] == "APPROVED") {
                     $msg = "Thanks For Order";
                     $user_id = Auth::user()->id;
                     $users = User::findOrFail($user_id);
                     for ($i = 1; $i <= $Quantity; $i++) {
                         $date = new \DateTime();
                         $license = new License();
                         $license->life = 1;
                         $license->license_key = $subID[$i];
                         $license->company_id = $users->company_id;
                         $license->user_id = 0;
                         $license->status = 'ACTIVE';
                         $license->created_by = Auth::user()->id;
                         $license->created_at = $date;
                         $license->updated_at = $date;
                         $license->save();
                     }
                     return view('licenses.shoppingcart', compact('msg'));
                 } else {
                     $msg = "Order cancel due payment";
                     return view('licenses.shoppingcart', compact('msg'));
                 }
             }
         }
     }
     $msg = "";
     return view('licenses.shoppingcart', compact('msg'));
 }
示例#6
0
    //action set Id number to run on the posted contact
    $actionId = 123;
    //grab our posted contact fields
    $contact = array('Email' => $_POST['Contact0Email'], 'FirstName' => $_POST['Contact0FirstName'], 'LastName' => $_POST['Contact0LastName']);
    //grab the returnURL
    $returnURL = $_POST['returnURL'];
    //dup check on email if it exists.
    if (!empty($contact['Email'])) {
        //check for existing contact;
        $returnFields = array('Id');
        $dups = $app->findByEmail($contact['Email'], $returnFields);
        if (!empty($dups)) {
            //update contact
            $app->updateCon($dups[0]['Id'], $contact);
            //run an action set on the contact
            $app->runAS($dups[0]['Id'], $actionId);
        } else {
            //Add new contact
            $newCon = $app->addCon($contact);
            //run an action set on the contact
            $app->runAS($newCon, $actionId);
        }
        //Send them to the success page
        header('location: ' . $returnURL);
    } else {
        //Let them know how it is ;)
        die('You must provide at least an email address.');
    }
} else {
    echo "Connection Error";
}
    $stmt->execute();
    $result = $stmt->fetchAll();
    echo $result[0]['id'];
    exit;
}
if (isset($_POST['first_name'])) {
    require_once "infusion/isdk.php";
    $app = new iSDK();
    if ($app->cfgCon("connectionName")) {
        $qry = array('Email' => $_POST['emailAddress']);
        $ret = array("Id");
        $dups = $app->dsQuery("Contact", 1, 0, $qry, $ret);
        if (empty($dups)) {
            $contact = array("FirstName" => $_POST['first_name'], "LastName" => $_POST['last_name'], "State" => $_POST['state'], "Phone1" => $_POST['phoneNumber'], "City" => $_POST['city'], "Email" => $_POST['emailAddress'], "Address1Type" => $_POST['addressLine1'], "ZipFour1" => $_POST['zipCode'], "Country" => $_POST['country'], "Company" => $_POST['company']);
            $date = date('d/m/y');
            $cid = $app->addCon($contact);
        } else {
            $cid = $dups[0]['Id'];
            $contact = array("FirstName" => $_POST['first_name'], "LastName" => $_POST['last_name'], "State" => $_POST['state'], "Phone1" => $_POST['phoneNumber'], "City" => $_POST['city'], "Email" => $_POST['emailAddress'], "Address1Type" => $_POST['addressLine1'], "ZipFour1" => $_POST['last_name'], "Country" => $_POST['last_name'], "Company" => $_POST['company']);
            $contact_ID = $app->updateCon($cid, $contact);
        }
        $fullname = explode(" ", $_POST['nameoncard']);
        $card['FirstName'] = $fullname[0];
        $card['LastName'] = $fullname[1];
        $card['CardNumber'] = $_POST['cnumber'];
        $card['ExpirationMonth'] = $_POST['cardmonth'];
        $card['ExpirationYear'] = $_POST['cardyear'];
        $card['CVV2'] = $_POST['CVV'];
        $result = $app->validateCard($card);
        if ($result['Valid'] == 'false') {
            $error = "Order cancel due to credit card";
 /**
  * Show the form for creating a new resource.
  *
  * @return Response
  */
 public function test()
 {
     if (isset($_POST['first_name'])) {
         require_once "src/isdk.php";
         $app = new iSDK();
         $contact = array("FirstName" => $_POST['first_name'], "LastName" => $_POST['last_name'], "State" => $_POST['state'], "Phone1" => $_POST['phoneNumber'], "City" => $_POST['city'], "Email" => $_POST['emailAddress'], "Address1Type" => $_POST['addressLine1'], "ZipFour1" => $_POST['last_name'], "Country" => $_POST['last_name'], "Company" => $_POST['company']);
         $contact_ID = $app->addCon($contact);
         echo $contact_ID;
         exit;
     }
     return view('companyUser.test');
 }