Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="isTest">Defines if the transaction will be sent as test mode</param>
        /// <param name="pCommand">Defines the command that will be aplied to the API, use Tulpep.PayULibrary.Cross.Constants to set it.</param>
        /// <param name="pLanguage">Defines the languaje wich will be used in the API to generate the responses to the user,
        /// use Tulpep.PayULibrary.Cross.Constants to set it.</param>
        /// <param name="pCreditCard"></param>
        /// <param name="pTX_VALUE"></param>
        /// <param name="pBuyer"></param>
        /// <param name="pOrderShippingAddress"></param>
        /// <param name="pPayer"></param>
        /// <param name="pExtraParameters"></param>
        /// <param name="pPaymentCountry"></param>
        /// <param name="pPaymentMethod"></param>
        /// <param name="pType"></param>
        /// <param name="pUserAgent"></param>
        /// <param name="pDescription"></param>
        /// <param name="pNotifyUrl"></param>
        /// <param name="pReferenceCode"></param>
        /// <param name="pCookie"></param>
        /// <param name="pDeviceSessionId"></param>
        /// <param name="pIpAddress"></param>
        /// <returns></returns>
        public static async Task <RootPayUPaymentCreditCardResponse> MakeACreditCardPayment(bool isTest, string pCommand, string pLanguage,
                                                                                            Request_CreditCard_CreditCard pCreditCard, Request_TXVALUE pTX_VALUE, bool calculateTaxes, Request_CreditCard_Buyer pBuyer,
                                                                                            Address pOrderShippingAddress, Request_CreditCard_Payer pPayer, Request_ExtraParameters pExtraParameters,
                                                                                            string pPaymentCountry, string pPaymentMethod, string pType, string pUserAgent, string pDescription,
                                                                                            string pNotifyUrl, string pReferenceCode, string pCookie, string pDeviceSessionId, string pIpAddress)
        {
            try
            {
                string productionOrTestApiKey = ConfigurationManager.AppSettings["PAYU_API_KEY"];

                string productionOrTestApiLogIn = ConfigurationManager.AppSettings["PAYU_API_LOGIN"];

                string productionOrTestMerchantId = ConfigurationManager.AppSettings["PAYU_API_MERCHANTID"];

                int productionOrTestAccountId = int.Parse(ConfigurationManager.AppSettings["PAYU_API_ACCOUNTID"]);

                string productionOrTestUrl = ConfigurationManager.AppSettings["PAYU_API_CONNECTION_URL"] + PayU_Constants.DefaultProductionPaymentsConnectionUrl;


                var url = productionOrTestUrl;
                if (url != null)
                {
                    string pSignature = CryptoHelper.RequestSignature(new RequestSignatureModel
                    {
                        ApiKey        = productionOrTestApiKey,
                        MerchantId    = productionOrTestMerchantId,
                        Currency      = pTX_VALUE.currency,
                        ReferenceCode = pReferenceCode,
                        Value         = pTX_VALUE.value
                    });
                    var jsonObject = new RootPayUPaymentCreditCardRequest()
                    {
                        command  = pCommand,
                        language = pLanguage,
                        merchant = new Merchant()
                        {
                            apiKey   = productionOrTestApiKey,
                            apiLogin = productionOrTestApiLogIn
                        },
                        test        = isTest,
                        transaction = new Request_CreditCard_Transaction()
                        {
                            cookie          = pCookie,
                            creditCard      = pCreditCard,
                            deviceSessionId = pDeviceSessionId,
                            extraParameters = pExtraParameters,
                            ipAddress       = pIpAddress,
                            order           = new Request_CreditCard_Order()
                            {
                                accountId        = productionOrTestAccountId,
                                additionalValues = calculateTaxes ? new Request_AdditionalValues()
                                {
                                    TX_VALUE = pTX_VALUE,
                                    TX_TAX   = new Request_TXTAX()
                                    {
                                        currency = pTX_VALUE.currency,
                                        value    = Tax_BaseReturnHelper.CalculateTaxValue(pTX_VALUE.value)
                                    },
                                    TX_TAX_RETURN_BASE = new Request_TXTAXRETURNBASE()
                                    {
                                        currency = pTX_VALUE.currency,
                                        value    = Tax_BaseReturnHelper.CalculateBaseReturnValue(pTX_VALUE.value)
                                    }
                                } : new Request_AdditionalValues()
                                {
                                    TX_VALUE = pTX_VALUE,
                                    TX_TAX   = new Request_TXTAX()
                                    {
                                        currency = pTX_VALUE.currency,
                                        value    = 0
                                    },
                                    TX_TAX_RETURN_BASE = new Request_TXTAXRETURNBASE()
                                    {
                                        currency = pTX_VALUE.currency,
                                        value    = 0
                                    }
                                },
                                buyer           = pBuyer,
                                description     = pDescription,
                                language        = pLanguage,
                                notifyUrl       = pNotifyUrl,
                                referenceCode   = pReferenceCode,
                                signature       = pSignature,
                                shippingAddress = pOrderShippingAddress
                            },
                            payer          = pPayer,
                            paymentCountry = pPaymentCountry,
                            paymentMethod  = pPaymentMethod,
                            type           = pType,
                            userAgent      = pUserAgent
                        }
                    };

                    string requestJson = JsonConvert.SerializeObject(jsonObject);

                    HttpWebResponse resp = await HtttpWebRequestHelper.SendJSONToPayUGeneralApi(url, requestJson, HttpMethod.POST);

                    if (resp == null)
                    {
                        return(null);
                    }

                    if (resp.StatusCode == HttpStatusCode.OK)
                    {
                        using (System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream()))
                        {
                            string res = await sr.ReadToEndAsync();

                            var des = JsonConvert.DeserializeObject <RootPayUPaymentCreditCardResponse>(res);
                            sr.Close();
                            if (des != null)
                            {
                                return(des);
                            }
                        }
                    }
                    else
                    {
                        throw new Exception(resp.StatusCode + "; " + resp.StatusDescription);
                    }
                }
            }
            catch
            {
                throw;
            }
            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="isTest"></param>
        /// <param name="pCommand"></param>
        /// <param name="pLanguage"></param>
        /// <returns></returns>
        public static async Task <RootPayUActivePaymentMethodResponse> GetActivePaymentMethods(bool isTest, string pCommand, string pLanguage)
        {
            try
            {
                string productionOrTestApiKey = ConfigurationManager.AppSettings["PAYU_API_KEY"];

                string productionOrTestApiLogIn = ConfigurationManager.AppSettings["PAYU_API_LOGIN"];

                string productionOrTestUrl = ConfigurationManager.AppSettings["PAYU_API_CONNECTION_URL"] + PayU_Constants.DefaultProductionPaymentsConnectionUrl;

                var url = productionOrTestUrl;
                if (url != null)
                {
                    var jsonObject = new RootPayUActivePaymentMethodRequest()
                    {
                        command  = pCommand,
                        language = pLanguage,
                        merchant = new Merchant()
                        {
                            apiKey   = productionOrTestApiKey,
                            apiLogin = productionOrTestApiLogIn
                        },
                        test = isTest
                    };

                    string requestJson = JsonConvert.SerializeObject(jsonObject);


                    HttpWebResponse resp = await HtttpWebRequestHelper.SendJSONToPayUGeneralApi(url, requestJson, HttpMethod.POST);

                    if (resp == null)
                    {
                        return(null);
                    }

                    if (resp.StatusCode == HttpStatusCode.OK)
                    {
                        using (System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream()))
                        {
                            string res = await sr.ReadToEndAsync();

                            var des = JsonConvert.DeserializeObject <RootPayUActivePaymentMethodResponse>(res);
                            sr.Close();
                            if (des != null)
                            {
                                return(des);
                            }
                        }
                    }
                    else
                    {
                        throw new Exception(resp.StatusCode + "; " + resp.StatusDescription);
                    }
                }
            }
            catch
            {
                throw;
            }
            return(null);
        }