createTransactionRequest可以用于授权、捕获和取消现有支付配置文件id的交易吗?

本文关键字:配置文件 id 交易 取消 用于 授权 createTransactionRequest | 更新日期: 2023-09-27 18:17:21

对于具有现有支付配置文件id(已保存的信用卡)的客户,我们使用如下的"createCustomerProfileTransactionController"进行授权。

public createCustomerProfileTransactionResponse AuthorizePaymentProfile(int customerProfileId, int customerPaymentProfileId, decimal amount)
        {
            createCustomerProfileTransactionResponse response = null;
            ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = environment;
            // define the merchant information (authentication / transaction id)
            ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType()
            {
                name = apiLoginID,
                ItemElementName = ItemChoiceType.transactionKey,
                Item = apiTransactionKey,
            };
            //construct request
            var request = new createCustomerProfileTransactionRequest
            {
                merchantAuthentication = new merchantAuthenticationType
                {
                    name = apiLoginID,
                    ItemElementName = ItemChoiceType.transactionKey,
                    Item = apiTransactionKey
                },
                transaction = new profileTransactionType
                {
                    Item = new profileTransAuthOnlyType
                    {
                        customerProfileId = customerProfileId.ToString(),
                        customerPaymentProfileId = customerPaymentProfileId.ToString(),
                        amount = amount
                    }
                },
                extraOptions = "x_duplicate_window=1"
            };
            //Prepare Request
            var controller = new createCustomerProfileTransactionController(request);
            controller.Execute();
            //Send Request to EndPoint
            response = controller.GetApiResponse();
            return response;
        }

对于没有现有支付配置文件id的客户,我们使用如下的"createTransactionRequest"进行授权。

public createTransactionResponse AuthorizeOneTimePayment(Card cardInfo, decimal amount)
        {
            createTransactionResponse response = null;
            ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = environment;
            //define the merchant information (authentication / transaction id)
            ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType()
            {
                name = apiLoginID,
                ItemElementName = ItemChoiceType.transactionKey,
                Item = apiTransactionKey,
            };
            var creditCard = new creditCardType
            {
                cardNumber = cardInfo.CardNumber,// "4111111111111111",
                expirationDate = cardInfo.ExpirationDate// "0718"
                //cardCode=cardInfo.VerificationCode
            };
            //standard api call to retrieve response
            var paymentType = new paymentType { Item = creditCard };
            string firstName = string.Empty;
            string lastName = string.Empty;
            if (!string.IsNullOrWhiteSpace(cardInfo.BillingName))
            {
                string[] name = GetBillName(cardInfo.BillingName);
                firstName = name[0];
                lastName = name[1];
            }
            var transactionRequest = new transactionRequestType
            {
                transactionType = transactionTypeEnum.authOnlyTransaction.ToString(), // authorize only
                amount = amount,
                payment = paymentType,
                billTo = new customerAddressType
                {
                    firstName = firstName,
                    lastName = lastName,
                    address = cardInfo.BillingAddress,
                    city = cardInfo.BillingCity,
                    state = cardInfo.BillingState,
                    zip = cardInfo.BillingZipCode
                }
            };
            var request = new createTransactionRequest { transactionRequest = transactionRequest };
            // instantiate the controller that will call the service
            var controller = new createTransactionController(request);
            controller.Execute();
            // get the response from the service (errors contained if any)
            response = controller.GetApiResponse();
            return response;
        }

并使用相同的技术来捕获和取消事务。

我的问题是,我们可以使用"createTransactionRequest"为所有的交易,如授权,捕获和无效交易的客户都有支付配置文件id和一次性客户。

我可以在authorize.net的在线文档中找到任何线索。请指导我们怎么做

createTransactionRequest可以用于授权、捕获和取消现有支付配置文件id的交易吗?

是的,您可以通过更改transactionRequestType和paymentType来使用createTransactionRequest进行认证/捕获、仅认证、预先认证和捕获、无效和退款。

对于像我一样有同样问题的人来说,这里是答案。
注意Order是可选的,而profile显然也是可选的。

            ...
            var transactionRequest = new transactionRequestType {
                transactionType = transactionTypeEnum.authOnlyTransaction.ToString(),
                amount = amount,
                order = new orderType { invoiceNumber = OrderID, description = desc },
                profile = getCustomerPaymentProfile(CustomerProfileId, creditProfileID)
            };
            ...
    private customerProfilePaymentType getCustomerPaymentProfile(string CustomerProfileId, string creditProfileID) {
        return new customerProfilePaymentType {
            customerProfileId = CustomerProfileId,
            paymentProfile = new paymentProfile { paymentProfileId = creditProfileID }
        };
    }