Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagephp
class MyGateway extends NonmerchantGateway {
...
	public function getName() {
		return Language::_("MyGateway.name", true);
	}
...
}

...

getVersion()

The getDescription() method simply returns the description This method must return the current version number of the gateway. It's always best to define any language in your gateway using language files (see Translating Blesta for more information)Upon installation or upgrade, Blesta records the current code version so that it can tell when an upgrade/downgrade is available. The version number should be compatible with PHP's version_compare() function.

Info

This method was added in Blesta v4.9.0 and can be defined in a gateway configuration file instead.

...

Code Block
languagephp
class MyGateway extends NonmerchantGateway {
	const VERSION = "1.0.0";	
...
	public function getDescriptiongetVersion() {
		return Languageself::_("MyGateway.description", true)VERSION;
	}
...

}

...

getAuthors()

This method must return the current version number returns an array containing information about the authors of the gateway. Upon installation or upgrade, Blesta records the current code version so that it can tell when an upgrade/downgrade is available. The version number should be compatible with PHP's version_compare() function.

Info

This method can be defined in a gateway configuration file instead.

...

Code Block
languagephp
class MyGateway extends NonmerchantGateway {
	const VERSION = "1.0.0";	  private static $authors = array(array('name' => "Phillips Data, Inc.", 'url' =>"http://www.blesta.com"));
...
	public function getVersiongetAuthors() {
		return self::VERSION$authors;
	}
...

}

...

getCurrencies()

This method returns an array containing information about the authors of the gatewaya set of all currencies supported by the gateway. Each currency should follow the ISO 4217 format for 3-character currency codes.

Info

This method can be defined in a gateway configuration file instead.

...

Code Block
languagephp
class MyGateway extends NonmerchantGateway {
...
	public function getCurrencies()  private static $authors = array(array('name' => "Phillips Data, Inc.", 'url' =>"http://www.blesta.com"));
...
	public function getAuthors() {
		return self::$authors;
	{
		return array("AUD", "GBP", "USD");
	}
...
}

...

setCurrency()

This method returns an array containing a set of all currencies supported by the gateway. Each currency should follow the ISO 4217 format for 3-character currency codes.

Info

This method can be defined in a gateway configuration file instead.

sets the currency to be used for subsequent payments.

Code Block
languagephp
class MyGateway extends NonmerchantGateway {
...
	public function getCurrenciessetCurrency() {
		return array("AUD", "GBP", "USD");$this->currency = $currency;
	}
...
}

...

getSettings(array $meta=null)

This method sets the currency to be used for subsequent payments.returns HTML content for the gateway's management page. The management page usually consists of form fields where API credentials can be entered. A set of existing $meta data may be given in order to pre-populate the form fields with data already saved for the gateway.

Code Block
languagephp
Code Block
languagephp
class MyGateway extends NonmerchantGateway {
...
	public function setCurrencygetSettings(array $meta=null) {
		$this->currency = $currency;
	}
...
}

...

editSettings(array $meta

...

)

This method returns HTML content validates and returns data to be saved for the gateway's management page. The management page . This data usually consists of form fields where API credentials can be entered. A set of existing $meta data may be given in order to pre-populate the form fields with data already saved for the gatewaynecessary for processing payments through the gateway. The $meta fields to validate consist of those defined from getSettings().

Code Block
languagephp
class MyGateway extends NonmerchantGateway {
...
	public function getSettingseditSettings(array $meta=null) {
		$this->currency = $currency;
	}
...
}

editSettings(array $meta)

This method validates and returns data to be saved for the gateway. This data usually consists of API credentials necessary for processing payments through the gateway. The $meta fields to validate consist of those defined from getSettings().

Code Block
languagephp
class MyGateway extends NonmerchantGateway {
...
	public function editSettings(array $meta) {
		// Define any rules necessary to validate the meta data given is valid and usable
		$rules = array(
			'account_email' => array(
				'// Define any rules necessary to validate the meta data given is valid and usable
		$rules = array(
			'account_email' => array(
				'valid' => array(
					'rule' => "isEmail",
					'message' => Language::_("MyGateway.!error.account_email.valid", true)
				)
			),
			'password' => array(
				'empty' => array(
					'rule' => "isEmpty",
					'negate' => true,
					'message' => Language::_("MyGateway.!error.password.empty", true)
				)
			)
		);

		// Set the rules to validate the $meta data against
		$this->Input->setRules($rules);

		// Validate whether the data given is valid
		$this->Input->validates($meta);

		// Return the meta data given
		return $meta;
	}
...
}

...

Code Block
languagephp
class MyGateway extends NonmerchantGateway {
...
	public function buildProcess(array $contact_info, $amount, array $invoice_amounts=null, array $options=null) {
		// Fetch the view template that renders the fields from the gateway's "process.pdt" template
		$this->view = $this->makeView("process", "default", str_replace(ROOTWEBDIR, "", dirname(__FILE__) . DS));

        // Load the helpers required for this view        
        Loader::loadHelpers($this, array("Form", "Html"));

        $fields = array();
        $post_to = "";

        #
        # TODO: Define all form fields and the $post_to fields
        #        
        $this->view->set("post_to", $post_to);
        $this->view->set("fields", $fields);

		return $this->view->fetch();
	}
...
}

buildAuthorize(array $contact_info, $amount, array $invoice_amounts=null, array $options=null)

This method is very similar to buildProcess(). It returns HTML content for the payment page from which a client can authorize a payment. Authorized payments are not completed until they are captured later.

capture($reference_id, $transaction_id, $amount, array $invoice_amounts=null)

This method is currently unused.

Code Block
languagephp
class MyGateway extends   #
        # TODO: Define all form fields and the $post_to fields
        #        
        $this->view->set("post_to", $post_to);NonmerchantGateway {
...
	public function capture($reference_id, $transaction_id, $amount, array $invoice_amounts=null) {
		// Method is unsupported
		if (isset($this->Input))
        $this->view->set("fields", $fields);

		return $this->view->fetch(    $this->Input->setErrors($this->getCommonError("unsupported"));
	}
...
}

buildAuthorize(array $contact_info, $amount, array $invoice_amounts=null, array $options=null)

...

.

...

.

...

.
}

void

...

($reference_id, $transaction_id,

...

$notes=null)

This method voids a payment transaction with the gateway. If voiding a payment is not supported by the gateway, and is not defined, the common "unsupported" error is set insteadThis method is currently unused.

Code Block
languagephp
class MyGateway extends NonmerchantGateway {
...
	public function capturevoid($reference_id, $transaction_id, $amount, array $invoice_amounts$notes=null) {
		// Method is unsupported
		if (isset($this->Input))
            $this->Input->setErrors($this->getCommonError("unsupported"));
	}
...
}

...

refund($reference_id, $transaction_id, $amount, $notes=null)

This method voids refunds a payment transaction with the gateway. If voiding refunding a payment is not supported by the gateway, and is not defined, the common "unsupported" error is set instead.

Code Block
languagephp
class MyGateway extends NonmerchantGateway {
...
	public function voidrefund($reference_id, $transaction_id, $amount, $notes=null) {
		// Method is unsupported
		if (isset($this->Input))
            $this->Input->setErrors($this->getCommonError("unsupported"));
	}
...
}

...

install()

This method refunds a payment transaction with is invoked when the gateway . If refunding a payment is not supported by the gateway, and is not defined, the common "unsupported" error is set insteadis installed to perform any installation logic. For example, if the gateway requires any dependencies, you could check that those dependencies are met before the gateway is installed. If the gateway should not be installed, set Input errors.

Code Block
languagephp
class MyGateway extends NonmerchantGateway {
...
	public function refund($reference_id, $transaction_id, $amount, $notes=null) {
		// Method is unsupported
		if (isset($this->Input))
            $this->Input->setErrors($this->getCommonError("unsupported"));install() {
		// Nothing to do
	}
...
}

...

upgrade($current_version)

This method is invoked when the gateway is installed to perform any installation logic. For example, if the gateway requires any dependencies, you could check that those dependencies are met before the gateway is installed. If the gateway should not be installed, set Input errorsupgraded from one version to another. Any gateway upgrade logic between versions can be performed here.

Code Block
languagephp
class MyGateway extends NonmerchantGateway {
...
	public function installupgrade($current_version) {
		// Nothing to do
	}
...
}

...

uninstall($gateway_id, $last_instance)

This method is invoked when the gateway is upgraded from one version to anotheruninstalled from a company. Any gateway upgrade cleanup logic between versions can be performed here.

Code Block
languagephp
class MyGateway extends NonmerchantGateway {
...
	public function upgrade($current_version uninstall($gateway_id, $last_instance) {
		// Nothing to do
	}
...
}

uninstall($gateway_id, $last_instance)

...

getDescription()

The getDescription() method simply returns the description of the gateway. It's always best to define any language in your gateway using language files (see Translating Blesta for more information).

Info

This method was added in Blesta v4.9.0 and can be defined in a gateway configuration file instead.


Code Block
languagephp
class MyGateway extends NonmerchantGateway {
...
	public function uninstall($gateway_id, $last_instancegetDescription() {
		// Nothing to doreturn Language::_("MyGateway.description", true);
	}
...
}

getLogo()

This method returns the relative path from the gateway's directory to the logo image. If not defined, the logo set in the configuration file will be used, or the logo file at views/default/images/logo.png.

...