Class: Safecharge::Request
- Inherits:
-
Object
- Object
- Safecharge::Request
- Defined in:
- lib/safecharge/request.rb
Constant Summary collapse
- ALLOWED_FIELDS =
{ 'currency' => {:required => true, :type => 'currency_code'}, 'customData' => {:required => false, :type => 'string', length: 255}, 'customSiteName' => {:required => false, :type => 'string', length: 50}, 'discount' => {:required => false, :type => 'currency'}, 'encoding' => {:required => false, :type => 'string', length: 20}, 'error_url' => {:required => false, :type => 'string', length: 300}, 'handling' => {:required => false, :type => 'currency'}, 'invoice_id' => {:required => false, :type => 'string', length: 400}, 'merchant_id' => {:required => true, :type => 'int'}, 'merchant_site_id' => {:required => true, :type => 'int'}, 'merchant_unique_id' => {:required => false, :type => 'string', length: 64}, 'merchantLocale' => {:required => false, :type => 'string', length: 5}, 'payment_method' => {:required => false, :type => 'string', length: 256}, 'pending_url' => {:required => false, :type => 'string', length: 300}, 'productId' => {:required => false, :type => 'string', length: 50}, 'shipping' => {:required => false, :type => 'currency'}, 'skip_billing_tab' => {:required => false, :type => 'boolstring'}, 'skip_review_tab' => {:required => false, :type => 'boolstring'}, 'success_url' => {:required => false, :type => 'string', length: 300}, 'total_amount' => {:required => true, :type => 'currency'}, 'total_tax' => {:required => false, :type => 'percent'}, 'userid' => {:required => false, :type => 'string', length: 50}, 'version' => {:required => true, :type => 'string', length: 10}, 'webMasterId' => {:required => false, :type => 'string', length: 255}, 'first_name' => {:required => false, :type => 'string', length: 30}, 'last_name' => {:required => false, :type => 'string', length: 40}, 'email' => {:required => false, :type => 'string', length: 100}, 'city' => {:required => false, :type => 'string', length: 30}, 'country' => {:required => false, :type => 'string', length: 20}, 'state' => {:required => false, :type => 'string', length: 20}, # ISO code 'zip' => {:required => false, :type => 'string', length: 10}, # post code 'address1' => {:required => false, :type => 'string', length: 60}, 'address2' => {:required => false, :type => 'string', length: 60}, 'phone1' => {:required => false, :type => 'string', length: 18}, 'phone2' => {:required => false, :type => 'string', length: 18}, 'phone3' => {:required => false, :type => 'string', length: 18} }
- ALLOWED_ITEM_FIELDS =
‘time_stamp’, ‘numberofitems’ and ‘checksum’ are inserted after validation.
{ 'name' => {:required => true, :type => 'string', length: 400}, 'number' => {:required => true, :type => 'string', length: 400}, 'amount' => {:required => true, :type => 'currency'}, 'quantity' => {:required => true, :type => 'int'}, 'discount' => {:required => false, :type => 'percent'}, 'shipping' => {:required => false, :type => 'currency'}, 'handling' => {:required => false, :type => 'currency'} }
- DEFAULT_PARAMS =
{ 'merchant_id' => Safecharge::Constants::MERCHANT_ID, 'merchant_site_id' => Safecharge::Constants::MERCHANT_SITE_ID, 'currency' => Safecharge::Constants::DEFAULT_CURRENCY_CODE, 'version' => Safecharge::Constants::API_VERSION, 'encoding' => Safecharge::Constants::DEFAULT_ENCODING }
Instance Attribute Summary collapse
-
#full_url ⇒ Object
Returns the value of attribute full_url.
-
#items ⇒ Object
Returns the value of attribute items.
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#params ⇒ Object
Returns the value of attribute params.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(a_url, some_params = {}) ⇒ Request
constructor
A new instance of Request.
Constructor Details
#initialize(a_url, some_params = {}) ⇒ Request
Returns a new instance of Request.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/safecharge/request.rb', line 70 def initialize(a_url, some_params = {}) raise ArgumentError, "missing url" if a_url == nil || a_url.empty? if a_url === Safecharge::Constants::SERVER_TEST self.mode = 'test' elsif a_url === Safecharge::Constants::SERVER_LIVE self.mode = 'live' else raise ArgumentError, "invalid url #{a_url}" end self.url = a_url self.full_url = a_url core_params, items, extracted_items = self.extract_items(convert_symbols_to_strings(some_params)) raise ValidationException, "Missing array of Items." if items == nil || items.empty? self.items = items self.params = DEFAULT_PARAMS.merge(core_params) self.validate_parameters(self.params) items.each {|i| self.validate_parameters(i, self.class::ALLOWED_ITEM_FIELDS)} self.params.merge!(extracted_items) self.params.merge!({'numberofitems' => items.size, 'time_stamp' => Time.now.utc.strftime("%Y-%m-%d.%H:%M:%S")}) self.params.merge!({'checksum' => calculate_checksum}) # must happen after the previous merge! self.construct_url end |
Instance Attribute Details
#full_url ⇒ Object
Returns the value of attribute full_url.
9 10 11 |
# File 'lib/safecharge/request.rb', line 9 def full_url @full_url end |
#items ⇒ Object
Returns the value of attribute items.
9 10 11 |
# File 'lib/safecharge/request.rb', line 9 def items @items end |
#mode ⇒ Object
Returns the value of attribute mode.
9 10 11 |
# File 'lib/safecharge/request.rb', line 9 def mode @mode end |
#params ⇒ Object
Returns the value of attribute params.
9 10 11 |
# File 'lib/safecharge/request.rb', line 9 def params @params end |
#url ⇒ Object
Returns the value of attribute url.
9 10 11 |
# File 'lib/safecharge/request.rb', line 9 def url @url end |