我在我的本地计算机和 aws ec2 Production服务器上创建了窗口任务计划程序,它们每月为客户收费, 在我的本地计算机上,它工作正常,但是在我的ec2服务器上,它抛出异常,因此无法正常工作。
public static StripeChargeResponse CreateMonthlyCharge(string customerId, string CardId, int UserId, string Email, string IsNotifiedForFailPayment)
{
var Obj = new StripeChargeResponse();
var ObjStatus = new Status();
try
{
StripeConfiguration.SetApiKey(Settings.GetStripeSecretKey());
float FinalAmount = 0;
// make discount if applied
bool IsDeleted = true;
bool IsActive = false;
bool IsUsed = false;
int UseLimit = 0;
float Amount = 0;
ObjStatus = DiscountCalculation(UserId);
dynamic data = ObjStatus.Data;
if (ObjStatus.Data != null)
{
IsDeleted = (bool)data.IsDeleted;
IsActive = (bool)data.IsActive;
IsUsed = (bool)data.IsUsed;
UseLimit = (int)data.UseLimit;
Amount = (float)data.DiscountAmount;
}
if (!IsDeleted && IsActive && UseLimit == 2)
{
FinalAmount = 99 - Amount;
}
else
{
if (!IsUsed)
{
FinalAmount = 99 - Amount;
}
else
{
FinalAmount = 99;
}
}
StripeChargeCreateOptions chargeoption = new StripeChargeCreateOptions();
chargeoption.Metadata = new Dictionary<string, string>();
chargeoption.Metadata.Add("UserId", UserId.ToString());
chargeoption.Amount = Convert.ToInt32(Convert.ToDouble(FinalAmount) * 100);
chargeoption.Currency = "usd";
chargeoption.CustomerId = customerId;
chargeoption.Description = "Monthly uses charge.";
var chargeService = new StripeChargeService(Settings.GetStripeSecretKey());
// For Create Charge
StripeCharge stripeCharge = chargeService.Create(chargeoption);
if (stripeCharge != null)
{
Obj.id = stripeCharge.Id;
var ds = DataAccess.ExecuteDataset(Settings.GetConnectionString(), "SaveUserSubscription", UserId, Obj.id, FinalAmount);
Obj.IsSuccess = true;
Obj.Message = "Success";
}
else
{
Obj.IsSuccess = false;
Obj.Message = "fail";
}
}
catch (StripeException ex)
{
InsertErrorLogs("StripeMethods UserId" + UserId, "CreateMonthlyCharge - Scheduler Utility from StripeException CustId " + customerId, ex.Message, ex.StackTrace, UserId);
if (!Convert.ToBoolean(IsNotifiedForFailPayment))
{
bool IsSend = EmailHelper.EmailHelper.SendCardDeclineMail(Email);
if (IsSend)
{
var ds = DataAccess.ExecuteDataset(Settings.GetConnectionString(), "UpdatePaymentStatusIncaseOfFailTransection", UserId);
}
}
}
catch (Exception ex)
{
InsertErrorLogs("StripeMethods UserId" + UserId, "CreateMonthlyCharge - Scheduler Utility -: CustId" + customerId, ex.Message, ex.StackTrace, UserId);
var ds = DataAccess.ExecuteDataset(Settings.GetConnectionString(), "UpdatePaymentStatusIncaseOfFailTransection");
}
return Obj;
}
以上代码在我的本地任务计划程序中工作正常,但在我的ec2服务器(生产服务器)中,由于波纹管引发异常
在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
中的KegsDirectUtilty.Stripe.StripeMethods.CreateMonthlyCharge(String customerId,String CardId,Int32 UserId,String Email,String IsNotifiedForFailPayment)中
在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)
在Stripe.Infrastructure.Requestor.ExecuteRequest(HttpRequestMessage requestMessage)
在Stripe.Infrastructure.Requestor.PostString(String url,StripeRequestOptions requestOptions)
在Stripe.StripeChargeService.Create(StripeChargeCreateOptions createOptions,StripeRequestOptions requestOptions)中
在D:\ AzzimKazzi \ Projects \ KegsDirect \ Developoment \ KegsDirectUtilty \ KegsDirectUtilty \ Stripe \ StripeMethods.cs:line 137
任何人都可以给我指路。