Repository navigation
Keep the passed payment in trigger_payment_status_change #3620
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
01513c5
d0fd2db
a934dc4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,6 +70,94 @@ public function test_maybe_use_decimal() { | |
| $this->assertSame( '111.500', $amount ); | ||
| } | ||
|
|
||
| /** | ||
| * @covers FrmTransLiteActionsController::trigger_payment_status_change | ||
| */ | ||
| public function test_trigger_payment_status_change_keeps_passed_payment() { | ||
| $entry = $this->create_entry_with_payments( array( 'complete', 'pending' ) ); | ||
| $older_id = $entry['payment_ids'][0]; | ||
| $older = ( new FrmTransLitePayment() )->get_one( $older_id ); | ||
|
|
||
| $atts = $this->trigger_payment_status_change( | ||
| array( | ||
| 'status' => 'refunded', | ||
| 'payment' => $older, | ||
| ) | ||
| ); | ||
|
|
||
| $this->assertNotNull( $atts ); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| $this->assertEquals( $older_id, $atts['payment']->id ); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| $this->assertEquals( $entry['id'], $atts['entry_id'] ); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
| /** | ||
| * @covers FrmTransLiteActionsController::trigger_payment_status_change | ||
| */ | ||
| public function test_trigger_payment_status_change_loads_payment_for_entry() { | ||
| $entry = $this->create_entry_with_payments( array( 'complete' ) ); | ||
|
|
||
| $atts = $this->trigger_payment_status_change( | ||
| array( | ||
| 'status' => 'refunded', | ||
| 'entry' => (object) array( 'id' => $entry['id'] ), | ||
| ) | ||
| ); | ||
|
|
||
| $this->assertNotNull( $atts ); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| $this->assertEquals( $entry['payment_ids'][0], $atts['payment']->id ); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
| /** | ||
| * @param array $atts | ||
| * | ||
| * @return array|null The atts passed to the frm_payment_status_refunded hook. | ||
| */ | ||
| private function trigger_payment_status_change( $atts ) { | ||
| $received = null; | ||
| $callback = function ( $hook_atts ) use ( &$received ) { | ||
| $received = $hook_atts; | ||
| }; | ||
|
|
||
| add_action( 'frm_payment_status_refunded', $callback ); | ||
| FrmTransLiteActionsController::trigger_payment_status_change( $atts ); | ||
| remove_action( 'frm_payment_status_refunded', $callback ); | ||
|
|
||
| return $received; | ||
| } | ||
|
|
||
| /** | ||
| * @param string[] $statuses One payment is created per status, oldest first. | ||
| * | ||
| * @return array{id: int, payment_ids: int[]} | ||
| */ | ||
| private function create_entry_with_payments( $statuses ) { | ||
| ( new FrmTransLiteDb() )->upgrade(); | ||
|
|
||
| $form = $this->factory->form->create_and_get(); | ||
| $entry = $this->factory->entry->create_and_get( $this->factory->field->generate_entry_array( $form ) ); | ||
| $frm_payment = new FrmTransLitePayment(); | ||
| $payment_ids = array(); | ||
|
|
||
| foreach ( $statuses as $index => $status ) { | ||
| $payment_ids[] = $frm_payment->create( | ||
| array( | ||
| 'item_id' => $entry->id, | ||
| 'action_id' => 1, | ||
| 'amount' => '10.00', | ||
| 'paysys' => 'stripe', | ||
| 'receipt_id' => 'pi_test_' . $index, | ||
| 'status' => $status, | ||
| 'created_at' => gmdate( 'Y-m-d H:i:s', strtotime( '+' . $index . ' day' ) ), | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| return array( | ||
| 'id' => $entry->id, | ||
| 'payment_ids' => $payment_ids, | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * @param string $amount | ||
| * @param array $currency | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method you are trying to call is not defined, which can result in a fatal error.