Answers.Body: <p>Finally the <code>getById()</code> method is the simplest, as it implicitly manages the <code>is_test</code> param.</p>
  <pre><code>$pp = \Civi\Payment\System::singleton()-&gt;getById($processor_id)
  </code></pre>
  <p>The <code>\Civi\Payment\System::getByClass()</code> passes a dummy empty payment processor with id 0</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-09-27T10:29:10.703Z
Answers.LastActivityDate: 2024-09-27T10:29:10.703Z
Answers.UserDisplayName: Bastien Ho
Answers.Body: <p>There are a couple functions in <code>\Civi\Payment\System</code> which you can call depending on what info about the processor you have at the time.</p>
  <p>e.g. if the <code>name</code> (the <code>name</code> field in civicrm_payment_processor) is MyCustomProcessor, then you could do:</p>
  <p><code>$pp = \Civi\Payment\System::singleton()-&gt;getByName('MyCustomProcessor', $is_test);</code></p>
  <p>where $is_test is true or false depending on whether you are in test mode or not.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-09-04T09:29:56.567Z
Answers.Text: Thank you @demerit, I found the best way in my case thanks to your answer. 
  `\Civi\Payment\System::singleton()->getByClass('Payment_MyCustomProcessor', $is_test);`
Answers.UserDisplayName: Bastien Ho
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-09-03T15:17:54.183Z
Answers.LastActivityDate: 2024-09-03T15:17:54.183Z
Answers.UserDisplayName: Demerit
Body: <p>I have a <a href="https://docs.civicrm.org/dev/en/latest/extensions/payment-processors/paymentclass/" rel="nofollow noreferrer">custom Payment class</a> extending <code>CRM_Core_Payment</code>.</p>
  <p>In a custom page outside of the class, I need to call some public methods, such as <code>supportsRecurring()</code> or <code>getReturnSuccessUrl()</code>.</p>
  <p>What is the <em>clean</em> way to instantiate the class?</p>
  
Tags: <extension><payment-processor><payment>
Title: How to instanciate a paymentProcessor class?
ThreadText: # How to instanciate a paymentProcessor class?
  
  (Asked by: username_0 on 2024-09-03)
  
  I have a [custom Payment class](https://docs.civicrm.org/dev/en/latest/extensions/payment-processors/paymentclass/) extending `CRM_Core_Payment`.
  
  In a custom page outside of the class, I need to call some public methods, such as `supportsRecurring()` or `getReturnSuccessUrl()`.
  
  What is the *clean* way to instantiate the class?
  
  **Tags:** extension, payment-processor, payment
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2024-09-27. Score: 0 | Accepted answer
  
  Finally the `getById()` method is the simplest, as it implicitly manages the `is_test` param.
  
  ```
  $pp = \Civi\Payment\System::singleton()->getById($processor_id)
  
  ```
  
  The `\Civi\Payment\System::getByClass()` passes a dummy empty payment processor with id 0
  
  
  ---
  
  ### Answer by username_1 on 2024-09-03. Score: 1
  
  There are a couple functions in `\Civi\Payment\System` which you can call depending on what info about the processor you have at the time.
  
  e.g. if the `name` (the `name` field in civicrm\_payment\_processor) is MyCustomProcessor, then you could do:
  
  `$pp = \Civi\Payment\System::singleton()->getByName('MyCustomProcessor', $is_test);`
  
  where $is\_test is true or false depending on whether you are in test mode or not.
  
  > **Comments:**
  > **username_0**: Thank you @username_1, I found the best way in my case thanks to your answer.  `\Civi\Payment\System::singleton()->getByClass('Payment_MyCustomProcessor', $is_test);`  
  
  ---
  
  