Sha256: 64036ee0de8f4ee51380c8789972f614be5bb82125dbfc0ba12be19969e87dae

Contents?: true

Size: 1.64 KB

Versions: 1

Compression:

Stored size: 1.64 KB

Contents

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

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

1 entries across 1 versions & 1 rubygems

Version Path
mollie-api-ruby-1.0.1 examples/1-new-payment.rb