public static ProfileTransactionType CreateProfileTransactionType(ProfileTransRefundType transType) { return(new ProfileTransactionType() { Item = transType }); }
public static bool CreateCustomerProfileTransactionRefund(SiteDT site, InvoiceDT invoice, TransactionDT transaction, CustomerDT customer, CreditCardDT creditCard, out long transactionId, out string message) { //This datetime is when system change. int deployYear = CastleClub.BusinessLogic.Data.GlobalParameters.DeployYear; int deployMonth = CastleClub.BusinessLogic.Data.GlobalParameters.DeployMonth; int deployDay = CastleClub.BusinessLogic.Data.GlobalParameters.DeployDay; if (invoice.BilledDate >= new DateTime(deployYear, deployMonth, deployDay)) { MerchantAuthenticationType merchantAT = new MerchantAuthenticationType(); merchantAT.name = site.AuthorizeLoginId; merchantAT.transactionKey = site.AuthorizeTransactionKey; ProfileTransactionType profileTT = new ProfileTransactionType(); ProfileTransRefundType profileTRT = new ProfileTransRefundType(); OrderExType orderET = new OrderExType(); orderET.invoiceNumber = invoice.Id.ToString(); profileTRT.amount = invoice.Amount; profileTRT.transId = transaction.AuthorizeTransactionId.ToString(); profileTRT.customerProfileId = customer.AuthorizeProfileId; profileTRT.customerProfileIdSpecified = true; profileTRT.customerPaymentProfileId = creditCard.AuthorizePaymentProfileId; profileTRT.customerPaymentProfileIdSpecified = true; profileTRT.order = orderET; profileTT.Item = profileTRT; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; ServiceSoapClient client = new ServiceSoapClient(); CreateCustomerProfileTransactionResponseType resp = client.CreateCustomerProfileTransaction(merchantAT, profileTT, String.Empty); if (resp.directResponse != null) { PaymentGatewayResponse paymentGatewayResponse = new PaymentGatewayResponse(resp.directResponse); transactionId = paymentGatewayResponse.TransactionId; message = paymentGatewayResponse.ResponseReasonText; } else { transactionId = 0; if (resp.messages.Length > 0) { message = resp.messages[0].text; } else { message = ""; } } return(resp.resultCode == MessageTypeEnum.Ok); } else { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; using (ServiceSoapClient client = new ServiceSoapClient()) { MerchantAuthenticationType merchant = new MerchantAuthenticationType() { name = site.AuthorizeLoginId, transactionKey = site.AuthorizeTransactionKey }; ProfileTransactionType profileTT = new ProfileTransactionType(); ProfileTransRefundType profileTRT = new ProfileTransRefundType(); profileTRT.amount = invoice.Amount; profileTRT.transId = transaction.AuthorizeTransactionId.ToString(); profileTRT.creditCardNumberMasked = "XXXX" + creditCard.LastFourDigit; profileTT.Item = profileTRT; var resp = client.CreateCustomerProfileTransaction(merchant, profileTT, string.Empty); if (resp.resultCode == MessageTypeEnum.Ok) { PaymentGatewayResponse paymentGatewayResponse = new PaymentGatewayResponse(resp.directResponse); transactionId = paymentGatewayResponse.TransactionId; message = paymentGatewayResponse.ResponseReasonText; } else { transactionId = 0; message = string.Empty; message = resp.messages != null && resp.messages.Count() > 0 ? resp.messages.Select(a => a.text).Aggregate((a, b) => a + " - " + b) : string.Empty; } return(resp.resultCode == MessageTypeEnum.Ok); } } }