Hallo liebe Community,
ich würde wieder Profiunterstützung von euch benötigen, da ich bei dem oben genannten Vorhaben etwas anstehe.
Ich habe eine bereits funktionierende Payment API Anbindung, möchte jedoch die Provider wechseln.
Dazu muss ich eine neue Gateway hinzufügen. Ich habe zwar eine englische Beschreibung, jedoch stehe irgendwie auf der Leitung.
Hier die Anleitung zur Einbindung:
ich würde wieder Profiunterstützung von euch benötigen, da ich bei dem oben genannten Vorhaben etwas anstehe.
Ich habe eine bereits funktionierende Payment API Anbindung, möchte jedoch die Provider wechseln.
Dazu muss ich eine neue Gateway hinzufügen. Ich habe zwar eine englische Beschreibung, jedoch stehe irgendwie auf der Leitung.
Hier die Anleitung zur Einbindung:
PHP-Code:
Overview
The Payment API attempts to provide a unified way of integration with different payment gateways.
The API provides an abstract definition of payment gateway API, this means it will not implement specific processing workflow – this is achieved by extending it.
The API consists of:
Library
API allowing you to extend the functionality of the library
Types of integrations
Gateway Integration – all communication is done between SoftwareABC5 web server and gateway, customer enters CC information on SoftwareABC5.
Hosted Page – all payment (addresses, items) information transferred to gateway and transaction is completed there
Workflow
Create a new php gateway class using the examples in this document
Code any custom functionality required by payment gateway
Place the class in the gateway folder
Open the admin and configure and enable offers for the new payment option
As an example, consider a typical payment gateway. You might need to:
set up a merchant ID and a password
add custom product codes for each offer
request users to write down their phone number before purchasing tokens
All these can be accomplished with simple tasks:
specify the 2 fields, one for merchant ID, one for the password in the generateAdminForm() metdod; they will automatically show up in admin edit screen
specify the product code field in the generateAdminOffersForm() method; it will automatically show up in admin edit screen, for every system offer
specify the phone # field in the generatePaymentForm() method; it will automatically show up in front-end, on buy process page
Conventions
New gateways must extend the abstract gateway class:
SoftwareABC_Payment_Gateway
The naming convention require SoftwareABC_Payment_Gateway_prefix being added to all new gateway class names, followed by a capitalized name of the payment gateway:
SoftwareABC_Payment_Gateway_Demo
Files must be placed in the gateway folder, for example:
libs/
classes/
SoftwareABC/
payment/
gateway/
Demo.class.php
Epoch.class.php
<- add new class here
Following the convention will assure the new gateway automatically shows up in admin, where it can be enabled and set up. No more, and no less, is required.
The Gateway class
Now that we’ve discussed the minimum requirements for creating a new gateway and its structure, let’s discuss the minimum requirement: the Gateway class.
The gateway class, as noted previously, should exist in the gateway’s folder. Beyond that, however, there are no real requirements, other that, at a minimum, it mus implement the following structure:
class SoftwareABC_Payment_Gateway_Demo extends SoftwareABC_Payment_Gateway
{
protected $_gateway = 'Demo';
public function generateAdminForm()
{
}
public function generatePaymentForm()
{
}
public function generateAdminOffersForm()
{
}
public function processOrder()
{
}
public function processTransaction(array $response)
{
}
}
So, what do gateway classes do, then?
The gateway class fulfills three key purposes:
It generates forms, either for configuration or for payment
It processes an order
It processes a transaction
Forms
Most gateways require some sort of configuration and parameters to be passed to each request. This can be achieved by generating forms.
There are 4 types of form elements that can be generated, each of them supports labels, custom css class, custom id, a chain of validators and other few specific options such as rows for testareas. Below are exampled for each type.
Example of text input
// set options
$options = array(
'label' => 'Text Input',
'3' => 1,
'id' => 'txt1',
'class' => 'text',
'size' => 28,
'maxlength' => 24
);
// init element
$element = new SoftwareABC_Form_Element_Text('text', $options);
// get value, fallback to default
$value = $this->getOption('text', 'default text value');
// set value, required, validator
$element->setValue($value)
->setRequired(true)
->addValidator('alpha');
// add element
$this->getPaymentForm()->addElement($element);
Example of textarea
// set options
$options = array(
'label' => array('value'=>'Textarea', 'class'=>'textarea'),
'id' => 'textarea1',
'class' => 'text',
'rows' => 5,
'cols' => 20,
);
// init element
$element = new SoftwareABC_Form_Element_Textarea('textarea', $options);
// get value, fallback to default
$value = $this->getOption('textarea', 'default value for textarea');
// set value, required, validator
$element->setValue($value)
->setRequired(true)
->addValidator('alpha');
// add element
$this->getPaymentForm()->addElement($element);
Example of select box
// set options
$options = array(
'label' => array('value'=>'Select', 'class'=>'select'),
'id' => 'select1',
'class' => 'text',
'options' => array(10=>'Option 10', 20=>'Option 20'),
);
// init element
$element = new SoftwareABC_Form_Element_Select('select', $options);
// get value, fallback to default
$value = $this->getOption('select', 20);
// set value, required, validator
$element->setValue($value)
->setRequired(true)
->addValidator('numeric');
// add element
$this->getPaymentForm()->addElement($element);
Example of multi-select box
// set options
$options = array(
'label' => array('value'=>'Multi Select', 'class'=>'multiselect'),
'id' => 'multi1',
'class' => 'text',
'multiple' => true,
);
$opt = array(10=>'Option 10', 20=>'Option 20', 30=>'Option 30');
// init element
$element = new SoftwareABC_Form_Element_Multiselect('multiselect', $options);
// get value, fallback to default
$value = $this->getOption('multiselect', array(10, 30));
// set value, required, validator
$element->setValue($value)
->setRequired(true)
->addValidator('numeric')
->setMultiOptions($opt);
// add element
$this->getPaymentForm()->addElement($element);
Processing orders
Different gateways require different parameters for the order. The implementation can follow two distinct directions:
Compose a URL with gateway url and a list of parameters, then redirect to gateway url. The gateway will use a callback script (URL available in admin, edit gateway screen) to respond with the transaction details. Based on response, display ok/error message.
OR
Compose an array of parameters and call the gateway. Based on response, display ok/error message.
Processing transactions
Different gateways respond in specific formats after a transaction. Based on the validity of response source, of response parameters, display ok/error message.
Kommentar