function testFind_throwsIfNotFound() { $this->setExpectedException('Braintree_Exception_NotFound', 'subscription with id does-not-exist not found'); Braintree_Subscription::find('does-not-exist'); }
/** * wrapper for getting subscriptions from braintree * @param object - user * @param string - id of the subscription (default null) * * @return object - the searched subscriptions OR null if not found OR collection of subscriptions */ private static function getSubscriptions($user, $subscriptionId = null) { self::setBraintreeCredentials($user); $returnVariable = null; if ($subscriptionId) { try { $returnVariable = Braintree_Subscription::find($subscriptionId); } catch (Exception $e) { return null; } } else { $returnVariable = Braintree_Subscription::search(array(Braintree_SubscriptionSearch::status()->in(array(Braintree_Subscription::ACTIVE, Braintree_Subscription::PAST_DUE, Braintree_Subscription::PENDING)))); } return $returnVariable; }
function testErrorsOnFindWithWhitespaceArgument() { $this->setExpectedException('InvalidArgumentException'); Braintree_Subscription::find('\\t'); }
<?php include '../brainTreePhp/lib/Braintree.php'; if (isset($_GET['subscription'])) { $subscription = $_GET['subscription']; } else { //echo 'Missing subscription ID!'; echo "0"; die; } Braintree_Configuration::environment('sandbox'); Braintree_Configuration::merchantId('zn8d4c74dbnp5ntw'); Braintree_Configuration::publicKey('ttwrprnsj83thjjz'); Braintree_Configuration::privateKey('a818cb5f3164585f31f4f03066f308c8'); try { $subscription = Braintree_Subscription::find($subscription); } catch (Braintree_Exception_NotFound $e) { //header('Location: ../response.html'); echo "0"; die; } if ($subscription->status == Braintree_Subscription::ACTIVE) { //header('Location: ../app.html'); echo "1"; } else { //header('Location: ../response.html'); echo "0"; }