/**
  * @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;
 }
 public function testDelete_worksWithPayPalAccounts()
 {
     $paymentMethodToken = 'PAYPAL_TOKEN-' . strval(rand());
     $customer = Braintree\Customer::createNoValidate();
     $http = new HttpClientApi(Braintree\Configuration::$global);
     $nonce = $http->nonceForPayPalAccount(['paypal_account' => ['consent_code' => 'PAYPAL_CONSENT_CODE', 'token' => $paymentMethodToken]]);
     $paypalAccountResult = Braintree\PaymentMethod::create(['customerId' => $customer->id, 'paymentMethodNonce' => $nonce]);
     $this->assertTrue($paypalAccountResult->success);
     Braintree\PaymentMethod::delete($paymentMethodToken);
     $this->setExpectedException('Braintree\\Exception\\NotFound');
     Braintree\PaymentMethod::find($paymentMethodToken);
 }
 public function testErrorsOnFindWithWhitespaceCharacterArgument()
 {
     $this->setExpectedException('InvalidArgumentException');
     Braintree\PaymentMethod::find('\\t');
 }
Exemplo n.º 4
0
 public function testCreate_withOnetimePayPalAndDoesNotVault()
 {
     $paymentMethodToken = 'PAYPAL_TOKEN-' . strval(rand());
     $http = new HttpClientApi(Braintree\Configuration::$global);
     $nonce = $http->nonceForPayPalAccount(['paypal_account' => ['access_token' => 'PAYPAL_ACCESS_TOKEN', 'token' => $paymentMethodToken]]);
     $result = Braintree\Transaction::sale(['amount' => Braintree\Test\TransactionAmounts::$authorize, 'paymentMethodNonce' => $nonce, 'options' => ['storeInVault' => true]]);
     $this->assertTrue($result->success);
     $transaction = $result->transaction;
     $this->assertEquals('*****@*****.**', $transaction->paypalDetails->payerEmail);
     $this->assertNotNull($transaction->paypalDetails->imageUrl);
     $this->assertNotNull($transaction->paypalDetails->debugId);
     $this->setExpectedException('Braintree\\Exception\\NotFound');
     Braintree\PaymentMethod::find($paymentMethodToken);
 }