/// <summary> /// Set or remove a new supported payment method for the store /// </summary> /// <param name="paymentMethodId">The paymentMethodId</param> /// <param name="supportedPaymentMethod">The payment method, or null to remove</param> public static void SetSupportedPaymentMethod(this StoreData storeData, PaymentMethodId paymentMethodId, ISupportedPaymentMethod supportedPaymentMethod) { if (supportedPaymentMethod != null && paymentMethodId != null && paymentMethodId != supportedPaymentMethod.PaymentId) { throw new InvalidOperationException("Incoherent arguments, this should never happen"); } if (supportedPaymentMethod == null && paymentMethodId == null) { throw new ArgumentException($"{nameof(supportedPaymentMethod)} or {nameof(paymentMethodId)} should be specified"); } if (supportedPaymentMethod != null && paymentMethodId == null) { paymentMethodId = supportedPaymentMethod.PaymentId; } #pragma warning disable CS0618 JObject strategies = string.IsNullOrEmpty(storeData.DerivationStrategies) ? new JObject() : JObject.Parse(storeData.DerivationStrategies); bool existing = false; foreach (var strat in strategies.Properties().ToList()) { var stratId = PaymentMethodId.Parse(strat.Name); if (stratId.IsBTCOnChain) { // Legacy stuff which should go away storeData.DerivationStrategy = null; } if (stratId == paymentMethodId) { if (supportedPaymentMethod == null) { strat.Remove(); } else { strat.Value = PaymentMethodExtensions.Serialize(supportedPaymentMethod); } existing = true; break; } } if (!existing && supportedPaymentMethod == null && paymentMethodId.IsBTCOnChain) { storeData.DerivationStrategy = null; } else if (!existing && supportedPaymentMethod != null) { strategies.Add(new JProperty(supportedPaymentMethod.PaymentId.ToString(), PaymentMethodExtensions.Serialize(supportedPaymentMethod))); } storeData.DerivationStrategies = strategies.ToString(); #pragma warning restore CS0618 }
internal void SetSupportedPaymentMethods(IEnumerable <ISupportedPaymentMethod> derivationStrategies) { JObject obj = new JObject(); foreach (var strat in derivationStrategies) { obj.Add(strat.PaymentId.ToString(), PaymentMethodExtensions.Serialize(strat)); #pragma warning disable CS0618 // This field should eventually disappear DerivationStrategy = null; } DerivationStrategies = JsonConvert.SerializeObject(obj); #pragma warning restore CS0618 }
internal void SetSupportedPaymentMethods(IEnumerable <ISupportedPaymentMethod> derivationStrategies) { JObject obj = new JObject(); foreach (var strat in derivationStrategies) { obj.Add(strat.PaymentId.ToString(), PaymentMethodExtensions.Serialize(strat)); #pragma warning disable CS0618 if (strat.PaymentId.IsBTCOnChain) { DerivationStrategy = ((JValue)PaymentMethodExtensions.Serialize(strat)).Value <string>(); } } DerivationStrategies = JsonConvert.SerializeObject(obj); #pragma warning restore CS0618 }
/// <summary> /// Set or remove a new supported payment method for the store /// </summary> /// <param name="paymentMethodId">The paymentMethodId</param> /// <param name="supportedPaymentMethod">The payment method, or null to remove</param> public void SetSupportedPaymentMethod(PaymentMethodId paymentMethodId, ISupportedPaymentMethod supportedPaymentMethod) { if (supportedPaymentMethod != null && paymentMethodId != supportedPaymentMethod.PaymentId) { throw new InvalidOperationException("Argument mismatch"); } #pragma warning disable CS0618 JObject strategies = string.IsNullOrEmpty(DerivationStrategies) ? new JObject() : JObject.Parse(DerivationStrategies); bool existing = false; foreach (var strat in strategies.Properties().ToList()) { var stratId = PaymentMethodId.Parse(strat.Name); if (stratId.IsBTCOnChain) { // Legacy stuff which should go away DerivationStrategy = null; } if (stratId == paymentMethodId) { if (supportedPaymentMethod == null) { strat.Remove(); } else { strat.Value = PaymentMethodExtensions.Serialize(supportedPaymentMethod); } existing = true; break; } } if (!existing && supportedPaymentMethod == null && paymentMethodId.IsBTCOnChain) { DerivationStrategy = null; } else if (!existing && supportedPaymentMethod != null) { strategies.Add(new JProperty(supportedPaymentMethod.PaymentId.ToString(), PaymentMethodExtensions.Serialize(supportedPaymentMethod))); } DerivationStrategies = strategies.ToString(); #pragma warning restore CS0618 }