本文整理汇总了C#中HttpRequest.MustNotBeNull方法的典型用法代码示例。如果您正苦于以下问题:C# HttpRequest.MustNotBeNull方法的具体用法?C# HttpRequest.MustNotBeNull怎么用?C# HttpRequest.MustNotBeNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpRequest
的用法示例。
在下文中一共展示了HttpRequest.MustNotBeNull方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessCallback
public override CallbackInfo ProcessCallback( Order order, HttpRequest request, IDictionary<string, string> settings )
{
CallbackInfo callbackInfo = null;
try {
order.MustNotBeNull( "order" );
request.MustNotBeNull( "request" );
settings.MustNotBeNull( "settings" );
settings.MustContainKey( "mode", "settings" );
settings.MustContainKey( settings[ "mode" ] + "_secret_key", "settings" );
// If in test mode, write out the form data to a text file
if ( settings.ContainsKey( "mode" ) && settings[ "mode" ] == "test" ) {
LogRequest( request, logPostData: true );
}
StripeChargeCreateOptions chargeOptions = new StripeChargeCreateOptions {
AmountInCents = (int)( order.TotalPrice.Value.WithVat * 100 ),
Currency = CurrencyService.Instance.Get( order.StoreId, order.CurrencyId ).IsoCode,
TokenId = request.Form[ "stripeToken" ],
Description = order.CartNumber,
Capture = settings.ContainsKey( "capture" ) && ( settings[ "capture" ].TryParse<bool>() ?? false )
};
StripeChargeService chargeService = new StripeChargeService( settings[ settings[ "mode" ] + "_secret_key" ] );
StripeCharge charge = chargeService.Create( chargeOptions );
if ( charge.AmountInCents != null && charge.Paid != null && charge.Paid.Value ) {
callbackInfo = new CallbackInfo( (decimal)charge.AmountInCents.Value / 100, charge.Id, charge.Captured != null && charge.Captured.Value ? PaymentState.Captured : PaymentState.Authorized );
}
} catch ( StripeException e ) {
// Pass through request fields
string requestFields = string.Join( "", request.Form.AllKeys.Select( k => "<input type=\"hidden\" name=\"" + k + "\" value=\"" + request.Form[ k ] + "\" />" ) );
//Add error details from the exception.
requestFields = requestFields + "<input type=\"hidden\" name=\"TransactionFailed\" value=\"true\" />";
requestFields = requestFields + "<input type=\"hidden\" name=\"FailureReason.chargeId\" value=\"" + e.StripeError.ChargeId + "\" />";
requestFields = requestFields + "<input type=\"hidden\" name=\"FailureReason.Code\" value=\"" + e.StripeError.Code + "\" />";
requestFields = requestFields + "<input type=\"hidden\" name=\"FailureReason.Error\" value=\"" + e.StripeError.Error + "\" />";
requestFields = requestFields + "<input type=\"hidden\" name=\"FailureReason.ErrorSubscription\" value=\"" + e.StripeError.ErrorSubscription + "\" />";
requestFields = requestFields + "<input type=\"hidden\" name=\"FailureReason.ErrorType\" value=\"" + e.StripeError.ErrorType + "\" />";
requestFields = requestFields + "<input type=\"hidden\" name=\"FailureReason.Message\" value=\"" + e.StripeError.Message + "\" />";
requestFields = requestFields + "<input type=\"hidden\" name=\"FailureReason.Parameter\" value=\"" + e.StripeError.Parameter + "\" />";
string paymentForm = PaymentMethodService.Instance.Get( order.StoreId, order.PaymentInformation.PaymentMethodId.Value ).GeneratePaymentForm( order, requestFields );
//Force the form to auto submit
paymentForm += "<script type=\"text/javascript\">document.forms[0].submit();</script>";
//Write out the form
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Write( paymentForm );
HttpContext.Current.Response.End();
} catch ( Exception exp ) {
LoggingService.Instance.Log( exp, "Stripe(" + order.CartNumber + ") - ProcessCallback" );
}
return callbackInfo;
}
示例2: ProcessRequest
public override string ProcessRequest( Order order, HttpRequest request, IDictionary<string, string> settings )
{
string response = "";
try {
order.MustNotBeNull( "order" );
request.MustNotBeNull( "request" );
settings.MustNotBeNull( "settings" );
// If in test mode, write out the form data to a text file
if ( settings.ContainsKey( "mode" ) && settings[ "mode" ] == "test" ) {
LogRequest( request, logPostData: true );
}
//Stripe supports webhooks
StripeEvent stripeEvent = GetStripeEvent( request );
StripeCharge charge = Mapper<StripeCharge>.MapFromJson( stripeEvent.Data.Object.ToString() );
if ( stripeEvent.Type.StartsWith( "charge." ) ) {
PaymentState paymentState = GetPaymentState( charge );
if ( order.TransactionInformation.PaymentState != paymentState ) {
order.TransactionInformation.TransactionId = charge.Id;
order.TransactionInformation.PaymentState = paymentState;
order.Save();
}
}
} catch ( Exception exp ) {
LoggingService.Instance.Log( exp, "Stripe(" + order.CartNumber + ") - ProcessRequest" );
}
return response;
}
示例3: GetCartNumber
public override string GetCartNumber( HttpRequest request, IDictionary<string, string> settings )
{
string cartNumber = "";
try {
request.MustNotBeNull( "request" );
settings.MustNotBeNull( "settings" );
// If in test mode, write out the form data to a text file
if ( settings.ContainsKey( "mode" ) && settings[ "mode" ] == "test" ) {
LogRequest( request, logPostData: true );
}
StripeEvent stripeEvent = GetStripeEvent( request );
// We are only interested in charge events
if ( stripeEvent != null && stripeEvent.Type.StartsWith( "charge." ) ) {
StripeCharge stripeCharge = Mapper<StripeCharge>.MapFromJson( stripeEvent.Data.Object.ToString() );
cartNumber = stripeCharge.Description;
} else {
HttpContext.Current.Response.StatusCode = (int)HttpStatusCode.BadRequest;
}
} catch ( Exception exp ) {
LoggingService.Instance.Log( exp, "Stripe - Get cart number" );
}
return cartNumber;
}
示例4: ProcessCallback
public override CallbackInfo ProcessCallback( Order order, HttpRequest request, IDictionary<string, string> settings )
{
CallbackInfo callbackInfo = null;
try {
order.MustNotBeNull( "order" );
request.MustNotBeNull( "request" );
settings.MustNotBeNull( "settings" );
settings.MustContainKey( "md5k1", "settings" );
settings.MustContainKey( "md5k2", "settings" );
//Write data when testing
if ( settings.ContainsKey( "test" ) && settings[ "test" ] == "1" ) {
LogRequest( request, logPostData: true );
}
string transaction = request.Form[ "transact" ];
string currencyCode = request.Form[ "currency" ];
string strAmount = request.Form[ "amount" ];
string authkey = request.Form[ "authkey" ];
string capturenow = request.Form[ "capturenow" ];
string fee = request.Form[ "fee" ] ?? "0"; //Is not always in the return data
string paytype = request.Form[ "paytype" ];
string cardnomask = request.Form[ "cardnomask" ];
decimal totalAmount = ( decimal.Parse( strAmount, CultureInfo.InvariantCulture ) + decimal.Parse( fee, CultureInfo.InvariantCulture ) );
bool autoCaptured = capturenow == "1";
string md5CheckValue = string.Empty;
md5CheckValue += settings[ "md5k1" ];
md5CheckValue += "transact=" + transaction;
md5CheckValue += "&amount=" + totalAmount.ToString( "0", CultureInfo.InvariantCulture );
md5CheckValue += "¤cy=" + currencyCode;
//authkey = MD5(k2 + MD5(k1 + "transact=tt&amount=aa¤cy=cc"))
if ( GenerateMD5Hash( settings[ "md5k2" ] + GenerateMD5Hash( md5CheckValue ) ) == authkey ) {
callbackInfo = new CallbackInfo( totalAmount / 100M, transaction, !autoCaptured ? PaymentState.Authorized : PaymentState.Captured, paytype, cardnomask );
} else {
LoggingService.Instance.Log( "DIBS(" + order.CartNumber + ") - MD5Sum security check failed" );
}
} catch ( Exception exp ) {
LoggingService.Instance.Log( exp, "DIBS(" + order.CartNumber + ") - Process callback" );
}
return callbackInfo;
}
示例5: ProcessCallback
public override CallbackInfo ProcessCallback( Order order, HttpRequest request, IDictionary<string, string> settings )
{
CallbackInfo callbackInfo = null;
try {
order.MustNotBeNull( "order" );
request.MustNotBeNull( "request" );
settings.MustNotBeNull( "settings" );
settings.MustContainKey( "md5CallbackSecret", "settings" );
//Write data when testing
if ( settings.ContainsKey( "testmode" ) && settings[ "testmode" ] == "1" ) {
LogRequest( request, logGetData: true );
}
string cartNumber = request.QueryString[ "orderid" ];
string currency = request.QueryString[ "currency" ];
string amount = request.QueryString[ "amount" ];
string cardType = settings.ContainsKey( "cardtype" ) ? settings[ "cardtype" ] : string.Empty;
string md5CheckValue = GenerateMD5Hash( cartNumber + currency + cardType + amount + settings[ "md5CallbackSecret" ] );
if ( order.CartNumber.Replace( StoreService.Instance.Get( order.StoreId ).OrderSettings.CartNumberPrefix, "" ) == cartNumber && md5CheckValue.Equals( request.QueryString[ "checkmd5callback" ] ) ) {
string transaction = request.QueryString[ "transacknum" ];
string cardtype = request.QueryString[ "cardtype" ];
string cardnomask = request.QueryString[ "cardnomask" ];
decimal totalAmount = decimal.Parse( amount, CultureInfo.InvariantCulture );
//Wannafind cant give us info about auto capturing
callbackInfo = new CallbackInfo( totalAmount / 100M, transaction, PaymentState.Authorized, cardtype, cardnomask );
} else {
LoggingService.Instance.Log( "Wannafind(" + order.CartNumber + ") - MD5Sum security check failed" );
}
} catch ( Exception exp ) {
LoggingService.Instance.Log( exp, "Wannafind(" + order.CartNumber + ") - Process callback" );
}
return callbackInfo;
}
示例6: ProcessCallback
public override CallbackInfo ProcessCallback( Order order, HttpRequest request, IDictionary<string, string> settings )
{
CallbackInfo callbackInfo = null;
try {
order.MustNotBeNull( "order" );
request.MustNotBeNull( "request" );
settings.MustNotBeNull( "settings" );
settings.MustContainKey( "privateKey", "settings" );
string orderName = order.CartNumber;
while ( orderName.Length < 4 )
orderName = "0" + orderName;
string checkSum = request.Headers[ "QuickPay-Checksum-Sha256" ];
byte[] bytes = new byte[ request.InputStream.Length ];
request.InputStream.Read( bytes, 0, bytes.Length );
request.InputStream.Position = 0;
string streamContent = Encoding.ASCII.GetString( bytes );
Result result = JsonConvert.DeserializeObject<Result>( streamContent );
if ( orderName == result.OrderId && GetChecksum( streamContent, settings[ "privateKey" ] ) == checkSum ) {
Operation lastAuthorize = result.Operations.LastOrDefault( o => o.Type == "authorize" );
if ( lastAuthorize != null ) {
if ( lastAuthorize.QpStatusCode == "20000" ) {
decimal amount = decimal.Parse( lastAuthorize.Amount, CultureInfo.InvariantCulture ) / 100M;
callbackInfo = new CallbackInfo( amount, result.Id, PaymentState.Authorized, result.Metadata.Type, result.Metadata.Last4 );
} else {
LoggingService.Instance.Warn<QuickPay10>( "Quickpay10(" + order.CartNumber + ") - Error making API request - error code: " + lastAuthorize.QpStatusCode + " | error message: " + lastAuthorize.QpStatusMsg );
}
} else {
LoggingService.Instance.Warn<QuickPay10>( "QuickPay10(" + order.CartNumber + ") - No authorize found" );
}
} else {
LoggingService.Instance.Warn<QuickPay10>( "QuickPay10(" + order.CartNumber + ") - Checksum security check failed" );
}
} catch ( Exception exp ) {
LoggingService.Instance.Error<QuickPay10>( "QuickPay10(" + order.CartNumber + ") - Process callback", exp );
}
return callbackInfo;
}
示例7: ProcessCallback
public override CallbackInfo ProcessCallback( Order order, HttpRequest request, IDictionary<string, string> settings )
{
CallbackInfo callbackInfo = null;
try {
order.MustNotBeNull( "order" );
request.MustNotBeNull( "request" );
settings.MustNotBeNull( "settings" );
settings.MustContainKey( "business", "settings" );
//Write data when testing
if ( settings.ContainsKey( "isSandbox" ) && settings[ "isSandbox" ] == "1" ) {
LogRequest<PayPal>( request, logPostData: true );
}
//Verify callback
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
string response = MakePostRequest( settings.ContainsKey( "isSandbox" ) && settings[ "isSandbox" ] == "1" ? "https://www.sandbox.paypal.com/cgi-bin/webscr" : "https://www.paypal.com/cgi-bin/webscr", Encoding.ASCII.GetString( request.BinaryRead( request.ContentLength ) ) + "&cmd=_notify-validate" );
if ( settings.ContainsKey( "isSandbox" ) && settings[ "isSandbox" ] == "1" ) {
using ( StreamWriter writer = new StreamWriter( File.Create( HostingEnvironment.MapPath( "~/paypal-callback-data-2.txt" ) ) ) ) {
writer.WriteLine( response );
writer.Flush();
}
}
if ( response == "VERIFIED" ) {
string receiverId = request.Form[ "receiver_id" ];
string receiverEmail = request.Form[ "receiver_email" ];
string transaction = request.Form[ "txn_id" ];
decimal amount = decimal.Parse( request.Form[ "mc_gross" ], CultureInfo.InvariantCulture );
string state = request.Form[ "payment_status" ];
string businessSetting = settings[ "business" ];
//Check if the business email is the same in the callback
if ( !string.IsNullOrEmpty( transaction ) && ( ( !string.IsNullOrEmpty( receiverId ) && businessSetting == receiverId ) || ( !string.IsNullOrEmpty( receiverEmail ) && businessSetting == receiverEmail ) ) ) {
//Pending
if ( state == "Pending" ) {
if ( request.Form[ "pending_reason" ] == "authorization" ) {
if ( request.Form[ "transaction_entity" ] == "auth" ) {
callbackInfo = new CallbackInfo( amount, transaction, PaymentState.Authorized );
}
} else if ( request.Form[ "pending_reason" ] == "multi_currency" ) {
callbackInfo = new CallbackInfo( amount, transaction, PaymentState.PendingExternalSystem );
}
//Completed - auto capture
} else if ( state == "Completed" ) {
callbackInfo = new CallbackInfo( amount, transaction, PaymentState.Captured );
}
} else {
LoggingService.Instance.Warn<PayPal>( "PayPal(" + order.CartNumber + ") - Business isn't identical - settings: " + businessSetting + " | request-receiverId: " + receiverId + " | request-receiverEmail: " + receiverEmail );
}
} else {
LoggingService.Instance.Warn<PayPal>( "PayPal(" + order.CartNumber + ") - Couldn't verify response: " + response );
}
} catch ( Exception exp ) {
LoggingService.Instance.Error<PayPal>( "PayPal(" + order.CartNumber + ") - Process callback", exp );
}
return callbackInfo;
}