Documentation here pertains to AWPCP 3.3.2 and higher.
Implementation Notes
All payment gateways should extend classAWPCP_PaymentGateway
and implement at least the four methods described below:
process_payment
: called when the payment gateway is about to be used in a transaction. This is the method used to render the payment buttons in PayPal or 2Checkout payment gateways, and the Billing Form in PayPal Pro Direct Payment or Authorize.Net.process_payment_notification
,process_payment_completed
andprocess_payment_canceled
: that are called when a notification is received for a transaction associated to the payment gateway, or when the user is redirected to thepayment-completed
andpayment-canceled
URLs.
Most payment gateways allow developers to specify a notify, return and cancel URL. Those are directly associated with theprocess_payment_notification
,process_payment_completed
andprocess_payment_canceled
methods above, respectively.
You can use the following code to generate the URLs mentioned above, for a given transaction,
$payments = awpcp_payments_api();
$notify_url = $payments->get_notify_url($transaction);
$return_url = $payments->get_return_url($transaction);
$cancel_url = $payments->get_cancel_url($transaction);
The plugin will handle those URLs automatically and will take care of calling the right method in each case.
The implementation of the methods varies depending on the kind of integration you are trying to develop.
- Integration by Payment Button (PayPal Standard or 2Checkout)
process_payment
: should print the payment button.process_payment_completed
: called when the user returns to your website from the payment gateway’s website, after having made a payment. The method should validate the information received and try to find out if the payment was successful or not, and update the transaction’s payment status. This is how PayPal Standard payment gateway works; seepayment-gateway-paypal-standard.php
.process_payment_canceled
: called when the user returns to your website after he or she cancelled the payment request. The method should update the payment status of the transaction.process_payment_notification
: called every time a notification is received for a transaction that used your payment gateway. Similar to whatprocess_payment_completed
does, this method has to verify the information received and figure out the new payment status and update the transaction accordingly.
After
process_payment_completed
orprocess_payment_canceled
have been called, the plugin continues handling the payment transaction and will let the user post the listing, if the payment was successful, or show him an error, if the payment failed. - Integration by Custom Form (Authorize.Net)
process_payment
: should print the billing form, but also takes care of precessing the data entered, contacting the payment gateway’s servers and consolidate the payment (update the transaction with a proper payment status).When you are done processing the payment, after you have updated the payment status of the transaction, callreturn awpcp_payments_api()->process_payment_completed($transaction);
to let the plugin continue handing the transaction and allow the user to post the listing (if the payment was successful).process_payment_completed
andprocess_payment_cancelled
are usually implemented without a body (just areturn;
line), because the user is never redirected during the payment transaction.- If the payment gateway supports notifications, the
process_payment_notification
method should be implemented as described in the Integration by Payment Button case.
Registering a payment gateway
Register an action for theawpcp-register-payment-methods
hook. The callback will receive an instance of thePayments_API
as its only argument. You should create an instance of your Payment Gateway and pass it to theregister_payment_method
method. For example:
public function register_payment_methods( $payments ) {
$payments->register_payment_method( new AWPCP_PayPalStandardPaymentGateway );
}