Adds a Coupon to a Subscription

@param string $subscriptionId
@param string $couponId
@return \DarkGhostHunter\FlowSdk\Resources\BasicResource & SubscriptionResource
@throws \Exception
420411
public function addCoupon(string $subscriptionId, string $couponId)
    {
        // Log Debug
        $this->flow->getLogger()->debug("Adding Coupon $couponId to $subscriptionId");

        return $this->make(
            $this->flow->send(
                'post',
                $this->endpoint . '/addCoupon',
                [
                    'subscriptionId' => $subscriptionId,
                    'couponId' => $couponId,
                ]
            )
        );
    }
170673
def add_coupon(self, coupon, idempotency_key=None):
		
		if isinstance(coupon, StripeModel):
			coupon = coupon.id

		stripe_customer = self.api_retrieve()
		stripe_customer["coupon"] = coupon
		stripe_customer.save(idempotency_key=idempotency_key)
		return self.__class__.sync_from_stripe_data(stripe_customer)
656421
protected function getCouponId()
	{
		if( !isset( $this->couponId ) )
		{
			$manager = \Aimeos\MShop::create( $this->getContext(), 'coupon' );

			$search = $manager->createSearch()->setSlice( 0, 1 );
			$search->setConditions( $search->compare( '=~', 'coupon.provider', 'Voucher' ) );

			$items = $manager->searchItems( $search );

			if( ( $item = reset( $items ) ) === false ) {
				throw new \Aimeos\Controller\Jobs\Exception( 'No coupon provider "Voucher" available' );
			}

			$this->couponId = $item->getId();
		}

		return $this->couponId;
	}
94276
public void setSubscriberID(String subscriptionID)
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "setSubscriberID", subscriptionID);

        this.subscriptionID = subscriptionID;

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(this, tc, "setSubscriberID");
    }
392216
protected function _beforeEntityInsert(AnCommandContext $context)
    {
        if (!empty($this->couponCode)) {
            $coupon = $this->getService('repos:subscriptions.coupon')
                           ->find(array(
                             'code' => $this->couponCode,
                           ));

            if ($coupon) {
                $coupon->used();
            }
        }
    }
583019
public function addSubscription(StripeLocalSubscription $subscription)
    {
        // If the subscription is already set
        if (false === $this->subscriptions->contains($subscription)) {
            // Add the subscription to the collection
            $this->subscriptions->add($subscription);
        }

        return $this;
    }
1236383
public function validateDuplicatedCoupon(
        CartInterface $cart,
        CouponInterface $coupon
    ) {
        $cartCoupon = $this
            ->cartCouponRepository
            ->findOneBy([
                'cart' => $cart,
                'coupon' => $coupon,
            ]);

        if (null !== $cartCoupon) {
            throw new CouponAlreadyAppliedException();
        }
    }
1091412
public function addCouponByCode(
        CartInterface $cart,
        $couponCode
    ) {
        $coupon = $this
            ->couponRepository
            ->findOneBy([
                'code' => $couponCode,
                'enabled' => true,
            ]);

        if (!($coupon instanceof CouponInterface)) {
            throw new CouponNotAvailableException();
        }

        return $this
            ->addCoupon(
                $cart,
                $coupon
            );
    }
826408
public function renewalEstimate(string $subscriptionId, array $parameters = [], array $headers = [])
    {
        $resolver = new OptionsResolver();

        $resolver->setDefined('use_existing_balances')
            ->setAllowedTypes('use_existing_balances', 'boolean');
        $resolver->setDefined('invoice_immediately')
            ->setAllowedTypes('invoice_immediately', 'boolean');
        $resolver->setDefined('billing_cycles')
            ->setAllowedTypes('billing_cycles', 'integer');
        $resolver->setDefined('terms_to_charge')
            ->setAllowedTypes('terms_to_charge', 'integer')
            ->setAllowedValues('terms_to_charge', function ($value) {
                return $value > 0;
            });
        $resolver->setDefined('billing_alignment_mode')
            ->setAllowedTypes('billing_alignment_mode', 'string')
            ->setAllowedValues('billing_alignment_mode', ['immediate', 'delayed']);
        $resolver->setDefined('coupon_ids');
        $resolver->setDefined('subscription');
        $resolver->setDefined('shipping_address');
        $resolver->setDefined('addons');

        $url = $this->url('subscriptions/%s/renewal_estimate', $subscriptionId);

        return $this->get($url, $resolver->resolve($parameters), $headers);
    }
