/**
  * 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 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();
 }
示例#3
0
            $city = $order[26];
            $state = $order[27];
            $country = $order[28];
            $zip = $order[29];
        }
        $invoice = $thisapp->blankOrder($con[0]['Id'], 'EKM imported order.', date('Ymd'), 0, 0);
        //$invoice=$thisapp->dsAdd('Job',array('ContactId'=>$con[0]['Id'],'JobTitle'=>'EKM imported order for order number ('.$order[2].')','ShipCity'=>$city,'ShipCompany'=>$company,'ShipCountry'=>$country,'ShipFirstName'=>$fname,'ShipLastName'=>$lname,'ShipPhone'=>$phone,'ShipState'=>$state,'ShipStreet1'=>$add1,'ShipStreet2'=>$add2,'ShipZip'=>$zip));
        //echo 'Adding  order for contact id : '.$data[0]['Id'].'<br>';
    } else {
        //if this is not a new order then add order items to the existing order
        /**** These are the indexes for product information ****
         * 		39=ProductId
         * 		40=ProductName
         * 		41=ProductCode (mapped to ShortDescription in IS)
         * 		42=ProductOptions
         * 		43=ProductPrice
         * 		44=ProductDiscount
         * 		45=ProductDelivery
         * 		46=ProductQuantity (this would go on an invoice rather than in a product definition)
         * 		47=ProductRRP (Recommended Retail Price)*/
        $prod = $thisapp->dsQuery('Product', 1, 0, array('ShortDescription' => $order[39]), array('Id'));
        $dat = $thisapp->addOrderItem($invoice, $prod[0]['Id'], 4, $prod[43], $order[46], $order[40], 'EKM imported invoice item');
        echo 'Adding produce (' . $prod[0]['Id'] . ') for order number ' . $invoice . '<br />';
    }
}
$orderDate = substr($order[3], 1, 8);
$pDate = $app->infuDate($orderDate);
$dat = $thisapp->addOrderItem($invoice, 0, 4, -$discount, 1, 'Total Discount', 'EKM imported invoice item');
$dat = $thisapp->addOrderItem($invoice, 0, 1, $shipping, 1, 'Total Shipping Cost', 'EKM imported invoice item');
$dat = $thisapp->manualPmt($invoice, $total, $pDate, 'Manual Credit Card Payment', 'EKM imported payment', true);
fclose($file);
<?php

require_once "../src/isdk.php";
$app = new iSDK();
if ($app->cfgCon("connectionName")) {
    echo "connected<br/>";
    echo "app connected<br/>";
    $currentDate = date("d-m-Y");
    $oDate = $app->infuDate($currentDate);
    echo "date set<br/>";
    $cid = 36;
    $newOrder = $app->blankOrder($cid, "New Order for Contact " . $cid, $oDate, 0, 0);
    echo "New order created=" . $newOrder . "<br/>";
    $result = $app->addOrderItem($newOrder, 0, 4, 66.66, 1, "Infusionsoft Stuff", "new stuff!");
    echo "item added<br/>";
    $operation = $app->manualPmt($newOrder, 66.66, $oDate, "Cash", "fakemoney", false);
    if ($operation) {
        echo "payment has been added for invoiceId-" . $newOrder;
    } else {
        echo "Manual Payment Failed<br />";
    }
} else {
    echo "Connection Failed";
}