//generate url for newtransaction public void NewTransaction() { String sellerOrderId; Random rn = new Random(); sellerOrderId = rn.Next(1, 99999999).ToString(); String orderTotalAmount = this.Request.Form["orderTotalAmount"]; String orderTotalCurrencyCode = this.Request.Form["orderTotalCurrencyCode"]; String customInformation = this.Request.Form["customInformation"]; parameters = new Dictionary <string, string>(6); parameters.Add(PWAINConstants.SELLER_ORDER_ID, sellerOrderId); parameters.Add(PWAINConstants.ORDER_TOTAL_AMOUNT, orderTotalAmount); parameters.Add(PWAINConstants.ORDER_TOTAL_CURRENCY_CODE, orderTotalCurrencyCode); parameters.Add(PWAINConstants.REDIRECT_URL, "{{=it.returnUrl}}"); /*Set optional parameters*/ //For testing in Sandbox mode, "false" when going live parameters.Add(PWAINConstants.IS_SANDBOX, "true"); //Transaction timeout in seconds parameters.Add(PWAINConstants.TRANSACTION_TIMEOUT, "1000"); parameters.Add(PWAINConstants.CUSTOM_INFORMATION, customInformation); merchantConfiguration = new MerchantConfiguration.Builder().WithSellerIdValue(sellerId).WithAwsAccessKeyIdValue(accessKey).WithAwsSecretKeyIdValue(secretKey).build(); pwaInBackendSDK = new PWAINBackendSDK(merchantConfiguration); String url = pwaInBackendSDK.GetPaymentUrl(parameters); ViewBag.Message = url; Response.Redirect(url); }
protected override async Task <IPaymentRedirectResponse> PaymentRedirectChargeGenerator(ICharge charge) { try { MerchantConfiguration merchantConfiguration; PWAINBackendSDK pwainBackendSDK; Dictionary <String, String> parameters = new Dictionary <string, string>(); parameters.Add(PWAINConstants.SELLER_ORDER_ID, charge.TransactionId.ToString()); parameters.Add(PWAINConstants.ORDER_TOTAL_AMOUNT, charge.Amount.ToString()); parameters.Add(PWAINConstants.ORDER_TOTAL_CURRENCY_CODE, charge.Currency.ToUpper()); parameters.Add(PWAINConstants.REDIRECT_URL, _settings.GetConfigSetting <string>(SettingKeys.PaymentGateway.AmazonPay.ReturnUrl)); if (_settings.GetConfigSetting <string>(SettingKeys.PaymentGateway.AmazonPay.IsSandbox).Equals("true")) { parameters.Add(PWAINConstants.IS_SANDBOX, "true"); } merchantConfiguration = new MerchantConfiguration.Builder().WithSellerIdValue(_settings.GetConfigSetting <string>(SettingKeys.PaymentGateway.AmazonPay.MerchantId)).WithAwsAccessKeyIdValue(_settings.GetConfigSetting <string>(SettingKeys.PaymentGateway.AmazonPay.AccessKey)).WithAwsSecretKeyIdValue(_settings.GetConfigSetting <string>(SettingKeys.PaymentGateway.AmazonPay.SecretKey)).build(); pwainBackendSDK = new PWAINBackendSDK(merchantConfiguration); string chargeUrl = pwainBackendSDK.GetPaymentUrl(parameters); return(GetPaymentRedirectResponse(chargeUrl, "")); } catch (Exception ex) { _logger.Log(LogCategory.Error, new Exception("Failed to create redirect charge", ex)); return(GetPaymentRedirectResponse(null, ex.Message)); } }
//shows response of the transaction public String TransactionResponse() { try { string sellerOrderId = this.Request.QueryString["sellerOrderId"]; string orderTotalAmount = this.Request.QueryString["orderTotalAmount"]; string orderTotalCurrencyCode = this.Request.QueryString["orderTotalCurrencyCode"]; string reasonCode = this.Request.QueryString["reasonCode"]; string amazonOrderId = this.Request.QueryString["amazonOrderId"]; string signature = this.Request.QueryString["signature"]; string status = this.Request.QueryString["status"]; string transactionDate = this.Request.QueryString["transactionDate"]; string description = this.Request.QueryString["description"]; String customInformation = this.Request.QueryString["customInformation"]; //Add the response parameter values to a Dictionary parameters = new Dictionary <string, string>(6); parameters.Add(PWAINConstants.SELLER_ORDER_ID, sellerOrderId); parameters.Add(PWAINConstants.ORDER_TOTAL_AMOUNT, orderTotalAmount); parameters.Add(PWAINConstants.ORDER_TOTAL_CURRENCY_CODE, orderTotalCurrencyCode); parameters.Add(PWAINConstants.REASON_CODE, reasonCode); parameters.Add(PWAINConstants.AMAZON_ORDER_ID, amazonOrderId); parameters.Add(PWAINConstants.VERIFY_SIGNATURE, signature); parameters.Add(PWAINConstants.STATUS, status); parameters.Add(PWAINConstants.TRANSACTION_DATE, transactionDate); parameters.Add(PWAINConstants.DESCRIPTION, description); parameters.Add(PWAINConstants.CUSTOM_INFORMATION, customInformation); merchantConfiguration = new MerchantConfiguration.Builder().WithSellerIdValue(sellerId).WithAwsAccessKeyIdValue(accessKey).WithAwsSecretKeyIdValue(secretKey).build(); pwaInBackendSDK = new PWAINBackendSDK(merchantConfiguration); pwaInBackendSDK.VerifySignature(parameters); return(string.Join(";", parameters)); //Signature verification successful please process the order } catch (Exception e) { return("verification failed:" + e.StackTrace); //Signature verification failed } }