Orders and Partial Payments

I’m working on a patch for the Drupal Commerce Square Connect contrib module. The patch doesn’t currently handle payments for additional order items properly. Here’s the use case:

  • An order is created, and payment is processed successfully.
  • The order is edited by adding a new item is added to the order.
  • Payment is submitted for the new item that’s been added to the order.

The issue is that the list of processed order items in the Commerce module includes all items associated with the order, not just the added item, and the payment amount is only for the new payment. As a result, the order cost (for all items) and the amount paid (for only the new item) are inconsistent, and Square rejects the payment.

Is there a way to submit a partial or update payment to Square?

Are you calling UpdatePayment for the original payment or are you looking to process and entirely new payment with the updated order_id?

The process for this would be CreateOrder and CreatePayment with autocomplete set to false. That will get you the authorized payment. You’ll then need to check the capabilities:

"capabilities": [
            "EDIT_AMOUNT_UP",
            "EDIT_AMOUNT_DOWN",
            "EDIT_TIP_AMOUNT_UP",
            "EDIT_TIP_AMOUNT_DOWN"
        ]

If you can edit the amount then you can UpdateOrder with any new items and then call UpdatePayment with the new net_amount_due_money and call CompletePayment to fully complete the payment.

If your not able to edit the amount then you’ll need to process an new payment for the outstanding amount with the same order_id. Once that payment is authorized you’ll then call PayOrder to complete that payments. :slightly_smiling_face:

Thanks for the reply! From the Drupal Commerce perspective, this would be a new, additional payment to an existing order which has had a new item added to it. Like this:

Original order #123:
Apple: $1
Orange: $1
Total payment: $2

Add “Pear” to original order $123:
Apple: $1 (already paid)
Orange: $1 (already paid)
Pear: $1 (unpaid)
Total payment: $1

Final order #123:
Apple: $1
Orange: $1
Pear: $1
Total paid: $3

Are you saying that the calls to CreateOrder and CreatePayment with autocomplete set to false would need to be done when the original order is processed, or when the order is processed to add the new item? Are any PHP code samples available?

Yes, the call to CreatePayment with autocomplete set to false would need to be done when the original order is processed. Orders with COMPLETED payments can’t add additional line items to them.

Unfortunately, we don’t have any PHP samples of this but it would be the following:

  • CreateOrder with original items.
  • CreatePayment with order_id and autocomplete set to false
  • UpdateOrder with new item
  • CreatePayment with original order_id for additional amount owed
  • When ready to complete the payment call PayOrder with the payment_ids for the additional payments on the order

Please note since the order has autocomplete false the order won’t be visible in the Dashboard or POS till PayOrder has been called with the payment_ids. Once PayOrder is called the order is no longer able to be updated. :slightly_smiling_face:

Thanks, I don’t think this approach will work for my application. The original order is commonly paid in full before a new item is added. What usually happens is that a customer wants to add an item after they’ve placed and paid for their order. That being the case, I imagine the best way to do this is to create a new order, and a new payment, for submission to Square - correct?

Yes, that’s correct since tendered orders with a COMPLETED payment can’t be updated with additional line items. We’re constantly working to improve our features based on feedback like this, so I’ll be sure to share your request to the API product team. :slightly_smiling_face: