private static decimal CalculateShipping(PaymentRequestOptions options, decimal subtotal) { var freeShippingThreshold = options.FreeShippingThreshold ?? 0.0m; var flatShippingRate = options.FlatShippingRate ?? 0.0m; return(subtotal > freeShippingThreshold ? 0.0m : flatShippingRate); }
public PaymentRequest(IList <CartView> cart, PaymentRequestOptions options) { InitApiCredentialsForMode(options); Init(options, cart); ItemList = GetItemListFrom(cart); InvoiceNumber = options.InvoiceNumber.ToString(); ReturnUrl = ($"{options.RequestUri}review").ToLower(); }
private void Init(PaymentRequestOptions options, IEnumerable <CartView> cart) { const decimal tax = 0.00m; var subTotal = CalculateSubTotal(cart); var shipping = CalculateShipping(options, subTotal); var total = subTotal + tax + shipping; Subtotal = subTotal.ToString(MoneyFormat); Total = total.ToString(MoneyFormat); Shipping = shipping.ToString(MoneyFormat); }
private void InitApiCredentialsForMode(PaymentRequestOptions options) { if (options.IsSandbox) { Mode = SandboxMode; ClientId = options.PaypalSandBoxClientId; ClientSecret = options.PaypalSandBoxSecret; } else { Mode = LiveMode; ClientId = options.PaypalClientId; ClientSecret = options.PaypalClientSecret; } }