Add a coupon to a Customer.

		The coupon can be a Coupon object, or a valid Stripe Coupon ID.
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)
105861
def add_provide(self, provide):
        
        for p in self.provides:
            if p.value == provide.value:
                return
        self.provides.append(provide)
1286874
public function applyCoupon($basketId, string $couponCode) // !! DEPRECATED moved to basket
    {
        $params = [
          "basketId"   => $basketId,
          "couponCode" => $couponCode,
        ];

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

        //TODO: refactor to make method
        return $response;
        //        return $this->make($response, false);
    }
112440
public function notifyCouponUsage(CouponInterface $coupon)
    {
        $couponUsedEvent = new CouponOnUsedEvent($coupon);

        $this->eventDispatcher->dispatch(
            ElcodiCouponEvents::COUPON_USED,
            $couponUsedEvent
        );

        return $this;
    }
640714
def create_customer(self, customer_deets):
        """"""
        request = self._post('customers', customer_deets)
        return self.responder(request)
381861
public function buildCouponFromCode($couponCode)
    {
        /** @var Coupon $couponModel */
        $couponModel = $this->facade->findOneCouponByCode($couponCode);
        if ($couponModel === null) {
            return false;
        }

        // check if coupon is enabled
        if (!$couponModel->getIsEnabled()) {
            throw new InactiveCouponException($couponCode);
        }

        $nowDateTime = new \DateTime();

        // Check coupon start date
        if ($couponModel->getStartDate() !== null && $couponModel->getStartDate() > $nowDateTime) {
            throw new CouponNotReleaseException($couponCode);
        }

        // Check coupon expiration date
        if ($couponModel->getExpirationDate() < $nowDateTime) {
            throw new CouponExpiredException($couponCode);
        }

        // Check coupon usage count
        if (! $couponModel->isUsageUnlimited()) {
            if (null === $customer = $this->facade->getCustomer()) {
                throw new UnmatchableConditionException($couponCode);
            }

            if ($couponModel->getUsagesLeft($customer->getId()) <= 0) {
                throw new CouponNoUsageLeftException($couponCode);
            }
        }

        /** @var CouponInterface $couponInterface */
        $couponInterface = $this->buildCouponFromModel($couponModel);

        if ($couponInterface && $couponInterface->getConditions()->count() == 0) {
            throw new InvalidConditionException(
                \get_class($couponInterface)
            );
        }

        return $couponInterface;
    }
430007
def update_customer(self, customer_id, **kwargs):
		""""""
		body = self._formdata(kwargs, FastlyCustomer.FIELDS)
		content = self._fetch("/customer/%s" % customer_id, method="PUT", body=body)
		return FastlyCustomer(self, content)
291074
public static Customer retrieve(String customer) throws StripeException {
    return retrieve(customer, (Map<String, Object>) null, (RequestOptions) null);
  }
297881
function apply_credit() {
    global $db, $insert_id;
    $cc_id = $_SESSION['cc_id'];
    if ($this->deduction !=0) {
      $db->Execute("insert into " . TABLE_COUPON_REDEEM_TRACK . "
                    (coupon_id, redeem_date, redeem_ip, customer_id, order_id)
                    values ('" . (int)$cc_id . "', now(), '" . $_SERVER['REMOTE_ADDR'] . "', '" . (int)$_SESSION['customer_id'] . "', '" . (int)$insert_id . "')");
    }
    $_SESSION['cc_id'] = "";
  }
1249379
public function addCoupon(
        CartInterface $cart,
        CouponInterface $coupon
    ) {
        $this
            ->cartCouponEventDispatcher
            ->dispatchCartCouponOnApplyEvent(
                $cart,
                $coupon
            );

        return $this;
    }
778598
def update_stripe_details
      render :json => false and return if !logged_in?
      
      sc = @site.store_config      
      Stripe.api_key = sc.stripe_secret_key.strip

      u = logged_in_user      
      
      c = nil
      if u.stripe_customer_id
        c = Stripe::Customer.retrieve(u.stripe_customer_id)
        begin          
          c.source = params[:token]
          c.save
        rescue          
          c = nil
        end
      end
      
      if c.nil?
        c = Stripe::Customer.create(
          :source => params[:token],
          :email => u.email,
          :metadata => { :user_id => u.id }          
        )
      end
      
      u.stripe_customer_id = c.id
      u.card_last4     = params[:card][:last4]
      u.card_brand     = params[:card][:brand]  
      u.card_exp_month = params[:card][:exp_month]
      u.card_exp_year  = params[:card][:exp_year]
      u.save
      
      render :json => {
        :success        => true,
        :customer_id    => u.stripe_customer_id,                                                           
        :card_last4     => u.card_last4,     
        :card_brand     => u.card_brand,       
        :card_exp_month => u.card_exp_month, 
        :card_exp_year  => u.card_exp_year
      }      
    end
171426
def cli(obj, customer, match, delete):
    """"""
    client = obj['client']
    if delete:
        client.delete_customer(delete)
    else:
        if not customer:
            raise click.UsageError('Missing option "--customer".')
        if not match:
            raise click.UsageError('Missing option "--org" / "--group" / "--domain" / "--role".')
        try:
            customer = client.create_customer(customer, match)
        except Exception as e:
            click.echo('ERROR: {}'.format(e))
            sys.exit(1)
        click.echo(customer.id)
1331367
public static Coupon retrieve(String coupon, RequestOptions options) throws StripeException {
    return retrieve(coupon, (Map<String, Object>) null, options);
  }
997703
public BranchEvent setCoupon(String coupon) {
        return addStandardProperty(Defines.Jsonkey.Coupon.getKey(), coupon);
    }
250335
def coupons= coupons
      self.coupon_codes = coupons.map do |coupon|
        coupon.coupon_code if coupon.respond_to? :coupon_code
      end.compact
      attributes[:coupons] = coupons
    end
587737
def update_customer(self, customer_id, customer_deets):
        """"""
        request = self._put("customers/" + str(customer_id), customer_deets)
        return self.responder(request)
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
            );
    }