Sha256: 79a29670880d1375f8f89794f6117bfa02afca9625a0a993c63eec341eddef0e
Contents?: true
Size: 1.47 KB
Versions: 6
Compression:
Stored size: 1.47 KB
Contents
module SlidePay class Payment < ApiResource URL_ROOT = "payment" ID_ATTRIBUTE = "payment_id" def initialize(values_hash={}) @id_attribute = "payment_id" @url_root = "payment" super(values_hash) end def save(options_hash={}) process(options_hash) end def destroy(options_hash={}) refund(options_hash) end def process(options_hash={}) token = @token || options_hash[:token] api_key = @api_key || options_hash[:api_key] endpoint = @endpoint || options_hash[:endpoint] response = SlidePay.post(path: "payment/simple", api_key: api_key, token: token, endpoint: endpoint, data: self.to_json) if response.was_successful? self["payment_id"] = response.data["payment_id"] self["order_master_id"] = response.data["order_master_id"] true elsif response.error_text raise Exception.new(response.error_text) elsif response.data["status_message"] raise Exception.new(response.data["status_message"]) else raise Exception.new("Payment could not be processed.") end end def refund(options_hash={}) token = @token || options_hash[:token] api_key = @api_key || options_hash[:api_key] endpoint = @endpoint || options_hash[:endpoint] response = SlidePay.post(path: "payment/refund/#{self.id()}", api_key: api_key, token: token, endpoint: endpoint, data: self.to_json) response.was_successful? end end end
Version data entries
6 entries across 6 versions & 1 rubygems