Sha256: eaa126967df12b52eb9b14a420acaaa1b5a2c5facb7cb5a982d09cc855f20d74

Contents?: true

Size: 1.71 KB

Versions: 10

Compression:

Stored size: 1.71 KB

Contents

#
# Example 1 - How to prepare a new payment with the Mollie API.
#
require File.expand_path "../lib/Mollie/API/Client", File.dirname(__FILE__)

begin
  #
  # Initialize the Mollie API library with your API key.
  #
  # See: https://www.mollie.nl/beheer/account/profielen/
  #
  mollie = Mollie::API::Client.new
  mollie.setApiKey "test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM"

  #
  # Generate a unique order id for this example. It is important to include this unique attribute
  # in the redirectUrl (below) so a proper return page can be shown to the customer.
  #
  order_id = Time.now.to_i

  #
  # Determine the url parts to these example files.
  #
  protocol = $request.secure? && "https" || "http"
  hostname = $request.host || "localhost"
  port     = $request.port || 80
  path     = $request.script_name || ""

  #
  # Payment parameters:
  #   amount        Amount in EUROs. This example creates a € 10,- payment.
  #   description   Description of the payment.
  #   redirectUrl   Redirect location. The customer will be redirected there after the payment.
  #   metadata      Custom metadata that is stored with the payment.
  #
  payment = mollie.payments.create \
    :amount       => 10.00,
    :description  => "My first API payment",
    :redirectUrl  => "#{protocol}://#{hostname}:#{port}#{path}/3-return-page?order_id=#{order_id}",
    :metadata     => {
      :order_id => order_id
    }

  #
  # In this example we store the order with its payment status in a database.
  #
  database_write order_id, payment.status

  #
  # Send the customer off to complete the payment.
  #
  $response.redirect payment.getPaymentUrl
rescue Mollie::API::Exception => e
  $response.body << "API call failed: " << (CGI.escapeHTML e.message)
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
mollie-api-ruby-1.4.2 examples/1-new-payment.rb
mollie-api-ruby-1.4.1 examples/1-new-payment.rb
mollie-api-ruby-1.4.0 examples/1-new-payment.rb
mollie-api-ruby-1.3.0 examples/1-new-payment.rb
mollie-api-ruby-1.2.2 examples/1-new-payment.rb
mollie-api-ruby-1.2.1 examples/1-new-payment.rb
mollie-api-ruby-1.2.0 examples/1-new-payment.rb
mollie-api-ruby-1.1.5 examples/1-new-payment.rb
mollie-api-ruby-1.1.4 examples/1-new-payment.rb
mollie-api-ruby-1.1.3 examples/1-new-payment.rb