334144
public function addInvolvedUserId($involvedUserId)
    {
        if (!in_array($involvedUserId, $this->involvedUserIds)) {
            $this->involvedUserIds[] = $involvedUserId;
        }

        return $this;
    }
997703
public BranchEvent setCoupon(String coupon) {
        return addStandardProperty(Defines.Jsonkey.Coupon.getKey(), coupon);
    }
352136
def add(self, quote_id, coupon_code, store_view=None):
        
        return bool(
            self.call('cart_coupon.add', [quote_id, coupon_code, store_view])
        )
1247258
public function getBackOfficeInputsAjaxAction($couponServiceId)
    {
        if (null !== $response = $this->checkAuth(AdminResources::COUPON, [], AccessManager::VIEW)) {
            return $response;
        }

        if (! empty($couponServiceId)) {
            $this->checkXmlHttpRequest();

            /** @var CouponInterface $coupon */
            $couponManager = $this->container->get($couponServiceId);

            if (!$couponManager instanceof CouponInterface) {
                $this->pageNotFound();
            }

            $response = new ResponseRest($couponManager->drawBackOfficeInputs(), 'text');
        } else {
            // Return an empty response if the service ID is not defined
            // Typically, when the user chooses "Please select a coupon type"
            $response = new ResponseRest('');
        }

        return $response;
    }
456942
public function cancelCoupon($basketId, string $couponCode, $userId)  // !! DEPRECATED moved to basket
    {
        $params = [
          "basketId" => $basketId,
          "couponCode" => $couponCode,
          "userId" => $userId
        ];

        $response = $this->handler->handle('POST', $params, 'discard');

        //TODO: refactor to make method
        return $response;
        //        return $this->make($response, false);
    }
1220112
public function setSubscriptionId($subscriptionId)
    {
        if (strlen($subscriptionId) > 50) {
            throw new InvalidArgumentException("Subscription id cannot be longer than 50 characters");
        }
        if (preg_match('/[^a-zA-Z0-9_-]/', $subscriptionId)) {
            throw new InvalidArgumentException("Subscription id cannot contain special characters");
        }
        $this->parameters['subscription_id'] = $subscriptionId;
    }
56385
public function getSubscriptionByCustomerId($customerId)
    {
        /** @var SubscriptionFbApi $response */
        $response = $this->call(new Request('subscription.get', array('customer_id' => $customerId)), 'DVelopment\FastBill\Model\SubscriptionFbApi');
        $subscriptions = $response->getResponse()->getSubscriptions();

        return reset($subscriptions);
    }
1232973
public function addCoupon( MShop_Order_Item_Base_Interface $base )
	{
		if( $this->_getObject()->isAvailable( $base ) === false ) {
			return;
		}

		$config = $this->_getItem()->getConfig();

		if( !isset( $config['present.productcode'] ) || !isset( $config['present.quantity']) )
		{
			throw new MShop_Coupon_Exception( sprintf(
				'Invalid configuration for coupon provider "%1$s", needs "%2$s"',
				$this->_getItem()->getProvider(), 'present.productcode, present.quantity'
			) );
		}

		$orderProduct = $this->_createProduct( $config['present.productcode'], $config['present.quantity'] );

		$base->addCoupon( $this->_getCode(), array( $orderProduct ) );
	}