예제 #1
0
 public function testSetPreferredPaymentProfile()
 {
     $partner = new Partner();
     $paymentProfile = new PaymentProfile();
     $paymentProfile->setReference('profile1');
     $partner->setPreferredPaymentProfile($paymentProfile);
     $this->assertSame($paymentProfile, $partner->getPreferredPaymentProfile());
     $this->assertContains($paymentProfile, $partner->getPaymentProfiles(), 'a profile should have been added to the collection of profiles');
     $paymentProfile2 = new PaymentProfile();
     $paymentProfile2->setReference('profile2');
     $partner->addPaymentProfile($paymentProfile2);
     $this->assertCount(2, $partner->getPaymentProfiles());
     $partner->setPreferredPaymentProfile($paymentProfile2);
     $this->assertSame($paymentProfile2, $partner->getPreferredPaymentProfile());
     $this->assertCount(2, $partner->getPaymentProfiles());
 }
 /**
  * This will delete a payment profile belonging to the customer on the subscription.
  * Please note that if the customer has multiple subscriptions, the payment profile will be removed from all of them.
  *
  * Please note that if you delete the default payment profile for a subscription, there is currently no way to designate a
  * different payment profile as the default via the API. You may want to Update the subscription instead.
  * To establish a new default payment profile after it has been deleted, either prompt the user to enter a card in the
  * billing portal or on the self-service page, or visit the Payment Details tab on the subscription in the Admin UI and use
  * the “Add New Credit Card” or “Make Active Payment Method” link, (depending on whether there are other cards present.)
  *
  * @param \Litwicki\Bundle\ChargifyBundle\Handler\PaymentProfile $entity
  *
  * @throws \Exception
  */
 public function deletePaymentProfile(PaymentProfile $entity)
 {
     try {
         $uri = sprintf('/subscriptions/<subscription_id>/payment_profiles/%s', $entity->getSubscriptionId(), $entity->getId());
         $response = $this->request($uri, 'DELETE');
         return $this->responseToArray($response);
     } catch (\Exception $e) {
         throw $e;
     }
 }
 function purchaseContact($_index = null, $_cache = null)
 {
     $_JSON = array();
     $_JSON['error'] = '';
     $_JSON['code'] = '';
     $_JSON['credits'] = 0;
     $_JSON['contacts'] = 0;
     if (Auth::check()) {
         $credits = Auth::user()->credits;
         $subscriptions = Auth::user()->subscription()->first();
         if ($subscriptions != null) {
             $transactions = $subscriptions->transaction()->get();
             if (count($transactions) > 0) {
                 foreach ($transactions as $transaction) {
                     $credits = $credits + $transaction->credits;
                 }
             }
         }
         $_JSON['error'] = '';
         $user = User::find(Auth::user()->id);
         $customername = $user->firstname . " " . $user->lastname;
         if ($credits == 0) {
             $_JSON['card'] = '';
             $_JSON['last4'] = '';
             $payment_profile = PaymentProfile::whereUser_id($user->id)->first();
             if (!empty($payment_profile)) {
                 $responseData = unserialize($payment_profile->response);
                 $responseData = $responseData->__toArray();
                 $cards = $responseData['cards']->__toArray();
                 if ($cards['total_count'] > 0) {
                     $card = $cards['data'][0]->__toArray();
                     $_JSON['card'] = $card['brand'];
                     $_JSON['last4'] = $card['last4'];
                 }
             }
             $_JSON['error'] = 'You don&#39;t have sufficient funds to purchase contacts';
         } else {
             $login_user_id = Auth::id();
             $index = Input::get('index', 0);
             if ($_cache == null) {
                 $CONTACTS = unserialize($user->cache);
             } else {
                 $CONTACTS = $_cache;
             }
             $_JSON['info1'] = $CONTACTS[$index]["linkedin"];
             $agents = User::where("status", "=", User::STATUS_AGENT)->get();
             $min = 1000000;
             $min_id = NULL;
             foreach ($agents as $agent) {
                 $linkedin_list = LinkedinContact::where("agent_id", "=", $agent->id)->where("status", "=", LinkedinContact::INCOMPLETE)->get();
                 $count = 0;
                 foreach ($linkedin_list as $linkedin_item) {
                     $count++;
                 }
                 if ($count < $min) {
                     $min = $count;
                     $min_id = $agent->id;
                 }
             }
             $linkedin_contact = LinkedinContact::where("url", "=", base64_decode($CONTACTS[$index]["linkedin"]))->first();
             if (!empty($min_id)) {
                 $linkedin_contact->agent_id = $min_id;
                 $linkedin_contact->started = 1;
                 $linkedin_contact->save();
             }
             // Automation Start
             $company_name = $CONTACTS[$index]['company_name'];
             $company_domain = '';
             if ($company_name != '') {
                 $obj = new GoogleCustomSearch();
                 $company_domain = $obj->makeCall($company_name);
                 //google Search Domain
             }
             if ($company_domain != '') {
                 $this->addNewLead($company_domain, $linkedin_contact->id);
             }
             // Automation End
             $_JSON['info2'] = $linkedin_contact;
             if ($linkedin_contact != null) {
                 $_JSON['info3'] = "saveToList";
                 $this->saveToList(Auth::user()->id, serialize($CONTACTS[$index]), $linkedin_contact->id);
                 $_JSON['credits'] = $credits - 1;
                 //send email to all addresses that are added from admin
                 $contact_data = array("firstname" => $linkedin_contact->firstname, "lastname" => $linkedin_contact->lastname, "title" => $linkedin_contact->title, "company" => $linkedin_contact->company, "location" => $linkedin_contact->location, "url" => $linkedin_contact->url);
                 $agent_alerts = Settings::all();
                 foreach ($agent_alerts as $alert) {
                     $contact_data['customername'] = $customername;
                     $contact_data['agentname'] = $alert['name'];
                     $contact_data['agentemail'] = $alert['value'];
                     Session::put('agentemail', $alert['value']);
                     Mail::queue('emails/agent/agent-added-contact', $contact_data, function ($message) {
                         $message->to(Session::get('agentemail'), 'abc')->subject('A new lead has been added by a user.');
                     });
                 }
                 // send to admin
                 $contact_data['customername'] = $customername;
                 $contact_data['agentname'] = 'Admin';
                 $contact_data['agentemail'] = '*****@*****.**';
                 Mail::queue('emails/agent/admin-added-contact', $contact_data, function ($message) {
                     $message->to('*****@*****.**', 'abc')->subject('A new lead has been added by a user.');
                 });
             }
         }
         $_JSON['contacts'] = count($user->lists()->first()->linkedinContact()->get());
     } else {
         $_JSON['error'] = '';
         $_JSON['code'] = '0001';
     }
     if ($_index == 5) {
         Log::notice("error");
     } else {
         Log::notice("json.response");
     }
     if ($_index == 5) {
         return $_JSON["error"];
     } else {
         return Response::json($_JSON);
     }
 }