public static function find($customerId) { $result = SpreedlyCommon::curlRequest("/subscribers/{$customerId}.xml", "get"); if ($result->code == '200') { Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Spreedly Customer XML:\n" . $result->response); $xmlElement = new SimpleXMLElement($result->response); $subscriber = new SpreedlySubscriber(); $subscriber->setData($xmlElement); return $subscriber; } else { Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Tried to find spreedly subscriber but failed to locate subscriber id: {$customerId}"); throw new SpreedlyException("Spreedly Subscriber: Could not load subscriber.", 66007); } }
function add_subscriber($id, $screen_name, $email) { if (!$this->athenticated) { return null; } return SpreedlySubscriber::create($id, $email, $screen_name); }
public function spreedlyListener() { if (isset($_POST['subscriber_ids'])) { $ids = explode(',', $_POST['subscriber_ids']); foreach ($ids as $id) { try { $subscriber = SpreedlySubscriber::find($id); $subscriber->updateLocalAccount(); Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Updated local account id: {$id}"); } catch (SpreedlyException $e) { Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] I heard that subscriber {$id} was changed but I can't do anything about it. " . $e->getMessage()); } } } else { Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] This is not a valid call to the spreedly listener."); } ob_clean(); header('HTTP/1.1 200 OK'); die; }
/** * Create an invoice and set the invoice token. * Set the public variable $this->subscriber to the subscriber returned when creating * the invoice. Return the XML response and the response code in an object format: * $result->response * $result->code * * @return object */ public function create(SpreedlySubscriber $subscriber, $planId) { $invoice = array('subscription-plan-id' => $planId, 'subscriber' => $subscriber->toArray(true, array('token', 'feature-level'))); return $this->createFromArray($invoice); }
public function testGetTransactions() { global $test_site_name, $test_token; Spreedly::configure($test_site_name, $test_token); SpreedlySubscriber::wipe(); // create invoice for existing customer $trial_plan = SpreedlySubscriptionPlan::find_by_name("Free Trial"); $sub1 = SpreedlySubscriber::create(75, null, "able"); $sub1->lifetime_comp("full"); $sub2 = SpreedlySubscriber::create(76, null, "baker"); $sub2->activate_free_trial($trial_plan->id); // !!!! $sub3 = SpreedlySubscriber::create(77, null, "charlie"); $sub3->activate_free_trial($trial_plan->id); $transactions = Spreedly::get_transactions(); $this->assertEquals(3, count($transactions)); $this->assertEquals("free_trial", $transactions[0]->detail->payment_method); // test getting subset of transactions $transactions = Spreedly::get_transactions($transactions[1]->id); $this->assertEquals(1, count($transactions)); $this->assertEquals(77, $transactions[0]->subscriber_customer_id); }
/** * Create a Spreedly subscription. * * @param int $accountId The primary key from the Cart66 accounts table associated with this subscription * @param int $subscriptionId The id of the spreedly subscription plan * @param mixed $paymentMethod Either 'on-file' or a SpreedlyCreditCard object */ public function createSpreedlySubscription($accountId, $subscriptionId, $productId, $paymentMethod = 'on-file') { $subscriptionCreated = false; if (is_numeric($accountId) && $accountId > 0) { if (!$this->loadByAccountId($accountId)) { $this->accountId = $accountId; } $subscriber = new SpreedlySubscriber(); $subscriber->hydrate($this->_getSpreedlySubscriberDataArray()); $subscription = new SpreedlySubscription($subscriptionId); if ('free_trial' == strtolower((string) $subscription->planType)) { $subscriberData = $subscriber->toArray(true); // prune the empty data Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Creating a new subscriber before assigning free trial. " . print_r($subscriberData, true)); $subscriber->create($subscriberData); Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Preparing to assign free trial plan ({$subscriptionId}) to new subscriber: " . print_r($subscriber->toArray(), true)); $subscriber->assignFreeTrialPlan($subscriptionId); } else { $invoice = new SpreedlyInvoice(); Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Creating a Spreedly invoice for subscription id: {$subscriptionId}"); $invoice->create($subscriber, $subscriptionId); $invoice->pay($paymentMethod); Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Spreedly invoice has been created and paid."); } $this->productId = $productId; $this->save(); } }