0
votes

For customer with existing payment profile id(Saved credit card) we are using "createCustomerProfileTransactionController" as follow for authorization.

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;

        }

And for customer without existing payment profile id we using "createTransactionRequest" as follow for authorization.

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;

        }

And following same technique for capture and void a transaction.

My question is can we use "createTransactionRequest" for all transaction like authorize, capture and void a transaction for both customer having payment profile id and one time customer.

I could find any clue in authorize.net on line documentation. Please guide us how to do that.

2

2 Answers

1
votes

Yes, you can use createTransactionRequest for Auth/Capture, Auth Only, Prior Auth and Capture, Void and Refund by changing the transactionRequestType and paymentType.

0
votes

For anyone with the same question, like me, here is the answer.
Note that Order is optional, and obviously profile is optional.

            ...
            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 }
        };
    }