public function testIn_multipleValues()
 {
     $creditCard = SubscriptionHelper::createCreditCard();
     $triallessPlan = SubscriptionHelper::triallessPlan();
     $activeSubscription = Braintree\Subscription::create(array('paymentMethodToken' => $creditCard->token, 'planId' => $triallessPlan['id'], 'price' => '4'))->subscription;
     $canceledSubscription = Braintree\Subscription::create(array('paymentMethodToken' => $creditCard->token, 'planId' => $triallessPlan['id'], 'price' => '4'))->subscription;
     Braintree\Subscription::cancel($canceledSubscription->id);
     $collection = Braintree\Subscription::search(array(Braintree\SubscriptionSearch::status()->in(array(Braintree\Subscription::ACTIVE, Braintree\Subscription::CANCELED)), Braintree\SubscriptionSearch::price()->is('4')));
     $this->assertTrue(Test\Helper::includes($collection, $activeSubscription));
     $this->assertTrue(Test\Helper::includes($collection, $canceledSubscription));
 }
 public function testFind_returnsSubscriptionsAssociatedWithAPaypalAccount()
 {
     $customer = Braintree\Customer::createNoValidate();
     $paymentMethodToken = 'paypal-account-' . strval(rand());
     $http = new HttpClientApi(Braintree\Configuration::$global);
     $nonce = $http->nonceForPayPalAccount(['paypal_account' => ['consent_code' => 'consent-code', 'token' => $paymentMethodToken]]);
     $result = Braintree\PaymentMethod::create(['paymentMethodNonce' => $nonce, 'customerId' => $customer->id]);
     $this->assertTrue($result->success);
     $token = $result->paymentMethod->token;
     $triallessPlan = SubscriptionHelper::triallessPlan();
     $subscription1 = Braintree\Subscription::create(['paymentMethodToken' => $token, 'planId' => $triallessPlan['id']])->subscription;
     $subscription2 = Braintree\Subscription::create(['paymentMethodToken' => $token, 'planId' => $triallessPlan['id']])->subscription;
     $paypalAccount = Braintree\PayPalAccount::find($token);
     $getIds = function ($sub) {
         return $sub->id;
     };
     $subIds = array_map($getIds, $paypalAccount->subscriptions);
     $this->assertTrue(in_array($subscription1->id, $subIds));
     $this->assertTrue(in_array($subscription2->id, $subIds));
 }
 public function testSearch_transactionId()
 {
     $creditCard = SubscriptionHelper::createCreditCard();
     $triallessPlan = SubscriptionHelper::triallessPlan();
     $matchingSubscription = Braintree\Subscription::create(['paymentMethodToken' => $creditCard->token, 'planId' => $triallessPlan['id']])->subscription;
     $nonMatchingSubscription = Braintree\Subscription::create(['paymentMethodToken' => $creditCard->token, 'planId' => $triallessPlan['id']])->subscription;
     $collection = Braintree\Subscription::search([Braintree\SubscriptionSearch::transactionId()->is($matchingSubscription->transactions[0]->id)]);
     $this->assertTrue(Test\Helper::includes($collection, $matchingSubscription));
     $this->assertFalse(Test\Helper::includes($collection, $nonMatchingSubscription));
 }
 public function testRetryCharge_WithAmount()
 {
     $subscription = SubscriptionHelper::createSubscription();
     $http = new Braintree\Http(Braintree\Configuration::$global);
     $path = Braintree\Configuration::$global->merchantPath() . '/subscriptions/' . $subscription->id . '/make_past_due';
     $http->put($path);
     $result = Braintree\Subscription::retryCharge($subscription->id, 1000);
     $this->assertTrue($result->success);
     $transaction = $result->transaction;
     $this->assertEquals(1000, $transaction->amount);
     $this->assertNotNull($transaction->processorAuthorizationCode);
     $this->assertEquals(Braintree\Transaction::SALE, $transaction->type);
     $this->assertEquals(Braintree\Transaction::AUTHORIZED, $transaction->status);
 }
 public function testSnapshotPlanIdAddOnsAndDiscountsFromSubscription()
 {
     $creditCard = SubscriptionHelper::createCreditCard();
     $plan = SubscriptionHelper::triallessPlan();
     $result = Braintree\Subscription::create(['paymentMethodToken' => $creditCard->token, 'planId' => $plan['id'], 'addOns' => ['add' => [['amount' => '11.00', 'inheritedFromId' => 'increase_10', 'quantity' => 2, 'numberOfBillingCycles' => 5], ['amount' => '21.00', 'inheritedFromId' => 'increase_20', 'quantity' => 3, 'numberOfBillingCycles' => 6]]], 'discounts' => ['add' => [['amount' => '7.50', 'inheritedFromId' => 'discount_7', 'quantity' => 2, 'neverExpires' => true]]]]);
     $transaction = $result->subscription->transactions[0];
     $this->assertEquals($transaction->planId, $plan['id']);
     $addOns = $transaction->addOns;
     SubscriptionHelper::sortModificationsById($addOns);
     $this->assertEquals($addOns[0]->amount, "11.00");
     $this->assertEquals($addOns[0]->id, "increase_10");
     $this->assertEquals($addOns[0]->quantity, 2);
     $this->assertEquals($addOns[0]->numberOfBillingCycles, 5);
     $this->assertFalse($addOns[0]->neverExpires);
     $this->assertEquals($addOns[1]->amount, "21.00");
     $this->assertEquals($addOns[1]->id, "increase_20");
     $this->assertEquals($addOns[1]->quantity, 3);
     $this->assertEquals($addOns[1]->numberOfBillingCycles, 6);
     $this->assertFalse($addOns[1]->neverExpires);
     $discounts = $transaction->discounts;
     $this->assertEquals($discounts[0]->amount, "7.50");
     $this->assertEquals($discounts[0]->id, "discount_7");
     $this->assertEquals($discounts[0]->quantity, 2);
     $this->assertEquals($discounts[0]->numberOfBillingCycles, null);
     $this->assertTrue($discounts[0]->neverExpires);
 }
 public function testContains()
 {
     $creditCard = SubscriptionHelper::createCreditCard();
     $triallessPlan = SubscriptionHelper::triallessPlan();
     $trialPlan = SubscriptionHelper::trialPlan();
     $trialSubscription = Braintree\Subscription::create(['paymentMethodToken' => $creditCard->token, 'planId' => $trialPlan['id'], 'price' => '9'])->subscription;
     $triallessSubscription = Braintree\Subscription::create(['paymentMethodToken' => $creditCard->token, 'planId' => $triallessPlan['id'], 'price' => '9'])->subscription;
     $collection = Braintree\Subscription::search([Braintree\SubscriptionSearch::planId()->contains("ration_trial_pl"), Braintree\SubscriptionSearch::price()->is("9")]);
     $this->assertTrue(Test\Helper::includes($collection, $trialSubscription));
     $this->assertFalse(Test\Helper::includes($collection, $triallessSubscription));
 }