There are two broad categories of payment methods enabled by the payment system out of the box: on-site payment and off-site payment. On-site payment is either processed via a third party web service using data collected through a checkout or administration form or simply entails presenting payment information to the customer for them to remit payment offline upon checkout completion. Off-site payment is enabled through a redirect from the Payment checkout page to the payment service, with customers ideally being returned back to the Payment page upon success or failure so they can be moved forward or backward in the checkout process as the case may require. Because off-site payment often requires direct customer input (such as a username and password), it is not normally possible to enact this type of payment through the administration form.
Payment gateways tend to offer multiple types of payment services, often providing on-site and off-site options. Each service should be represented by a different payment method in Drupal Commerce. Using PayPal as an example, this means the Commerce PayPal project will include modules defining their services a separate payment methods, including PayPal WPS (off-site service), WPP (on-site service), and EC (a mixture between off-site and on-site). When a payment method module is enabled, a default payment method rule will be defined that you can use to configure settings for your payment methods. During the checkout process, all the active payment method rules will be evaluated and given a chance to enable their respective payment methods for use on the checkout form. You can actually use more than one rule to enable any given payment method using a different set of API credentials or transaction settings based on conditions of the order being paid for. The important thing to ensure is that no payment method is enabled by more than one rule.
The Payment module includes functions designed to support common types of payment services, the most common being credit card payments. The file commerce_payment.credit_card.inc includes helper functions for building and validating credit card forms and data. Payment method modules integrating with credit card processing services should use these functions and can use the Commerce Authorize.Net project as an example for the integration.
Whenever a payment is attempted, a payment transaction should be created that references the order for which payment was attempted. This includes transaction attempts that failed, that require further action, or were processed successfully as reflected in the transaction's status: Failure, Pending, Success. The transaction functions as a log indicating while a payment failed or a basic receipt for successful payments. The initial amount of the transaction should be the requested payment or authorization amount, but if this changes prior to completion (such as performing a prior authorization capture for a different amount than was originally authorized), the transaction should be updated to reflect the final amount of money collected. The sum of all successful payment transactions is used to track the outstanding balance on an order.
It is quite likely that additional actions may be available to be performed on payment transactions. These include things like voiding transactions, applying a credit to the account, or performing a prior authorization capture. All such functions should be accessible from the "Operations" column of an order's Payment tab. Links appear in this column through the use of Drupal's contextual link system as demonstrated by the Commerce Authorize.Net module for prior authorization captures of authorization only transactions. Depending on the nature of the operation, you will either update the transaction (e.g. update its amount and status after capture) or create a new transaction (e.g. creating a new transaction with a negative amount to reflect a credit).
The responsibilities of a payment method module include the following main points:
For more information and examples of these, refer to the Payment info hook documentation and the proof-of-concept modules Commerce Authorize.Net and Commerce PayPal. Refer to the payment method FAQ for other modules that are developed or in development supporting different types of payment services and representing different countries.
When a user is directed off-site to submit payment, their order remains in the Checkout: Payment status that by default is not designated as a shopping cart order status. This means if the user presses the browser back button to return to your site instead of the appropriate link on the page, they will arrive at an inappropriate checkout page for their order status and in fact may no longer have their order recognized by the checkout process. The order is locked down to prevent manipulations to the order in a separate tab while payment is potentially being submitted.
Additionally, most off-site payment methods will return the user to your site via a POST that includes some basic payment information, such as whether or not the payment succeeded or failed and what the actual payment amount was. You should not depend on this information to actually create and update payment transactions, though this information may be used to progress through the checkout process. This is to mitigate the risk of simulated payment completion being logged in the database as actual payments, even if the scammer ends up seeing the checkout completion page after attempting to scam the site. This is why we make the "When an order is first paid in full" event available for use alongside the "Customer completes checkout" event. Sites relying on off-site payment methods (and sites using authorization only transactions with delayed capture after the fact) should use the "When an order is first paid in full" event to perform business logic that is dependent on actual payment and not just the appearance of checkout completion.
For off-site payment methods, payment transactions should be created and updated based on secure notification from the payment gateway, such as PayPal's Instant Payment Notifications (IPN). These notifications should be properly validated according to the payment gateway's specification, and upon validation, payment transactions can be created associated with the order in question or updated as necessary.
The two API functions are:
To see an example of these functions implemented by an off-site payment method module, refer to the function commerce_paypal_wps_paypal_ipn_process() in the commerce_wps.module of the Commerce PayPal module.
Found errors? Think you can improve this documentation? edit this page