public static function getApplicableCouponsForSubscription($subscription, $options = NULL, $customClient = NULL) { $subscriptionID = Bf_Subscription::getIdentifier($subscription); $endpoint = sprintf("%s/applicable-coupons", rawurlencode($subscriptionID)); $responseEntity = Bf_Coupon::getClassName(); return static::getCollection($endpoint, $options, $customClient, $responseEntity); }
public static function applyCouponToSubscription(Bf_Coupon $coupon, $subscription) { $subscriptionID = Bf_Subscription::getIdentifier($subscription); // make new Bf_Coupon using only the `couponCode` param $requestEntity = new Bf_Coupon(array('couponCode' => $coupon->couponCode), $coupon->getClient()); $endpoint = sprintf("%s/coupons", rawurlencode($subscriptionID)); $responseEntity = Bf_Coupon::getClassName(); $constructedEntity = static::postEntityAndGrabFirst($endpoint, $requestEntity, $responseEntity); return $constructedEntity; }
/** * Discard the amendment (now, or at a scheduled time). * @param array $discardOptions (Default: All keys set to their respective default values) Encapsulates the following optional parameters: * * @param {@see self::parseActioningTime(mixed)} $..['actioningTime'] When to action the 'next execution attempt' amendment * @return Bf_AmendmentDiscardAmendment The created 'amendment discarding' amendment. */ public function scheduleDiscard(array $discardOptions = array('actioningTime' => 'Immediate')) { $inputOptions = $discardOptions; $amendmentID = Bf_Amendment::getIdentifier($this); $subscriptionID = Bf_Subscription::getIdentifier($this->subscriptionID); $stateParams = array_merge(static::getFinalArgDefault(__METHOD__), array('subscriptionID' => $subscriptionID, 'amendmentToDiscardID' => $amendmentID), $inputOptions); static::mutateKeysByStaticLambdas($stateParams, array('actioningTime' => 'parseActioningTime'), array('actioningTime' => array($subscriptionID))); // create model of amendment $amendment = new Bf_AmendmentDiscardAmendment($stateParams); $createdAmendment = Bf_AmendmentDiscardAmendment::create($amendment); return $createdAmendment; }
/** * Gets Bf_Invoices for a given Bf_Subscription * @param union[string | Bf_Subscription] $subscription Reference to subscription <string>: $id of the Bf_Subscription. <Bf_Subscription>: The Bf_Subscription entity. * @return Bf_Invoice[] */ public static function getForSubscription($subscription, $options = NULL, $customClient = NULL) { $subscriptionID = Bf_Subscription::getIdentifier($subscription); $endpoint = sprintf("subscription/%s", rawurlencode($subscriptionID)); return static::getCollection($endpoint, $options, $customClient); }
/** * Creates a TimerAmendment to notify you (via webhook) of events upon your subscription * @param array $payload (Default: All keys set to their respective default values) Encapsulates the following optional parameters: * * @param int (Default: NULL) $..['duration'] Number of periods before or after the event * * @param string_ENUM['Minutes', 'Hours', 'Days'] (Default: NULL) $..['period'] Measure describing the magnitude of the duration * * @param string_ENUM['Before', 'After'] (Default: 'Before') $..['direction'] Timer fires x time-measures Before event, or After event * * @param string_ENUM['TrialExpiry', 'SubscriptionExpiry', 'PeriodEnd'] (Default: NULL) $..['event'] Subscription event to which this timer relates * @return Bf_TimerAmendment The timer amendment */ public function setupTimer(array $payload = array('duration' => NULL, 'period' => NULL, 'direction' => 'Before', 'event' => NULL)) { $inputOptions = $payload; $subscriptionID = Bf_Subscription::getIdentifier($this); $stateParams = static::mergeUserArgsOverNonNullDefaults(__METHOD__, array(), $inputOptions); $requestEntity = new Bf_CreateSubscriptionTimerRequest($stateParams); $endpoint = sprintf("%s/timer", rawurlencode($subscriptionID)); $responseEntity = Bf_TimerAmendment::getClassName(); $constructedEntity = static::postEntityAndGrabFirst($endpoint, $requestEntity, $responseEntity); return $constructedEntity; }