示例#1
0
        private static string GetEncryptedString(M2uPayload payload)
        {
            var paymentInfo = new StringBuilder();

            paymentInfo.Append($"Login${ payload.PayeeCode.ToJavaNullString() }");
            paymentInfo.Append($"$1${ payload.Amount.ToJavaNullString() }");

            /*
             * Case 1:
             *  ( RefNo isNull AND AccountNo isNotNull )
             *
             *  Format : Login$( )$1$( )$$$1$( )$( )
             *  Param  : PayeeCode, Amount, AccountNo, CallbackUrl
             *
             * Case 2:
             *  ( accountNo isNull AND RefNo isNotNull )
             *
             *  Format : Login$( )$1$( )$1$( )$$$( )
             *  Param  : PayeeCode, Amount, RefNo, CallbackUrl
             *
             * Case 3:
             *  ( any other cases )
             *
             *  Format : Login$( )$1$( )$1$( )$1$( )$( )
             *  Param  : PayeeCode, Amount, RefNo, AccountNo, CallbackUrl
             */

            if (string.IsNullOrEmpty(payload.RefNo) &&
                !string.IsNullOrEmpty(payload.AccountNo))
            {
                paymentInfo.Append($"$$$1${ payload.AccountNo }");
            }
            else if (string.IsNullOrEmpty(payload.AccountNo) &&
                     !string.IsNullOrEmpty(payload.RefNo))
            {
                paymentInfo.Append($"$1${ payload.RefNo.ToJavaNullString() }$$");
            }
            else
            {
                paymentInfo.Append($"$1${ payload.RefNo.ToJavaNullString() }");
                paymentInfo.Append($"$1${ payload.AccountNo.ToJavaNullString() }");
            }

            paymentInfo.Append($"${ payload.CallbackUrl.ToJavaNullString() }");

            return(M2uCryptoService.Encrypt(paymentInfo.ToString()).UrlEncodeUpperCase());
        }
示例#2
0
        public static string GetEncryptionJsonString(
            this M2uPayload payload,
            int environment)
        {
            var actionUrl       = string.Empty;
            var encryptedString = string.Empty;

            try
            {
                actionUrl = GetActionUrl((Environment)Enum.Parse(
                                             typeof(Environment), environment.ToString()));

                encryptedString = GetEncryptedString(payload);
            }
            catch (Exception)
            {
                encryptedString = "FAIL";
            }

            return(new M2uEncryptedJson(actionUrl, encryptedString).ToJson());
        }