本文整理汇总了PHP中Braintree_Subscription::cancel方法的典型用法代码示例。如果您正苦于以下问题:PHP Braintree_Subscription::cancel方法的具体用法?PHP Braintree_Subscription::cancel怎么用?PHP Braintree_Subscription::cancel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Braintree_Subscription
的用法示例。
在下文中一共展示了Braintree_Subscription::cancel方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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));
}
示例2: testCancel_returnsErrorIfCancelingCanceledSubscription
function testCancel_returnsErrorIfCancelingCanceledSubscription()
{
$subscription = Braintree_SubscriptionTestHelper::createSubscription();
Braintree_Subscription::cancel($subscription->id);
$result = Braintree_Subscription::cancel($subscription->id);
$this->assertFalse($result->success);
$errors = $result->errors->forKey('subscription')->onAttribute('status');
$this->assertEquals(Braintree_Error_Codes::SUBSCRIPTION_STATUS_IS_CANCELED, $errors[0]->code);
}
示例3:
<?php
require_once "../library/lib/Braintree.php";
$result = Braintree_Subscription::cancel('8bpb4b');
echo "<pre>";
print_r($result);
示例4: cancel_subscription
function cancel_subscription($sub_id)
{
$result = Braintree_Subscription::cancel($sub_id);
if ($result->success === true) {
return true;
}
$this->_parse_errors($result);
return false;
}
示例5: cancel
function cancel(&$order)
{
//require a subscription id
if (empty($order->subscription_transaction_id)) {
return false;
}
//find the customer
if (!empty($order->subscription_transaction_id)) {
//cancel
try {
$result = Braintree_Subscription::cancel($order->subscription_transaction_id);
} catch (Exception $e) {
$order->updateStatus("cancelled");
//assume it's been cancelled already
$order->error = __("Could not find the subscription.", "pmpro") . " " . $e->getMessage();
$order->shorterror = $order->error;
return false;
//no subscription found
}
if ($result->success) {
$order->updateStatus("cancelled");
return true;
} else {
$order->updateStatus("cancelled");
//assume it's been cancelled already
$order->error = __("Could not find the subscription.", "pmpro") . " " . $result->message;
$order->shorterror = $order->error;
return false;
//no subscription found
}
} else {
$order->error = __("Could not find the subscription.", "pmpro");
$order->shorterror = $order->error;
return false;
//no customer found
}
}
示例6: cancelBraintreeSubscription
/**
* cancelBraintreeSubscription
* --------------------------------------------------
* @return Cancels the current Braintree Subscription.
* --------------------------------------------------
*/
private function cancelBraintreeSubscription()
{
/* Initialize variables */
$result = ['errors' => FALSE, 'messages' => ''];
error_log('recece');
/* Cancel braintree subscription */
$cancellationResult = Braintree_Subscription::cancel($this->braintree_subscription_id);
/* Error */
if (!$cancellationResult->success) {
error_log('not success');
/* Get and store errors */
foreach ($cancellationResult->errors->deepAll() as $error) {
/* SKIP | Subscription has already been canceled. */
if ($error->code == SiteConstants::getBraintreeErrorCodes()['Subscription has already been canceled']) {
continue;
} else {
$result['errors'] |= TRUE;
$result['messages'] .= $error->code . ": " . $error->message . ' ';
}
}
}
/* Return result */
return $result;
}
示例7: doCancelSubscription
public function doCancelSubscription()
{
$user = Auth::user();
if ($user->subscriptionId) {
try {
$result = Braintree_Subscription::cancel($user->subscriptionId);
} catch (Exception $e) {
return Redirect::back()->with('error', "Couldn't process subscription, try again later.");
}
$user->subscriptionId = '';
$user->plan = 'cancelled';
$user->save();
IntercomHelper::cancelled($user);
return Redirect::route('auth.plan')->with('success', 'Unsubscribed successfully');
} else {
Redirect::back()->with('error', 'No valid subscription');
}
}
示例8: checkout
public function checkout()
{
$this->layout = 'profile_new';
if (!$this->request->is('post')) {
throw new NotFoundException(__d('billing', 'Incorrect request type'));
}
$customer = Braintree_Customer::find('konstruktor-' . $this->currUser['User']['id']);
if (isset($this->request->data['payment_method_nonce'])) {
$nonceFromTheClient = $this->request->data['payment_method_nonce'];
$payment = Braintree_PaymentMethod::create(['customerId' => 'konstruktor-' . $this->currUser['User']['id'], 'paymentMethodNonce' => $nonceFromTheClient]);
if (!$payment->success) {
$this->Session->setFlash($payment->message);
$this->redirect(array('action' => 'payment'));
}
$payment = $payment->paymentMethod;
} elseif (isset($this->request->data['payment_method']) && !empty($this->request->data['payment_method'])) {
$payment = null;
foreach ($customer->paymentMethods as $payment) {
if ($payment->token == $this->request->data['payment_method']) {
break;
}
}
if (empty($payment)) {
throw new NotFoundException(__d('billing', 'Payment method not found'));
}
} else {
throw new NotFoundException(__d('billing', 'Unable to create subscription'));
}
$braintreePlanId = $this->Session->read('Billing.plan');
$plan = $this->BillingPlan->findByRemotePlan($braintreePlanId);
$braintreePlans = Braintree_Plan::all();
$braintreePlan = null;
foreach ($braintreePlans as $_braintreePlan) {
if ($_braintreePlan->id == $braintreePlanId) {
$braintreePlan = $_braintreePlan;
break;
}
}
if (empty($braintreePlan)) {
throw new NotFoundException(__d('billing', 'Unable to create subscription'));
}
//Important! unit setup for model must be here. Before creating Braintree subscription
$unit = Configure::read('Billing.units.' . $plan['BillingGroup']['limit_units']);
if (empty($unit['model']) || empty($unit['field'])) {
throw new NotFoundException(__d('billing', 'Invalid billing plan'));
}
$this->BillingSubscription->Behaviors->load('Billing.Limitable', array('remoteModel' => $unit['model'], 'remoteField' => $unit['field'], 'scope' => isset($unit['scope']) ? $unit['scope'] : 'user_id'));
//Precreate subscription
$braintreeData = array('paymentMethodToken' => $payment->token, 'planId' => $braintreePlanId);
$qty = $this->Session->read('Billing.qty');
if (!empty($qty)) {
if (empty($braintreePlan->addOns)) {
throw new NotFoundException(__d('billing', 'Unable to create subscription'));
}
foreach ($braintreePlan->addOns as $addOn) {
$braintreeData['addOns']['update'][] = array('existingId' => $addOn->id, 'quantity' => $qty);
}
}
$billingSubscription = $this->BillingSubscription->find('first', array('conditions' => array('BillingSubscription.group_id' => $plan['BillingGroup']['id'], 'BillingSubscription.user_id' => $this->currUser['User']['id'], 'BillingSubscription.active' => true)));
//braintree unable to update subscription to a plan with a different billing frequency So we need to cancel current
if (!empty($billingSubscription)) {
if ($braintreePlan->billingFrequency != $billingSubscription['BraintreePlan']->billingFrequency || $billingSubscription['BraintreeSubscription']->status == 'Canceled' || $billingSubscription['BraintreeSubscription']->status == 'Expired') {
if ($braintreePlan->billingFrequency != $billingSubscription['BraintreePlan']->billingFrequency || $billingSubscription['BraintreeSubscription']->status != 'Canceled') {
try {
$result = Braintree_Subscription::cancel($billingSubscription['BraintreeSubscription']->id);
if ($result->success) {
$billingSubscription['BraintreeSubscription'] = $result->subscription;
}
} catch (Exception $e) {
}
}
$status = isset($billingSubscription['BraintreeSubscription']->status) ? $billingSubscription['BraintreeSubscription']->status : 'Canceled';
$this->BillingSubscription->cancel($billingSubscription['BillingSubscription']['id'], $status);
$billingSubscription = null;
}
}
if (!isset($billingSubscription['BillingSubscription'])) {
$data = array('group_id' => $plan['BillingGroup']['id'], 'plan_id' => $plan['BillingPlan']['id'], 'user_id' => $this->currUser['User']['id'], 'limit_value' => !empty($qty) ? $qty : $plan['BillingPlan']['limit_value'], 'active' => false);
} else {
$data = $billingSubscription['BillingSubscription'];
$data['limit_value'] = !empty($qty) ? $qty : $plan['BillingPlan']['limit_value'];
}
//No Exceptions anymore!
if (!isset($data['remote_subscription_id']) || empty($data['remote_subscription_id'])) {
//Subscribe user by create
$result = Braintree_Subscription::create($braintreeData);
} else {
$data['plan_id'] = $plan['BillingPlan']['id'];
//Subscribe user by update
$result = Braintree_Subscription::update($data['remote_subscription_id'], $braintreeData);
}
if (!$result->success) {
$this->Session->setFlash(__d('billing', 'Unable to subscribe on chosen plan. Please contact with resorce administration'));
$this->redirect(array('action' => 'plans', $plan['BillingGroup']['slug']));
}
$data = Hash::merge($data, array('remote_subscription_id' => $result->subscription->id, 'remote_plan_id' => $result->subscription->planId, 'active' => $result->subscription->status === 'Active' ? true : false, 'status' => $result->subscription->status, 'expires' => $result->subscription->billingPeriodEndDate->format('Y-m-d H:i:s'), 'created' => $result->subscription->createdAt->format('Y-m-d H:i:s'), 'modified' => $result->subscription->updatedAt->format('Y-m-d H:i:s')));
if (!isset($data['id'])) {
$this->BillingSubscription->create();
}
if ($this->BillingSubscription->save($data)) {
//.........这里部分代码省略.........
示例9:
<?php
include '../brainTreePhp/lib/Braintree.php';
Braintree_Configuration::environment('sandbox');
Braintree_Configuration::merchantId('zn8d4c74dbnp5ntw');
Braintree_Configuration::publicKey('ttwrprnsj83thjjz');
Braintree_Configuration::privateKey('a818cb5f3164585f31f4f03066f308c8');
$result = Braintree_Subscription::cancel($_GET['subscription']);
示例10: cancelSubscription
/**
* @param $subscriptionId
*
* @return mixed
*/
public function cancelSubscription($subscriptionId)
{
$result = \Braintree_Subscription::cancel($subscriptionId);
if ($result->success == true) {
return $this->response(true);
}
}