Reputation: 3174
I've got a working Ruby implementation that uses Authorize.net's PayPal Express API Authorize & Capture function. I'm trying to add the shipping method firstName to the request but I always get an error. Here is my code:
transaction = Transaction.new("xxxxx","xxxxx")
request = CreateTransactionRequest.new
payPalType = PayPalType.new()
payPalType.successUrl = "https://www.example.com"
payPalType.cancelUrl = "https://www.example.com"
#standard api call to retrieve response
paymentType = PaymentType.new()
paymentType.payPal = payPalType
request.transactionRequest = TransactionRequestType.new()
request.transactionRequest.amount = 99.99
request.transactionRequest.payment = paymentType
request.transactionRequest.transactionType = TransactionTypeEnum::AuthCaptureTransaction
#I WANT TO SET THE SHIPPING FIRST NAME HERE:
request.transactionRequest.shipTo.firstName="Bob"
response = transaction.create_transaction(request)
Here is the error I am getting when I try to set the shipping method name:
NoMethodError (undefined method `firstName=' for nil:NilClass):
I understand the error, but cannot figure out if either I am calling the wrong method on the wrong object or what is going on. The docs aren't very clear on this method call. Any help would be appreciated. Thanks
Upvotes: 0
Views: 118
Reputation: 2290
I've only used billTo and not shipTo, although I guess they both should accept a CustomerAddressType
so it should be something like:
transactionRequest.shipTo = CustomerAddressType.new(
user[:user_name][:first],
user[:user_name][:last],
nil,
user[:user_address][:street],
user[:user_address][:city],
user[:user_address][:state],
user[:user_address][:zip],
'USA'
)
I left the fields but you should check if the order is the same for "shipTo".
Upvotes: 1