コード例 #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 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));
        }
コード例 #3
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));
        }
コード例 #4
0
        /// <summary>
        /// Credit and charge a campaign
        /// </summary>
        /// <param name="campaignId"></param>
        public void ChargeCampaign(int campaignId)
        {
            Campaign campaign;

            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions {
                IsolationLevel = IsolationLevel.RepeatableRead
            }))
            {
                // Get the price of the campaign
                campaign = db.Campaigns.Find(campaignId);
                campaign.SetCampaignPrice();
                // Set campaign state to PriceSet
                campaign.CampaignStateId = CampaignState.PriceSet;
                campaign.CampaignStateId = CampaignState.AttemptingCharge;
                db.SaveChanges();
            }

            // Charge the users account
            bool chargeSuccessful = ChargeAccount(campaignId);

            // Update the status of the campaign once completed

            campaign = db.Campaigns.Find(campaignId);

            // if successful, set the campaign state to ChargeSuccesful or failed
            if (chargeSuccessful)
            {
                // Set the campaign state to ChargeSuccessful
                campaign.DateCharged     = DateTime.Now;
                campaign.CampaignStateId = CampaignState.ChargedSuccessful;
            }
            else
            {
                // Set the campaign state tChargeFailed
                campaign.CampaignStateId = CampaignState.ChargeFailed;
            }

            db.SaveChanges();
        }
コード例 #5
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));
        }