private Transaction doTransfer(StripeSession session, string recipientID, Account customerAccount, Amount amount, string description, object extraData = null) { var actualAccountData = session.FetchAccountData(customerAccount); try { var prms = new WebClient.RequestParams(this) { UserName = session.SecretKey, Method = HTTPRequestMethod.POST, BodyParameters = new Dictionary <string, string>() { { PRM_RECIPIENT, recipientID }, { PRM_AMOUNT, ((int)((amount.Value * 100))).ToString() }, { PRM_CURRENCY, amount.CurrencyISO.ToLower() }, { PRM_DESCRIPTION, description } } }; dynamic obj = WebClient.GetJsonAsDynamic(new Uri(TRANSFER_URI), prms); var created = ((long)obj.created).FromSecondsSinceUnixEpochStart(); var taId = session.GenerateTransactionID(TransactionType.Transfer); var ta = new Transaction(taId, TransactionType.Transfer, TransactionStatus.Success, Account.EmptyInstance, customerAccount, this.Name, obj.id, created, amount, description: description, extraData: extraData); StatTransfer(amount); return(ta); } catch (Exception ex) { StatTransferError(); var wex = ex as System.Net.WebException; if (wex != null) { var response = wex.Response as System.Net.HttpWebResponse; if (response != null) { string errorMessage = this.GetType().Name + ".doTransfer(recipientID='{0}', customerAccount='{1}', amount='{2}')".Args(recipientID, actualAccountData, amount); PaymentStripeException stripeEx = PaymentStripeException.Compose(response, errorMessage, wex); if (stripeEx != null) { throw stripeEx; } } } throw new PaymentStripeException(StringConsts.PAYMENT_CANNOT_TRANSFER_ERROR + this.GetType() + " .doTransfer(customerAccout='{0}')".Args(actualAccountData), ex); } }
private Transaction doCharge(StripeSession session, Account from, Account to, Amount amount, bool capture = true, string description = null, object extraData = null) { var fromActualData = session.FetchAccountData(from); try { var bodyPrms = new Dictionary <string, string>() { { PRM_AMOUNT, ((int)((amount.Value * 100))).ToString() }, { PRM_CURRENCY, amount.CurrencyISO.ToString().ToLower() }, { PRM_DESCRIPTION, description }, { PRM_CAPTURE, capture.ToString() } }; fillBodyParametersFromAccount(bodyPrms, fromActualData); var prms = new WebClient.RequestParams(this) { UserName = session.SecretKey, Method = HTTPRequestMethod.POST, BodyParameters = bodyPrms }; dynamic obj = WebClient.GetJsonAsDynamic(new Uri(CHARGE_URI), prms); var created = ((long)obj.created).FromSecondsSinceUnixEpochStart(); var taId = session.GenerateTransactionID(TransactionType.Charge); var ta = new Transaction(taId, TransactionType.Charge, TransactionStatus.Success, from, to, this.Name, obj.AsGDID, created, amount, description: description, extraData: extraData); if (capture) { ta.__Apply(Transaction.Operation.Capture(TransactionStatus.Success, created, token: obj.AsGDID, description: description, amount: amount.Value, extraData: extraData)); } StatCharge(amount); return(ta); } catch (Exception ex) { StatChargeError(); var wex = ex as System.Net.WebException; if (wex != null) { var response = wex.Response as System.Net.HttpWebResponse; if (response != null) { string errorMessage = this.GetType().Name + ".Charge(money: {0}, card: {1}, amount: '{2}')".Args(amount.Value, fromActualData.AccountID, amount); var stripeEx = PaymentStripeException.Compose(response, errorMessage, wex); throw stripeEx; } } throw new PaymentStripeException(StringConsts.PAYMENT_CANNOT_CHARGE_PAYMENT_ERROR + this.GetType() + " .Capture(session='{0}', card='{1}', amount='{2}')".Args(session, from, amount), ex); } }