コード例 #1
0
        public Charge DestinationCharge(SmChargeInfo vm)
        {
            //  Destination charge ----------------
            //  - platform is responsible for the cost of the Stripe fees, refunds, and chargebacks.
            var chargeOptions = new ChargeCreateOptions()
            {
                Amount      = vm.TotalAmount,
                Customer    = vm.BuyerStripeCustId,
                Destination = new ChargeDestinationCreateOptions()
                {
                    Account = vm.VendorStripeAcctId,
                    //  effectively - taking fees
                    Amount = vm.TotalAmount - vm.SmFee
                             // This amount becomes available on the connected account’s normal transfer schedule,
                             // just like funds from regular Stripe charges.
                },
                Currency    = "usd",
                Description = "Buyer charged: " + vm.BuyersEmail,
            };

            var    chargeService = new ChargeService();
            Charge charge        = chargeService.Create(chargeOptions);

            return(charge);
        }
コード例 #2
0
        // Charge called only when vendor confirms product shipped
        //  - order transaction records one buyer purchase, may be multiple
        //     transactions as shopping cart supports multiple product purchase
        //     requests in one order.
        public ResultAndMessage CreateCharge(SmChargeInfo data)
        {
            ResultAndMessage result = new ResultAndMessage();

            if (data.Tran.OrderItem.Price > 0)
            {
                //// no account balance monitoring until Mango

                // Testing
                if (data.BuyerMemberType == MemberType.Vendor)
                {
                    var chargeResult = ChargeAccountToAccount(data.BuyerStripeCustId,
                                                              data.VendorStripeAcctId,
                                                              data.Tran.TotalAmount,
                                                              data.Tran.OrderItem.SmFee);
                    if (!chargeResult.success)
                    {
                        result.message = $"SmTransService.ChargeAccount : Charge failed for Tran {data.Tran.Id}";
                        return(result);
                    }
                    // credit tran.VendorId
                }
                if (data.BuyerMemberType == MemberType.Member)
                {
                    // TODO get Stripe key
                    string key          = "adsfsdf";
                    var    stripeResult = ChargeCustomerToAccount(data.BuyerStripeCustId,
                                                                  data.VendorStripeAcctId,
                                                                  key,
                                                                  data.Tran.TotalAmount,
                                                                  data.Tran.OrderItem.SmFee);
                    if (!stripeResult.success)
                    {
                        result.message += $"SmTransService.ChargeCard : Charge failed for Tran {data.Tran.Id}";
                        return(stripeResult);
                    }
                }

                // interesting idea here of  tran history as a separate collection of records
                // tied by tranid to order tran.
                // Another approach might be to convert TranStateElement into an array of state-change entries

                //TranStatusHistory charge = new TranStatusHistory()
                //{
                //    DateCreated = DateTime.UtcNow,
                //    TranId = tran.TranId,
                //    tranEvent = OrderEventType.Charge,
                //    EventName = OrderEventType.Charge.ToString()

                //};
                //result.success = AddTranHistory(charge);
                return(result);
            }
            return(result);
        }
コード例 #3
0
        public Transfer TransferFromSmToVendor(SmChargeInfo vm)
        {
            var options = new TransferCreateOptions
            {
                Amount            = (vm.TotalAmount - vm.SmFee),
                Currency          = "usd",
                Destination       = vm.VendorStripeAcctId,
                SourceTransaction = vm.ChargeId
            };

            var service = new TransferService();

            return(service.Create(options));
        }
コード例 #4
0
        // Charges -------------------------
        //-----------------------------------------------
        // Stripe : Separate charges and transfers  -----------------
        //        create charges on the platform account and then separately transfer funds
        //        to the connected account.This approach is similar to creating destination charges,
        //        but provides greater flexibility over the flow of funds at the cost of a more
        //        complicated integration.
        //  Using this approach:
        //      Your platform account is responsible for the cost of the Stripe fees, refunds,
        //      and chargebacks, handling these for the connected account
        //      The payment itself appears as a charge in your platform account, with a separate,
        //      manual allocation to the connected account, which decreases your platform’s balance
        //      and increases the connected account’s balance
        //      Funds from charges can be allocated to more than one connected account
        //      Platform fees are earned by allocating less than the entire charge amount to the connected account

        public Charge SeparateCharge(SmChargeInfo vm, string TransferGroup)
        {
            var chargeOptions = new ChargeCreateOptions()
            {
                Amount        = vm.TotalAmount,
                ReceiptEmail  = vm.BuyersEmail,
                Source        = vm.BuyerStripeAcctId,
                TransferGroup = TransferGroup,
                Currency      = "usd",
                Description   = "Buyer charged: " + vm.BuyersEmail,
            };

            var    chargeService = new ChargeService();
            Charge charge        = chargeService.Create(chargeOptions);

            return(charge);
        }