コード例 #1
0
        public IHttpActionResult PostPaymentAccount(StripeBindingModel stripeBindingModel)
        {
            int     accountId = this.GetAccountId();
            Account account   = db.Accounts.Find(accountId);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            // Use stripe to get the customer token
            string stripeCustomerToken = "";

            var myCustomer = new StripeCustomerCreateOptions();

            myCustomer.SourceToken = stripeBindingModel.CardToken;
            var customerService = new StripeCustomerService();
            var stripeCustomer  = customerService.Create(myCustomer);

            PaymentAccount paymentAccount = new PaymentAccount(PaymentMethod.Stripe, stripeCustomerToken);

            paymentAccount.AccountId = accountId;

            // updae the default payment account as the new account
            account.DefaultPaymentAccount = paymentAccount;
            db.SetModified(account);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = paymentAccount.Id }, paymentAccount));
        }
コード例 #2
0
        public IHttpActionResult PutProfileList(int id, ProfileList profileList)
        {
            int accountId = this.GetAccountId();

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != profileList.Id || profileList.AccountId != accountId)
            {
                return(BadRequest());
            }

            db.SetModified(profileList);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProfileListExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #3
0
        public IHttpActionResult PutRecipientProfile(int id, RecipientProfile recipientProfile)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != recipientProfile.Id)
            {
                return(BadRequest());
            }

            db.SetModified(recipientProfile);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RecipientProfileExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #4
0
        public IHttpActionResult PutCampaign(int id, Campaign campaign)
        {
            int accountId = this.GetAccountId();

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != campaign.Id || accountId != campaign.AccountId || !campaign.CanEditCampaign())
            {
                return(BadRequest());
            }

            // Reset the price set state as it needs to be recalculated
            campaign.CampaignStateId = CampaignState.DefaultState;

            db.SetModified(campaign);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CampaignExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }