Sha256: 6607fb61c58bf54ac314ef4ea3e11fb52851f5b8f568f70c8db2d671100a901e

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

#
# Example 7 - How to refund a payment programmatically.
#
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_bt7vvByF6jTcBR4dLuW66eNnHYNIJp"

	#
	# Retrieve the payment you want to refund from the API.
	#
	payment = mollie.payments.get "tr_dO6CPyCfoK"

	#
	# Refund the payment.
	#
	refund = mollie.payments_refunds.with(payment).create

	$response.body << "The payment #{payment.id} is now refunded.<br>"

	#
	# Retrieve refunds on a payment.
	#
	refunds = mollie.payments_refunds.with(payment).all

	refunds.each { |refund|
		$response.body << '<br> Refund date: ' << (CGI.escapeHTML refund.refundedDatetime)
		$response.body << '<br> Refunded: &euro; ' << (CGI.escapeHTML refund.amountRefunded) 
		$response.body << '<br> Remaining: &euro; ' << (CGI.escapeHTML refund.amountRemaining)
		$response.body << '<br>'
	}
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.1.1 examples/7-refund-payment.rb