protected PayfirmaTransactionResponse ProcessTransaction(String type, PayfirmaCredentials credentials, PayfirmaCreditCard cc, PayfirmaMetaData metaData, Double amount, Boolean isTest) { PayfirmaTransactionResponse payfirmaResponse = new PayfirmaTransactionResponse(); var webClient = new WebClient(); NameValueCollection requestData = new NameValueCollection(); this.GenerateMetaData(metaData, requestData); requestData.Add("key", credentials.APIKey); requestData.Add("merchant_id", credentials.MerchantID); requestData.Add("amount", amount.ToString()); requestData.Add("card_number", cc.Number); requestData.Add("card_expiry_month", cc.ExpMonth.ToString()); requestData.Add("card_expiry_year", cc.ExpYear.ToString()); requestData.Add("cvv2", cc.CVV2); if (isTest) { requestData.Add("test_mode", "true"); } requestData.Add("do_not_store", "true"); if (type.ToLower() != "sale" && type.ToLower() != "authorize") { // Default to sale transaction type. type = "sale"; } String url = this.GetPayfirmaURL() + "/" + type.ToLower(); ; try { var webResponseByte = webClient.UploadValues(url, "POST", requestData); var webResponse = Encoding.ASCII.GetString(webResponseByte); if (!String.IsNullOrEmpty(webResponse)) { payfirmaResponse = this.HandleTransacitonResponse(webResponse); } else { payfirmaResponse.Error = "Payfirma unknown error"; } } catch (Exception e) { payfirmaResponse.Error = "Payfirma Error: " + e.Message; } return payfirmaResponse; }
public PayfirmaTransactionResponse ProcessAuthorize(PayfirmaCredentials credentials, PayfirmaCreditCard cc, PayfirmaMetaData metaData, Double amount, Boolean isTest) { return(base.ProcessTransaction("authorize", credentials, cc, metaData, amount, isTest)); }
protected PayfirmaTransactionResponse ProcessTransaction(String type, PayfirmaCredentials credentials, PayfirmaCreditCard cc, PayfirmaMetaData metaData, Double amount, Boolean isTest) { PayfirmaTransactionResponse payfirmaResponse = new PayfirmaTransactionResponse(); var webClient = new WebClient(); NameValueCollection requestData = new NameValueCollection(); this.GenerateMetaData(metaData, requestData); requestData.Add("key", credentials.APIKey); requestData.Add("merchant_id", credentials.MerchantID); requestData.Add("amount", amount.ToString()); requestData.Add("card_number", cc.Number); requestData.Add("card_expiry_month", cc.ExpMonth.ToString()); requestData.Add("card_expiry_year", cc.ExpYear.ToString()); requestData.Add("cvv2", cc.CVV2); if (isTest) { requestData.Add("test_mode", "true"); } requestData.Add("do_not_store", "true"); if (type.ToLower() != "sale" && type.ToLower() != "authorize") { // Default to sale transaction type. type = "sale"; } String url = this.GetPayfirmaURL() + "/" + type.ToLower();; try { var webResponseByte = webClient.UploadValues(url, "POST", requestData); var webResponse = Encoding.ASCII.GetString(webResponseByte); if (!String.IsNullOrEmpty(webResponse)) { payfirmaResponse = this.HandleTransacitonResponse(webResponse); } else { payfirmaResponse.Error = "Payfirma unknown error"; } } catch (Exception e) { payfirmaResponse.Error = "Payfirma Error: " + e.Message; } return(payfirmaResponse); }
public PayfirmaTransactionResponse ProcessAuthorize(PayfirmaCredentials credentials, PayfirmaCreditCard cc, PayfirmaMetaData metaData, Double amount, Boolean isTest) { return base.ProcessTransaction("authorize", credentials, cc, metaData, amount, isTest); }
public ProcessPaymentResult ProcessPayment(ProcessPaymentRequest processPaymentRequest) { var result = new ProcessPaymentResult(); var customer = _customerService.GetCustomerById(processPaymentRequest.CustomerId); // Credit Card Info PayfirmaCreditCard cc = new PayfirmaCreditCard() { Number = processPaymentRequest.CreditCardNumber, ExpMonth = processPaymentRequest.CreditCardExpireMonth, ExpYear = processPaymentRequest.CreditCardExpireYear, CVV2 = processPaymentRequest.CreditCardCvv2 }; // Extra Meta Data PayfirmaMetaData payfirmaMeta = new PayfirmaMetaData(); payfirmaMeta.Firstname = customer.BillingAddress.FirstName; payfirmaMeta.Lastname = customer.BillingAddress.LastName; if (!String.IsNullOrEmpty(customer.BillingAddress.Company)) { payfirmaMeta.Company = customer.BillingAddress.Company; } payfirmaMeta.Address1 = customer.BillingAddress.Address1; if (!String.IsNullOrEmpty(customer.BillingAddress.Address2)) { payfirmaMeta.Address2 = customer.BillingAddress.Address2; } payfirmaMeta.City = customer.BillingAddress.City; if (customer.BillingAddress.StateProvince != null) { payfirmaMeta.Province = customer.BillingAddress.StateProvince.Name; } payfirmaMeta.PostalCode = customer.BillingAddress.ZipPostalCode; if (customer.BillingAddress.Country != null) { payfirmaMeta.Country = customer.BillingAddress.Country.Name; } payfirmaMeta.Email = customer.BillingAddress.Email; String currencyCode = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode; payfirmaMeta.Currency = "CA$"; if (currencyCode == "USD") { payfirmaMeta.Currency = "US$"; } payfirmaMeta.OrderId = processPaymentRequest.OrderGuid.ToString(); if (!String.IsNullOrEmpty(customer.BillingAddress.PhoneNumber)) { payfirmaMeta.Telephone = customer.BillingAddress.PhoneNumber; } payfirmaMeta.Description = "Payment via nopCommerce."; PayfirmaTransaction payfirma = new PayfirmaTransaction(); PayfirmaTransactionResponse payfirmaResponse; if (_payfirmaPaymentSettings.TransactMode == TransactMode.Authorize) { payfirmaResponse = payfirma.ProcessAuthorize(this.PopulateMerchantCredentials(), cc, payfirmaMeta, Convert.ToDouble(processPaymentRequest.OrderTotal), _payfirmaPaymentSettings.IsTest); } else { payfirmaResponse = payfirma.ProcessSale(this.PopulateMerchantCredentials(), cc, payfirmaMeta, Convert.ToDouble(processPaymentRequest.OrderTotal), _payfirmaPaymentSettings.IsTest); } if (!String.IsNullOrEmpty(payfirmaResponse.Error)) { result.AddError(payfirmaResponse.Error); } else if (!payfirmaResponse.Result) { result.AddError(payfirmaResponse.ResultMessage); } else { result.AvsResult = payfirmaResponse.AVS; result.AuthorizationTransactionCode = payfirmaResponse.AuthCode; result.AuthorizationTransactionId = payfirmaResponse.TransactionId; result.AuthorizationTransactionResult = payfirmaResponse.ResultMessage; if (_payfirmaPaymentSettings.TransactMode == TransactMode.Authorize) { result.NewPaymentStatus = PaymentStatus.Authorized; } else { result.NewPaymentStatus = PaymentStatus.Paid; } } return result; }