I have been reading through the issue queue, the code and documentation and I'm quite confused about adding a payment form, either custom or standalone.

I am looking to add a form to allow admins to account for payments received offline, unassociated to specific purchasable entities. Is this possible?

To summarise, I looked at "Writing a Context" documentation.

To create a payment form, it's easiest to create your own custom form and use payment_form_embedded() directly to get the core payment form elements, or to display payment_form_standalone() by calling drupal_get_form('payment_form_standalone'), which calls payment_form_embedded() for you.

I created a module with the following:

 /**
 * Implements hook_menu.
 */
function payment_management_menu() {
  $items['admin/config/services/payment/add'] = array(
    'title' => 'Add Payment',
    'description' => 'Form to add a custom payment',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('payment_management_payment_add'),
    'access arguments' => array('administer payment configuration'),
  );

  return $items;
}

/**
 * Custom form for adding payments.
 */
function payment_management_payment_add() {
  return drupal_get_form('payment_form_standalone');
}

I get the error:

Recoverable fatal error: Argument 3 passed to payment_form_standalone() must be an instance of Payment, none given in payment_form_standalone()

I have tried the "Add a new Payment" field method, but I would prefer to have a stand alone form untied to an entity via a payment field. I also cannot edit the "Account" value using this method, ideally this would be editable on the form I want to present the admins.

There are multiple issues relating to this, which I added as related issues, but I cannot find a desirable solution or currently recommended method for this presumably common use case. If this exists in the documentation as stated in #2165269-5: Provide "add" form for payments, could you please provide a direct link to the part of the documentation, or an example of this in action.

Thanks in advance.

CommentFileSizeAuthor
#2 payment-edit-form.png49.07 KBmccrodp
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Xano’s picture

Version: 7.x-1.14 » 7.x-1.x-dev
Status: Active » Postponed (maintainer needs more info)

I get the error:

Recoverable fatal error: Argument 3 passed to payment_form_standalone() must be an instance of Payment, none given in payment_form_standalone()

That means you have to create a Payment object that you pass on to the form.

I have tried the "Add a new Payment" field method, but I would prefer to have a stand alone form untied to an entity via a payment field.

Do you mean one of the fields that is shipped with Payment? If so, please refer to functionality using the official names so people know what you mean.

I also cannot edit the "Account" value using this method, ideally this would be editable on the form I want to present the admins.

Why not? How do you edit it, and what happens when you do?

mccrodp’s picture

FileSize
49.07 KB

That means you have to create a Payment object that you pass on to the form.

Ok, thanks. I thought so from code, but was hoping there was an easier way. Is there an example of this in code or documentation, aside from the Test module?

Do you mean one of the fields that is shipped with Payment? If so, please refer to functionality using the official names so people know what you mean.

Yes, the payment reference field method bundled with the module that provides the string "Add a new Payment".

Why not? How do you edit it, and what happens when you do?

Was just editing the payment with "basic" payment methods. I think it is as designed then, the payment "Amount" value is not editable from the payment/ID/edit form. I think I expected to be able to edit the payment amount here, but I imagine it is not possible when using these "payment reference" field methods at least. i.e. - the payment reference field amount was defined as 20 in the attached image and it cannot be changed per payment on this edit form.

I think I will use a separate custom receipt (node) entity for offline payments and reference the payment entity for on-site payments taken with the payment module. It seems non-standard or at least quite custom to achieve what I am attempting with this module. Trying to write as little custom code as possible. Thanks.

Xano’s picture

Ok, thanks. I thought so from code, but was hoping there was an easier way. Is there an example of this in code or documentation, aside from the Test module?

Look for instantiations of the Payment class, and usages of payment_form_embedded() and payment_form_standalone().

Xano’s picture

Status: Postponed (maintainer needs more info) » Fixed
mccrodp’s picture

Thanks for your support with this, sorry for delayed response. I'm sure this info will be useful to others as this question appears a lot.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.