本文整理汇总了PHP中Braintree_Subscription类的典型用法代码示例。如果您正苦于以下问题:PHP Braintree_Subscription类的具体用法?PHP Braintree_Subscription怎么用?PHP Braintree_Subscription使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Braintree_Subscription类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _initialize
protected function _initialize($attributes)
{
$this->_attributes = $attributes;
if (isset($attributes['subject']['apiErrorResponse'])) {
$wrapperNode = $attributes['subject']['apiErrorResponse'];
} else {
$wrapperNode = $attributes['subject'];
}
if (isset($wrapperNode['subscription'])) {
$this->_set('subscription', Braintree_Subscription::factory($attributes['subject']['subscription']));
}
if (isset($wrapperNode['merchantAccount'])) {
$this->_set('merchantAccount', Braintree_MerchantAccount::factory($wrapperNode['merchantAccount']));
}
if (isset($wrapperNode['transaction'])) {
$this->_set('transaction', Braintree_Transaction::factory($wrapperNode['transaction']));
}
if (isset($wrapperNode['disbursement'])) {
$this->_set('disbursement', Braintree_Disbursement::factory($wrapperNode['disbursement']));
}
if (isset($wrapperNode['partnerMerchant'])) {
$this->_set('partnerMerchant', Braintree_PartnerMerchant::factory($wrapperNode['partnerMerchant']));
}
if (isset($wrapperNode['errors'])) {
$this->_set('errors', new Braintree_Error_ValidationErrorCollection($wrapperNode['errors']));
$this->_set('message', $wrapperNode['message']);
}
}
示例2: afterFind
public function afterFind($results, $primary = false)
{
if ($primary) {
$results = Hash::insert($results, "{n}.BraintreeSubscription", array());
$results = Hash::insert($results, "{n}.BraintreePlan", array());
$braintreeSubscriptions = Braintree_Subscription::search([Braintree_SubscriptionSearch::ids()->in(Hash::extract($results, "{n}.BillingSubscription.remote_subscription_id"))]);
$braintreePlans = Braintree_Plan::all();
foreach ($results as $key => $result) {
foreach ($braintreeSubscriptions as $braintreeSubscription) {
if ($braintreeSubscription->id == $result['BillingSubscription']['remote_subscription_id']) {
$result['BraintreeSubscription'] = $braintreeSubscription;
break;
}
//$results = Hash::insert($results, "{n}.BillingSubscription[remote_subscription_id=".$braintreeSubscription->id."]", array('BraintreeSubscription' => $braintreeSubscription));
}
foreach ($braintreePlans as $braintreePlan) {
if ($braintreePlan->id == $result['BillingSubscription']['remote_plan_id']) {
$result['BraintreePlan'] = $braintreePlan;
break;
}
}
$results[$key] = $result;
}
}
return $results;
}
示例3: _initialize
protected function _initialize($attributes)
{
$this->_attributes = $attributes;
if (isset($attributes['subject']) && isset($attributes['subject']['subscription'])) {
$this->_set('subscription', Braintree_Subscription::factory($attributes['subject']['subscription']));
}
}
示例4: updateSubscriptions
/**
* updateSubscriptions
* --------------------------------------------------
* Updating the BraintreeSubscriptions.
* @return The stripe plans.
* @throws BraintreeNotConnected
* --------------------------------------------------
*/
public function updateSubscriptions()
{
// Updating plans to be up to date.
$this->updatePlans();
$subscriptions = array();
// Clollecting subscriptions.
try {
$braintreeSubscriptions = Braintree_Subscription::search(array(Braintree_SubscriptionSearch::status()->in(array(Braintree_Subscription::ACTIVE))));
} catch (Exception $e) {
// Something went wrong.
return;
}
foreach ($braintreeSubscriptions as $subscription) {
$new_subscription = new BraintreeSubscription(array('start' => $subscription->firstBillingDate, 'status' => $subscription->status));
$plan = BraintreePlan::where('plan_id', $subscription->planId)->first();
if ($plan === null) {
// Braintree integrity error, link to a non-existing plan.
return array();
}
$new_subscription->plan()->associate($plan);
array_push($subscriptions, $new_subscription);
}
// Save new.
foreach ($subscriptions as $subscription) {
$subscription->save();
}
return $subscriptions;
}
示例5: __construct
/**
* overrides default constructor
* @ignore
* @param array $response gateway response array
*/
public function __construct($response)
{
$this->_attributes = $response;
$this->_set('errors', new Braintree_Error_ErrorCollection($response['errors']));
if (isset($response['verification'])) {
$this->_set('creditCardVerification', new Braintree_Result_CreditCardVerification($response['verification']));
} else {
$this->_set('creditCardVerification', null);
}
if (isset($response['transaction'])) {
$this->_set('transaction', Braintree_Transaction::factory($response['transaction']));
} else {
$this->_set('transaction', null);
}
if (isset($response['subscription'])) {
$this->_set('subscription', Braintree_Subscription::factory($response['subscription']));
} else {
$this->_set('subscription', null);
}
if (isset($response['merchantAccount'])) {
$this->_set('merchantAccount', Braintree_MerchantAccount::factory($response['merchantAccount']));
} else {
$this->_set('merchantAccount', null);
}
}
示例6: testContains
function testContains()
{
$creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
$triallessPlan = Braintree_SubscriptionTestHelper::triallessPlan();
$trialPlan = Braintree_SubscriptionTestHelper::trialPlan();
$trialSubscription = Braintree_Subscription::create(array('paymentMethodToken' => $creditCard->token, 'planId' => $trialPlan['id'], 'price' => '9'))->subscription;
$triallessSubscription = Braintree_Subscription::create(array('paymentMethodToken' => $creditCard->token, 'planId' => $triallessPlan['id'], 'price' => '9'))->subscription;
$collection = Braintree_Subscription::search(array(Braintree_SubscriptionSearch::planId()->contains("ration_trial_pl"), Braintree_SubscriptionSearch::price()->is("9")));
$this->assertTrue(Braintree_TestHelper::includes($collection, $trialSubscription));
$this->assertFalse(Braintree_TestHelper::includes($collection, $triallessSubscription));
}
示例7: testIn_multipleValues
function testIn_multipleValues()
{
$creditCard = Braintree_SubscriptionTestHelper::createCreditCard();
$triallessPlan = Braintree_SubscriptionTestHelper::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(Braintree_TestHelper::includes($collection, $activeSubscription));
$this->assertTrue(Braintree_TestHelper::includes($collection, $canceledSubscription));
}
示例8: _initialize
/**
* sets instance properties from an array of values
*
* @access protected
* @param array $paypalAccountAttribs array of paypalAccount data
* @return none
*/
protected function _initialize($paypalAccountAttribs)
{
// set the attributes
$this->_attributes = $paypalAccountAttribs;
$subscriptionArray = array();
if (isset($paypalAccountAttribs['subscriptions'])) {
foreach ($paypalAccountAttribs['subscriptions'] as $subscription) {
$subscriptionArray[] = Braintree_Subscription::factory($subscription);
}
}
$this->_set('subscriptions', $subscriptionArray);
}
示例9: _initialize
/**
* sets instance properties from an array of values
*
* @access protected
* @param array $applePayCardAttribs array of Apple Pay card properties
* @return none
*/
protected function _initialize($applePayCardAttribs)
{
// set the attributes
$this->_attributes = $applePayCardAttribs;
$subscriptionArray = array();
if (isset($applePayCardAttribs['subscriptions'])) {
foreach ($applePayCardAttribs['subscriptions'] as $subscription) {
$subscriptionArray[] = Braintree_Subscription::factory($subscription);
}
}
$this->_set('subscriptions', $subscriptionArray);
$this->_set('expirationDate', $this->expirationMonth . '/' . $this->expirationYear);
}
示例10: createSubscription
public function createSubscription($customer_id, $package_code, $monthly_price)
{
try {
$customer = Braintree_Customer::find($customer_id);
$payment_method_token = $customer->creditCards[0]->token;
$result = Braintree_Subscription::create(array('paymentMethodToken' => $payment_method_token, 'planId' => $package_code, 'price' => $monthly_price));
return $result;
} catch (Braintree_Exception_NotFound $e) {
$bexcption = print_r($e, true);
log_message('error', date('Y-m-d H:i:s') . ' ' . $bexcption, true);
$result = new stdClass();
$result->success = false;
return $result;
}
}
示例11: sendSubscription
/**
* Braintree sale function
* @param bool|true $submitForSettlement
* @param bool|true $storeInVaultOnSuccess
* @return array
*/
public function sendSubscription()
{
//$customer = \Braintree_Customer::find($this->options['customerId']);
$subscriptionData = array('paymentMethodToken' => $this->options['paymentMethodToken'], 'planId' => $this->options['planId']);
$result = \Braintree_Subscription::create($subscriptionData);
if ($result->success) {
return ['status' => true, 'result' => $result];
} else {
if ($result->transaction) {
return ['status' => false, 'result' => $result];
} else {
return ['status' => false, 'result' => $result];
}
}
}
示例12: testFind_returnsSubscriptionsAssociatedWithAPaypalAccount
function testFind_returnsSubscriptionsAssociatedWithAPaypalAccount()
{
$customer = Braintree_Customer::createNoValidate();
$paymentMethodToken = 'paypal-account-' . strval(rand());
$nonce = Braintree_HttpClientApi::nonceForPayPalAccount(array('paypal_account' => array('consent_code' => 'consent-code', 'token' => $paymentMethodToken)));
$result = Braintree_PaymentMethod::create(array('paymentMethodNonce' => $nonce, 'customerId' => $customer->id));
$this->assertTrue($result->success);
$token = $result->paymentMethod->token;
$triallessPlan = Braintree_SubscriptionTestHelper::triallessPlan();
$subscription1 = Braintree_Subscription::create(array('paymentMethodToken' => $token, 'planId' => $triallessPlan['id']))->subscription;
$subscription2 = Braintree_Subscription::create(array('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));
}
示例13: subscribe
function subscribe($nonce, $info)
{
$customerResult;
$subscriptionResult;
$customerResult = Braintree_Customer::create(['firstName' => $info['fname'], 'lastName' => $info['lname'], 'email' => $info['email'], 'paymentMethodNonce' => $nonce]);
if (!$customerResult->success) {
return $this->processErrors('subscription', $customerResult->errors->deepAll());
}
$r = $customerResult->customer;
$a = $r->addresses[0];
$sql = 'INSERT INTO users (first_name, last_name, address, city, state, zip, braintree_customer_id, created_date, email) ';
$sql .= "VALUES ('" . $r->firstName . "','" . $r->lastName . "','" . $a->streetAddress . "','" . $a->locality . "','" . $a->region . "','" . $a->postalCode . "','" . $r->id . "', now(),'" . $r->email . "');";
$info['userId'] = MysqlAccess::insert($sql);
$subscriptionResult = Braintree_Subscription::create(['paymentMethodToken' => $customerResult->customer->paymentMethods[0]->token, 'planId' => 'donation', 'price' => $info['amount']]);
if (!isset($subscriptionResult->subscription) || !$subscriptionResult->subscription) {
return $this->processErrors('subscription', $subscriptionResult->errors->deepAll());
}
return $this->retrieveSubscriptionResults($subscriptionResult->success, $subscriptionResult->subscription, $info);
}
示例14: testRetryCharge_WithAmount
function testRetryCharge_WithAmount()
{
$subscription = Braintree_SubscriptionTestHelper::createSubscription();
Braintree_Http::put('/subscriptions/' . $subscription->id . '/make_past_due');
$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);
}
示例15: testFindReturnsAssociatedSubscriptions
function testFindReturnsAssociatedSubscriptions()
{
$customer = Braintree_Customer::createNoValidate();
$result = Braintree_CreditCard::create(array('customerId' => $customer->id, 'cardholderName' => 'Cardholder', 'number' => '5105105105105100', 'expirationDate' => '05/12', 'billingAddress' => array('firstName' => 'Drew', 'lastName' => 'Smith', 'company' => 'Smith Co.', 'streetAddress' => '1 E Main St', 'extendedAddress' => 'Suite 101', 'locality' => 'Chicago', 'region' => 'IL', 'postalCode' => '60622', 'countryName' => 'United States of America')));
$id = strval(rand());
Braintree_Subscription::create(array('id' => $id, 'paymentMethodToken' => $result->creditCard->token, 'planId' => 'integration_trialless_plan', 'price' => '1.00'));
$creditCard = Braintree_CreditCard::find($result->creditCard->token);
$this->assertEquals($id, $creditCard->subscriptions[0]->id);
$this->assertEquals('integration_trialless_plan', $creditCard->subscriptions[0]->planId);
$this->assertEquals('1.00', $creditCard->subscriptions[0]->price);
}