function get_subscriber($id) { if (!$this->athenticated) { return null; } return SpreedlySubscriber::find($id); }
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; }
public function testPayInvoice() { 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"); $sub = SpreedlySubscriber::create(75, null, "charlie"); $sub->activate_free_trial($trial_plan->id); // !!!! $sub = SpreedlySubscriber::find(75); $annual = SpreedlySubscriptionPlan::find_by_name("Annual"); $invoice = SpreedlyInvoice::create($sub->get_id(), $annual->id, $sub->screen_name, "*****@*****.**"); $response = $invoice->pay("4222222222222", "visa", "123", "13", date("Y") + 1, "Test", "User"); $this->assertTrue($response instanceof SpreedlyErrorList); $response = $invoice->pay("4222222222222", "visa", "123", "12", date("Y") - 1, "Test", "User"); $this->assertTrue($response instanceof SpreedlyErrorList); // declined try { $response = $invoice->pay("4012888888881881", "visa", "123", "12", date("Y") + 1, "Test", "User"); $this->fail("An exception should have been thrown"); } catch (SpreedlyException $e) { $this->assertEquals(403, $e->getCode()); } $response = $invoice->pay("4222222222222", "visa", "123", "12", date("Y") + 1, "Test", "User"); $this->assertTrue($response->closed); // test paying paid invoice try { $response = $invoice->pay("4222222222222", "visa", "123", "12", date("Y") + 1, "Test", "User"); $this->fail("An exception should have been thrown"); } catch (SpreedlyException $e) { $this->assertEquals(403, $e->getCode()); } // test adding fees $this->assertEquals(75, $sub->get_id()); $sub->add_fee("Daily Bandwidth Charge", "313 MB used", "Traffic Fees", 2.34); }