/**
  * @param string $subscription_id
  * @param bool $get_payment_method_info
  * @param int $numberOfTransactions
  * @return bool|\stdClass | {status, createdAt, updatedAt, cancelledAt, pastDue, daysPastDue, transactions}
  */
 public function getSubscriptionInfo($subscription_id, $get_payment_method_info = true, $numberOfTransactions = 5)
 {
     $subscription = Braintree_Subscription::find($subscription_id);
     if (!empty($subscription)) {
         $data = new \stdClass();
         $statuses = [Braintree_Subscription::ACTIVE => 'Active', Braintree_Subscription::CANCELED => 'Canceled', Braintree_Subscription::EXPIRED => 'Expired', Braintree_Subscription::PAST_DUE => 'Past due', Braintree_Subscription::PENDING => 'Pending'];
         $data->status = $statuses[$subscription->status];
         $data->createdAt = Carbon::instance($subscription->createdAt);
         $data->updatedAt = Carbon::instance($subscription->updatedAt);
         //The date/time the object was last updated. If a subscription has been cancelled, this value will represent the date/time of cancellation.
         if ($subscription->status == Braintree_Subscription::CANCELED) {
             $data->cancelledAt = Carbon::instance($data->updatedAt);
         } else {
             $data->cancelledAt = null;
         }
         $data->gracePeriod = $this->getGracePeriodFromSubscriptionInstance($subscription);
         $data->currentBillingCycle = $subscription->currentBillingCycle;
         $data->successfullyBilled = $data->currentBillingCycle > 0;
         $data->nextBill = new \stdClass();
         $data->nextBill->date = $subscription->nextBillingDate;
         $data->nextBill->amount = $subscription->nextBillingPeriodAmount;
         //String, The total subscription amount for the next billing period. This amount includes add-ons and discounts but does not include the current balance.
         if ($subscription->status == Braintree_Subscription::PAST_DUE) {
             $data->pastDue = true;
             $data->daysPastDue = $subscription->daysPastDue;
             //int, The number of days that the subscription is past due.
         } else {
             $data->pastDue = false;
             $data->daysPastDue = 0;
         }
         $data->transactions = [];
         $i = 0;
         $transactionStatuses = [Braintree_Transaction::AUTHORIZATION_EXPIRED => 'Authorization expired', Braintree_Transaction::AUTHORIZED => 'Authorized', Braintree_Transaction::AUTHORIZING => 'Authorizing', Braintree_Transaction::GATEWAY_REJECTED => 'Gateway rejected', Braintree_Transaction::FAILED => 'Failed', Braintree_Transaction::PROCESSOR_DECLINED => 'Processor declined', Braintree_Transaction::SETTLED => 'Settled', Braintree_Transaction::SETTLING => 'Settling', Braintree_Transaction::SUBMITTED_FOR_SETTLEMENT => 'Submitted for settlement', Braintree_Transaction::VOIDED => 'Voided', Braintree_Transaction::UNRECOGNIZED => 'Unrecognized', Braintree_Transaction::SETTLEMENT_DECLINED => 'Settlement declined', Braintree_Transaction::SETTLEMENT_PENDING => 'Settlement pending', Braintree_Transaction::SETTLEMENT_CONFIRMED => 'Settlement confirmed'];
         foreach ($subscription->transactions as $transaction) {
             $data->transactions[] = (object) ['status' => $transactionStatuses[$transaction->status], 'amount' => $transaction->amount, 'date' => Carbon::instance($transaction->createdAt), 'credit_card' => (object) ['type' => $transaction->creditCardDetails->cardType, 'last4' => $transaction->creditCardDetails->last4]];
             $i++;
             if ($i >= $numberOfTransactions) {
                 break;
             }
         }
         $subscription->transactions;
         // Array of Braintree_Transaction objects, Transactions associated with the subscription, sorted by creation date with the most recent first.
         if ($get_payment_method_info) {
             $paymentMethod = Braintree_PaymentMethod::find($subscription->paymentMethodToken);
             $data->payment_method = new \stdClass();
             $data->payment_method->credit_card = (object) ['type' => $paymentMethod->cardType, 'last4' => $paymentMethod->last4, 'expiration_month' => $paymentMethod->expirationMonth, 'expiration_year' => $paymentMethod->expirationYear];
             $data->payment_method->billing_address = (object) ['first_name' => $paymentMethod->billingAddress->firstName, 'last_name' => $paymentMethod->billingAddress->lastName, 'address' => $paymentMethod->billingAddress->streetAddress, 'city' => $paymentMethod->billingAddress->locality, 'state' => $paymentMethod->billingAddress->region, 'zip' => $paymentMethod->billingAddress->postalCode];
         }
         return $data;
     }
     return false;
 }
 /**
  * Get the subscription as a Braintree subscription object.
  *
  * @return \Braintree\Subscription
  */
 public function asBraintreeSubscription()
 {
     return BraintreeSubscription::find($this->braintree_id);
 }
Example #3
0
 public function findSubscription($subscriptionId)
 {
     return Subscription::find($subscriptionId);
 }
 public function testFind_throwsIfNotFound()
 {
     $this->setExpectedException('Braintree\\Exception\\NotFound', 'subscription with id does-not-exist not found');
     Braintree\Subscription::find('does-not-exist');
 }
 public function testErrorsOnFindWithWhitespaceArgument()
 {
     $this->setExpectedException('InvalidArgumentException');
     Braintree\Subscription::find('\\t');
 }