Skip to content
Snippets Groups Projects

Formatting improvements and add code comments on Order API + fix broken URL

Created by: artfulrobot

  • Fix broken link to dev/financial#73 (closed)
  • Use // for single line comments (isn't # deprecated? or is that just in .ini files?)
  • Add whitespace and comments around migration from transact code.
  • Wrap code example lines so they display properly

Merge request reports

Approval is optional

Merged by avatar (Apr 21, 2025 3:54pm UTC)

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
351 353 }
352 354 $order = civicrm_api3('Order', 'create' $params);
353 355 try {
356 // Use the Payment Processor to attempt to take the actual payment. You may
357 // pass in other params here, too.
354 358 civicrm_api3('PaymentProcessor', 'pay', ['contribution_id' => $order['id']]);
355 civicrm_api3('Payment', 'create', ['contribution_id' => $order['id'], 'amount' => $params['amount']]);
359
360 // Assuming the payment was taken, record it which will mark the Contribution
361 // as Completed and update related entities.
362 civicrm_api3('Payment', 'create', [
363 'contribution_id' => $order['id'],
364 'total_amount' => $params['amount'],
  • Created by: eileenmcnaughton

    I've realised we could probably deprecate not passing paymen_processor_id or payment_instrument_id in here - perhaps we should add that to the example

  • homotechsual
    homotechsual @homotechsual started a thread on commit 92f5cf20
  • 351 353 }
    352 354 $order = civicrm_api3('Order', 'create' $params);
    353 355 try {
    356 // Use the Payment Processor to attempt to take the actual payment. You may
    357 // pass in other params here, too.
    354 358 civicrm_api3('PaymentProcessor', 'pay', ['contribution_id' => $order['id']]);
    355 civicrm_api3('Payment', 'create', ['contribution_id' => $order['id'], 'amount' => $params['amount']]);
    359
    360 // Assuming the payment was taken, record it which will mark the Contribution
    361 // as Completed and update related entities.
    362 civicrm_api3('Payment', 'create', [
    363 'contribution_id' => $order['id'],
    364 'total_amount' => $params['amount'],
  • homotechsual
    homotechsual @homotechsual started a thread on commit 92f5cf20
  • 351 353 }
    352 354 $order = civicrm_api3('Order', 'create' $params);
    353 355 try {
    356 // Use the Payment Processor to attempt to take the actual payment. You may
    357 // pass in other params here, too.
    354 358 civicrm_api3('PaymentProcessor', 'pay', ['contribution_id' => $order['id']]);
    355 civicrm_api3('Payment', 'create', ['contribution_id' => $order['id'], 'amount' => $params['amount']]);
    359
    360 // Assuming the payment was taken, record it which will mark the Contribution
    361 // as Completed and update related entities.
    362 civicrm_api3('Payment', 'create', [
    363 'contribution_id' => $order['id'],
    364 'total_amount' => $params['amount'],
  • homotechsual
    homotechsual @homotechsual started a thread on commit 92f5cf20
  • 351 353 }
    352 354 $order = civicrm_api3('Order', 'create' $params);
    353 355 try {
    356 // Use the Payment Processor to attempt to take the actual payment. You may
    357 // pass in other params here, too.
    354 358 civicrm_api3('PaymentProcessor', 'pay', ['contribution_id' => $order['id']]);
    355 civicrm_api3('Payment', 'create', ['contribution_id' => $order['id'], 'amount' => $params['amount']]);
    359
    360 // Assuming the payment was taken, record it which will mark the Contribution
    361 // as Completed and update related entities.
    362 civicrm_api3('Payment', 'create', [
    363 'contribution_id' => $order['id'],
    364 'total_amount' => $params['amount'],
    • Created by: eileenmcnaughton

      but yes - I think we can't really add payments without knowing what sort of payments they are without too much magic & payment method should be known when creating a payment

  • homotechsual
    homotechsual @homotechsual started a thread on commit 92f5cf20
  • 351 353 }
    352 354 $order = civicrm_api3('Order', 'create' $params);
    353 355 try {
    356 // Use the Payment Processor to attempt to take the actual payment. You may
    357 // pass in other params here, too.
    354 358 civicrm_api3('PaymentProcessor', 'pay', ['contribution_id' => $order['id']]);
    355 civicrm_api3('Payment', 'create', ['contribution_id' => $order['id'], 'amount' => $params['amount']]);
    359
    360 // Assuming the payment was taken, record it which will mark the Contribution
    361 // as Completed and update related entities.
    362 civicrm_api3('Payment', 'create', [
    363 'contribution_id' => $order['id'],
    364 'total_amount' => $params['amount'],
    • Created by: artfulrobot

      I've added both in because that's the most efficient way (saves a lookup on instrument). It currently looks up intstrument from the contribution too, if processor not given, but anyway.

      I wonder if payment_processor_id should be required for Payment.create - it seems really important and is stored in the financial transaction table.

  • homotechsual
    homotechsual @homotechsual started a thread on commit 92f5cf20
  • 351 353 }
    352 354 $order = civicrm_api3('Order', 'create' $params);
    353 355 try {
    356 // Use the Payment Processor to attempt to take the actual payment. You may
    357 // pass in other params here, too.
    354 358 civicrm_api3('PaymentProcessor', 'pay', ['contribution_id' => $order['id']]);
    355 civicrm_api3('Payment', 'create', ['contribution_id' => $order['id'], 'amount' => $params['amount']]);
    359
    360 // Assuming the payment was taken, record it which will mark the Contribution
    361 // as Completed and update related entities.
    362 civicrm_api3('Payment', 'create', [
    363 'contribution_id' => $order['id'],
    364 'total_amount' => $params['amount'],
    • Created by: eileenmcnaughton

      Well processor_id is only relevant for processor payments -not checks. If you pass in payment_instrument_id & it is not the same as the one associated with they payment processor I think it should be ignored - meaning a look up is still needed

  • Created by: artfulrobot

    Aah, yes checks. I'll add a note. I think it's the other way around at the moment, I think if you pass in instrument the lookup on processor does not happen.

  • Created by: eileenmcnaughton

    @artfulrobot ok I logged that here dev/financial#95

    @MikeyMJCO I think this is OK to merge

  • homotechsual
  • Approved - merging!

  • Created by: eileenmcnaughton

    Yay thanks - great this documentation is progressing

  • Please register or sign in to reply
    Loading