-
Notifications
You must be signed in to change notification settings - Fork 0
Adding formats
Format classes are loaded when the connection is established to Paysimple; therefore, they have to have a particular format.
###namespace
PS::Api::Soap
or
PS::Api::Xml
###Initializer
The initializer should set the authentication information for making requests to the api to nil. The instance variable env is the only exception here, we set that to production to make just using the gem easier. Setting the instance variables in this way allows the connection handling to see those as require attributes, i.e. validate input against them, and then can dynamically assign the input from Base.establish_connection. The code that handles all of the validation and assigning is located in PS::Base and PS::Api.
it should look as follows:
def initialize
@apikey = nil
@userkey = nil
@company_name = nil
@env = "production"
end ###Require Public Methods
In order to have requests to be make successfully, and for responses to be handled properly; we require 3 public methods be available in the format class.
The first of those three methods is request. This is the method that will actually make the request to the appropriate paysimple api. This method should take two arguments: method and params. Method is the actual paysimple method we want to call, and params is the parameters to that method.
Before the parameters make it to the format class they are converted to camel case, as paysimple expects, but other formatting concerns should be handled in the format class as they are going to be format specific (see Paysimple V3 (error filled) documentation ). See the Json format for an example concerning date formatting.
The expected output of request is the parsed response. That is to say convert from the format to a hash. If using HTTParty then just using #parsed_response should be enough to coerce it into the correct format.
This method detects if the value of an attribute returned by paysimple is a date. They have different date formats for the different format apis. see the documentation for that date format. If it's a date return true, else false.
This method will only be called if date?() returns true. This parses the format class' particular date format into a Time object, and returns it.