I assume this should be possible, but it wasn't obvious how you might add pay form items to a completely custom form?

Are there any docs or examples around on this subject.

Comments

allie micka’s picture

Status: Active » Needs work

There's some documentation in the source code of pay.module, but I don't think that anyone has added it somewhere responsible, such as a handbook page (do i hear a volunteer?)

The code that generates a payment form "from scratch" is located in pay.module:pay_form().

<?php
/**
 * A simple form any type of pay element.
 * If you want to build a module with a standalone payment form, you would
 * do so by passing this function to the drupal_get_form page handler in your
 * hook_menu() funcion.
 *
 * Alternatively, you can manually add payment form capabilities by including
 * the code from this function in your form builder or form_alter code.
 */
function pay_form(&$form_state, $pay, $type = NULL, $form_type = 'default') {
...
?>

If adding pay-ness to a form of your own, you'd minimally implement the following 2 lines of code:

<?php
  // Load a $pay_form handler, which controls how a form looks and functions.  
  // Existing pay_form handlers include Donate or Webform Pay, or you can write your own by observing those modules.
  $pay_form = pay_form_load($handler_name_or_id_of_your_pay_form_instance);

  //  This function should do everything you need, augmenting your form with payment info, adding submit handlers, etc. 
  $pay_form->form($form, $form_state);
?>