Created
July 9, 2017 23:49
-
-
Save deepumi/277312f2680beedd193939a0b80701d2 to your computer and use it in GitHub Desktop.
Stripe code snippet to charge transaction fee from customer side using CSharp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//code snippet to charge transaction fee from customer side. | |
//https://support.stripe.com/questions/can-i-charge-my-stripe-fees-to-my-customers | |
static void Main() | |
{ | |
//Total fee for platform and stripe would be 5% + .30 Cents | |
const decimal fixedFee = .30M; //.30 cents | |
const decimal fixedFeePercentage = 5M; // 5% = Percentage fees for Stripe and Platform (ex : stripe fee 2.9 + 2.1 platform fee = 5%) | |
decimal goal = 25.00M; //goal amount from customer | |
decimal fee = Math.Round((goal * fixedFeePercentage / 100M) + fixedFee, 2, MidpointRounding.AwayFromZero); | |
decimal formulaFee = 1M - (fixedFeePercentage / 100M); | |
decimal charge = (goal + fixedFee) / formulaFee; // ($100.00 + $0.30) / (1 - 2.9 %) = $100.30 / 0.971 = $103.30. | |
decimal chargeRounded = System.Math.Round(charge, 2, MidpointRounding.AwayFromZero); | |
decimal customerToCharge = chargeRounded * (fixedFeePercentage /100M) + fixedFee; | |
Console.WriteLine("Actual fee => " + fee + " = (" + goal + " * " + fixedFeePercentage + "/100 + " + fixedFee +")"); | |
Console.WriteLine("\nCharge rounded => " + chargeRounded); | |
Console.WriteLine("\nTotal fee with Stripe fee => " + System.Math.Round(customerToCharge,2,MidpointRounding.AwayFromZero)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment