Class: Shipay::OrderCommom

Inherits:
Model show all
Defined in:
lib/shipay/order_commom.rb

Direct Known Subclasses

Order, OrderBacen, OrderV

Constant Summary

Constants inherited from ShipayObject

ShipayObject::RESOURCES

Instance Attribute Summary

Attributes inherited from ShipayObject

#attributes

Instance Method Summary collapse

Methods inherited from Model

class_name, #class_name, #create, create, #fetch, find_by_id, #save, underscored_class_name, url, #url

Methods inherited from ShipayObject

#==, #[]=, convert, #empty?, #initialize, #respond_to?, #to_hash, #unsaved_attributes

Constructor Details

This class inherits a constructor from Shipay::ShipayObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Shipay::ShipayObject

Instance Method Details

#cancelOrder

Request order Cancel to Shipay api

Returns:

  • (Order)

    Return model order instance



39
40
41
42
# File 'lib/shipay/order_commom.rb', line 39

def cancel()
  update Shipay::Request.delete(url_delete, client_key: @client_key).call(underscored_class_name)
  self
end

#primary_keyString

Defines primary key for model

Returns:

  • (String)

    Return the primary_key field value



26
27
28
# File 'lib/shipay/order_commom.rb', line 26

def primary_key
  order_id
end

#refund(params = {}) ⇒ Order

Request refund to Shipay api for this order

Examples:

Refund 1.0 from order

order_instance.refund(amount: 1.0)

Parameters:

  • params (Hash) (defaults to: {})

    Parameters for function

Options Hash (params):

  • :amount (Numeric) — default: Required

    The amount that will be refunded in float format

Returns:

  • (Order)

    Return model order instance

Raises:



16
17
18
19
20
# File 'lib/shipay/order_commom.rb', line 16

def refund(params={})
  raise ParamError.new("Missing ammount param", :amount, :float, url('refund')) unless params.has_key? :amount
  update Shipay::Request.delete(url_delete('refund'), params: params.merge(client_key: @client_key)).call(underscored_class_name)
  self
end

#url_delete(*params) ⇒ Object

Raises:



30
31
32
33
# File 'lib/shipay/order_commom.rb', line 30

def url_delete(*params)
  raise RequestError.new('Invalid ID') unless primary_key.present?
  ["/order", CGI.escape(primary_key.to_s), *params].join('/')
end