I have this service class in RoR:
class PaypalService
attr_reader :api
def initialize()
@api = PayPal::SDK::Merchant::API.new
puts "PaypalService initilized"
end
# Paypal setExpressCheckout
def self.setExpressCheckout(billingType, returnURL, cancelURL, amount, description, isRecurring, locale)
new
if billingType == "credit-card"
billingType = "Billing"
else
billingType = "Login"
end
if isRecurring
varSetExpressCheckoutRequestDetails = createSetExpressCheckoutRecurringRequestDetails(billingType, returnURL, cancelURL, amount, description, isRecurring, locale)
else
varSetExpressCheckoutRequestDetails = createSetExpressCheckoutRequestDetails(billingType, returnURL, cancelURL, amount, description, isRecurring, locale)
end
@set_express_checkout = @api.build_set_express_checkout(varSetExpressCheckoutRequestDetails)
...
My call to the service is:
I want to initilize the @api attribute and use it whenever I execute one service method. This is my call from the client controller:
expressCheckoutResponse = PaypalService.setExpressCheckout(params[:paymentType],
"http://" + Yanpy::IP + "/app/index.html#/boat-booking-payment",
"http://" + Yanpy::IP + "/app/index.html#/boat-booking",
totalPrice,
description,
false,
'ES')
Log output:
PaypalService initilized
Completed 500 Internal Server Error in 625ms
NoMethodError (undefined method `build_set_express_checkout' for nil:NilClass):
lib/paypal_service.rb:30:in `setExpressCheckout'
app/controllers/bookings_controller.rb:275:in `create'
What am I missing?