module FlexCommerce::PaypalExpress::Api

A concern for use in paypal express services that need access to the API

Constants

USER_ERRORS

Private Instance Methods

convert_amount(amount) click to toggle source
# File lib/paypal_express/api.rb, line 80
def convert_amount(amount)
  (amount * 100.0).round.to_i
end
gateway() click to toggle source
# File lib/paypal_express/api.rb, line 30
def gateway
  verify_credentials
  @gateway ||= gateway_class.new(
    test: test_mode,
    login: paypal_login,
    password: paypal_password,
    signature: paypal_signature)
end
is_user_error?(response) click to toggle source
# File lib/paypal_express/api.rb, line 39
def is_user_error?(response)
  (USER_ERRORS.keys & response_error_codes(response)).present?
end
mark_transaction_with_errors!(response) click to toggle source
# File lib/paypal_express/api.rb, line 43
def mark_transaction_with_errors!(response)
  errors = []
  response_error_codes(response).each do |error_code|
    errors.push(USER_ERRORS[error_code])
  end
  errors
end
paypal_login() click to toggle source

PAYPAL CREDENTAILS

# File lib/paypal_express/api.rb, line 68
def paypal_login
  FlexCommerceApi.config.paypal_login
end
paypal_password() click to toggle source
# File lib/paypal_express/api.rb, line 72
def paypal_password
  FlexCommerceApi.config.paypal_password
end
paypal_signature() click to toggle source
# File lib/paypal_express/api.rb, line 76
def paypal_signature
  FlexCommerceApi.config.paypal_signature
end
response_error_codes(response) click to toggle source
# File lib/paypal_express/api.rb, line 51
def response_error_codes(response)
  response.params["error_codes"].split(",")
end
test_mode() click to toggle source

DEFAULT value for test mode is true.

# File lib/paypal_express/api.rb, line 62
def test_mode
  FlexCommerceApi.config.order_test_mode == true || FlexCommerceApi.config.order_test_mode == "true"
end
verify_credentials() click to toggle source
# File lib/paypal_express/api.rb, line 55
def verify_credentials
  unless paypal_login.present? && paypal_password.present? && paypal_signature.present? then
    raise "Please ensure all Paypal Credentails are set in your env file."
  end
end