Class: Skrill::Payment

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/skrill/payment.rb,
lib/skrill/payment/utils.rb,
lib/skrill/payment/version.rb

Defined Under Namespace

Modules: Utils Classes: Configuration, Request

Constant Summary collapse

OPTIONS =
[:email, :amount, :identifier]
VERSION =
'0.3.' + (ENV['BUILD_VERSION'] || '0')

Instance Method Summary collapse

Methods included from Utils

#assign_attirbutes, #serialize_arguments

Constructor Details

#initialize(payment_data = {}) {|_self| ... } ⇒ Skrill::Payment

Prepares a new payment using the configuration attributes when provided and the payment attributes. The configuration attributes can be overwritten by using in the same Hash keys or methods. Attributes can be passed in by using a block or a Hash.

Examples:

Prepare a new payment using a block.

Skrill::Payment.new do |payee|
  payee.email = '[email protected]'
  payee.amount = 10.00
end

Prepare a new payment using a Hash.

Skrill::Payment.new(email: '[email protected]', amount:  10.00)

Yields:

  • (_self)

Yield Parameters:

Since:

  • 0.1.0



33
34
35
36
37
# File 'lib/skrill/payment.rb', line 33

def initialize(payment_data = {}, &block)
  assign_attirbutes(payment_data)

  yield(self) if block_given?
end

Instance Method Details

#deliverRequest

Sends a payment request to Skrill. Use the ‘successful?` method to check if the Skrill was able to process the payment successfully.

Returns:

  • (Request)

    The request object.

Since:

  • 0.1.0



45
46
47
# File 'lib/skrill/payment.rb', line 45

def deliver
  @request = Skrill::Payment::Request.post(config_data, payment_data)
end

#error_messageString?

Returns the error message from Skrill or nil when the payment was successful.

Returns:

  • (String, nil)

    The error message or nil.

Since:

  • 0.2.0



64
65
66
# File 'lib/skrill/payment.rb', line 64

def error_message
  @request.error_message
end

#successful?true, false

Checks if the payment has been delivered and was successful.

Returns:

  • (true, false)

    The payment success status.

Since:

  • 0.1.0



54
55
56
# File 'lib/skrill/payment.rb', line 54

def successful?
  !!@request && @request.successful?
end