コード例 #1
0
ファイル: Ogone.cs プロジェクト: EtchUK/Payment-providers
        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( "SHAOUTPASSPHRASE", "settings" );

            //Write data when testing
            if ( settings.ContainsKey( "TESTMODE" ) && settings[ "TESTMODE" ] == "1" ) {
              LogRequest<Ogone>( request, logGetData: true );
            }

            Dictionary<string, string> inputFields = new Dictionary<string, string>();

            string shaSign = request.QueryString[ "SHASIGN" ];
            string strAmount = request.QueryString[ "AMOUNT" ];
            string transaction = request.QueryString[ "PAYID" ];
            string status = request.QueryString[ "STATUS" ];
            string cardType = request.QueryString[ "BRAND" ];
            string cardNo = request.QueryString[ "CARDNO" ];

            foreach ( string key in request.QueryString.Keys ) {
              if ( !key.Equals( "SHASIGN" ) )
            inputFields[ key ] = request.QueryString[ key ];
            }

            string strToHash = string.Join( "", inputFields.OrderBy( i => i.Key ).Select( i => i.Key.ToUpperInvariant() + "=" + i.Value + settings[ "SHAOUTPASSPHRASE" ] ) );
            string digest = new SHA512Managed().ComputeHash( Encoding.UTF8.GetBytes( strToHash ) ).ToHex().ToUpperInvariant();

            if ( order.CartNumber == request.QueryString[ "ORDERID" ] && digest.Equals( shaSign ) ) {
              callbackInfo = new CallbackInfo( decimal.Parse( strAmount, CultureInfo.InvariantCulture ), transaction, status == "5" || status == "51" ? PaymentState.Authorized : PaymentState.Captured, cardType, cardNo );
            } else {
              LoggingService.Instance.Warn<Ogone>( "Ogone(" + order.CartNumber + ") - SHASIGN check isn't valid - Calculated digest: " + digest + " - Ogone SHASIGN: " + shaSign );
            }
              } catch ( Exception exp ) {
            LoggingService.Instance.Error<Ogone>( "Ogone(" + order.CartNumber + ") - Process callback", exp );
              }

              return callbackInfo;
        }