Skip to content

Commit b69676d

Browse files
author
Timur Karimov
committed
merge UPE tests into main gateway - III
1 parent 5012f8e commit b69676d

File tree

3 files changed

+372
-686
lines changed

3 files changed

+372
-686
lines changed

tests/unit/payment-methods/test-class-upe-payment-gateway.php

Lines changed: 0 additions & 353 deletions
Original file line numberDiff line numberDiff line change
@@ -354,359 +354,6 @@ public function tear_down() {
354354
wcpay_get_test_container()->reset_all_replacements();
355355
}
356356

357-
public function test_process_redirect_payment_intent_processing() {
358-
$order = WC_Helper_Order::create_order();
359-
$order_id = $order->get_id();
360-
$save_payment_method = false;
361-
$user = wp_get_current_user();
362-
$intent_status = Intent_Status::PROCESSING;
363-
$intent_metadata = [ 'order_id' => (string) $order_id ];
364-
$charge_id = 'ch_mock';
365-
$customer_id = 'cus_mock';
366-
$intent_id = 'pi_mock';
367-
$payment_method_id = 'pm_mock';
368-
369-
// Supply the order with the intent id so that it can be retrieved during the redirect payment processing.
370-
$order->update_meta_data( '_intent_id', $intent_id );
371-
$order->save();
372-
373-
$payment_intent = WC_Helper_Intention::create_intention(
374-
[
375-
'status' => $intent_status,
376-
'metadata' => $intent_metadata,
377-
]
378-
);
379-
380-
$this->mock_gateway->expects( $this->once() )
381-
->method( 'manage_customer_details_for_order' )
382-
->will(
383-
$this->returnValue( [ $user, $customer_id ] )
384-
);
385-
386-
$request = $this->mock_wcpay_request( Get_Intention::class, 1, $intent_id );
387-
388-
$request->expects( $this->once() )
389-
->method( 'format_response' )
390-
->will( $this->returnValue( $payment_intent ) );
391-
392-
$this->set_cart_contains_subscription_items( false );
393-
394-
$this->mock_gateway->process_redirect_payment( $order, $intent_id, $save_payment_method );
395-
396-
$result_order = wc_get_order( $order_id );
397-
$note = wc_get_order_notes(
398-
[
399-
'order_id' => $order_id,
400-
'limit' => 1,
401-
]
402-
)[0];
403-
404-
$this->assertStringContainsString( 'authorized', $note->content );
405-
$this->assertEquals( $intent_id, $result_order->get_meta( '_intent_id', true ) );
406-
$this->assertEquals( $charge_id, $result_order->get_meta( '_charge_id', true ) );
407-
$this->assertEquals( $intent_status, $result_order->get_meta( '_intention_status', true ) );
408-
$this->assertEquals( $payment_method_id, $result_order->get_meta( '_payment_method_id', true ) );
409-
$this->assertEquals( $customer_id, $result_order->get_meta( '_stripe_customer_id', true ) );
410-
$this->assertEquals( Order_Status::ON_HOLD, $result_order->get_status() );
411-
}
412-
413-
public function test_process_redirect_payment_intent_succeded() {
414-
$order = WC_Helper_Order::create_order();
415-
$order_id = $order->get_id();
416-
$save_payment_method = false;
417-
$user = wp_get_current_user();
418-
$intent_status = Intent_Status::SUCCEEDED;
419-
$intent_metadata = [ 'order_id' => (string) $order_id ];
420-
$charge_id = 'ch_mock';
421-
$customer_id = 'cus_mock';
422-
$intent_id = 'pi_mock';
423-
$payment_method_id = 'pm_mock';
424-
425-
// Supply the order with the intent id so that it can be retrieved during the redirect payment processing.
426-
$order->update_meta_data( '_intent_id', $intent_id );
427-
$order->save();
428-
429-
$payment_intent = WC_Helper_Intention::create_intention(
430-
[
431-
'status' => $intent_status,
432-
'metadata' => $intent_metadata,
433-
]
434-
);
435-
436-
$this->mock_gateway->expects( $this->once() )
437-
->method( 'manage_customer_details_for_order' )
438-
->will(
439-
$this->returnValue( [ $user, $customer_id ] )
440-
);
441-
442-
$request = $this->mock_wcpay_request( Get_Intention::class, 1, $intent_id );
443-
444-
$request->expects( $this->once() )
445-
->method( 'format_response' )
446-
->will( $this->returnValue( $payment_intent ) );
447-
448-
$this->set_cart_contains_subscription_items( false );
449-
450-
$this->mock_gateway->process_redirect_payment( $order, $intent_id, $save_payment_method );
451-
452-
$result_order = wc_get_order( $order_id );
453-
454-
$this->assertEquals( $intent_id, $result_order->get_meta( '_intent_id', true ) );
455-
$this->assertEquals( $charge_id, $result_order->get_meta( '_charge_id', true ) );
456-
$this->assertEquals( $intent_status, $result_order->get_meta( '_intention_status', true ) );
457-
$this->assertEquals( $payment_method_id, $result_order->get_meta( '_payment_method_id', true ) );
458-
$this->assertEquals( $customer_id, $result_order->get_meta( '_stripe_customer_id', true ) );
459-
$this->assertEquals( Order_Status::PROCESSING, $result_order->get_status() );
460-
}
461-
462-
public function test_validate_order_id_received_vs_intent_meta_order_id_throw_exception() {
463-
$order = WC_Helper_Order::create_order();
464-
$intent_metadata = [ 'order_id' => (string) ( $order->get_id() + 100 ) ];
465-
466-
$this->expectException( Process_Payment_Exception::class );
467-
$this->expectExceptionMessage( "We're not able to process this payment due to the order ID mismatch. Please try again later." );
468-
469-
\PHPUnit_Utils::call_method(
470-
$this->mock_gateway,
471-
'validate_order_id_received_vs_intent_meta_order_id',
472-
[ $order, $intent_metadata ]
473-
);
474-
}
475-
476-
public function test_validate_order_id_received_vs_intent_meta_order_id_returning_void() {
477-
$order = WC_Helper_Order::create_order();
478-
$intent_metadata = [ 'order_id' => (string) ( $order->get_id() ) ];
479-
480-
$res = \PHPUnit_Utils::call_method(
481-
$this->mock_gateway,
482-
'validate_order_id_received_vs_intent_meta_order_id',
483-
[ $order, $intent_metadata ]
484-
);
485-
486-
$this->assertSame( null, $res );
487-
}
488-
489-
public function test_correct_payment_method_title_for_order() {
490-
$order = WC_Helper_Order::create_order();
491-
492-
$visa_credit_details = [
493-
'type' => 'card',
494-
'card' => [
495-
'network' => 'visa',
496-
'funding' => 'credit',
497-
],
498-
];
499-
$visa_debit_details = [
500-
'type' => 'card',
501-
'card' => [
502-
'network' => 'visa',
503-
'funding' => 'debit',
504-
],
505-
];
506-
$mastercard_credit_details = [
507-
'type' => 'card',
508-
'card' => [
509-
'network' => 'mastercard',
510-
'funding' => 'credit',
511-
],
512-
];
513-
$eps_details = [
514-
'type' => 'eps',
515-
];
516-
$giropay_details = [
517-
'type' => 'giropay',
518-
];
519-
$p24_details = [
520-
'type' => 'p24',
521-
];
522-
$sofort_details = [
523-
'type' => 'sofort',
524-
];
525-
$bancontact_details = [
526-
'type' => 'bancontact',
527-
];
528-
$sepa_details = [
529-
'type' => 'sepa_debit',
530-
];
531-
$ideal_details = [
532-
'type' => 'ideal',
533-
];
534-
$becs_details = [
535-
'type' => 'au_becs_debit',
536-
];
537-
538-
$charge_payment_method_details = [
539-
$visa_credit_details,
540-
$visa_debit_details,
541-
$mastercard_credit_details,
542-
$giropay_details,
543-
$sofort_details,
544-
$bancontact_details,
545-
$eps_details,
546-
$p24_details,
547-
$ideal_details,
548-
$sepa_details,
549-
$becs_details,
550-
];
551-
552-
$expected_payment_method_titles = [
553-
'Visa credit card',
554-
'Visa debit card',
555-
'Mastercard credit card',
556-
'giropay',
557-
'Sofort',
558-
'Bancontact',
559-
'EPS',
560-
'Przelewy24 (P24)',
561-
'iDEAL',
562-
'SEPA Direct Debit',
563-
'BECS Direct Debit',
564-
];
565-
566-
foreach ( $charge_payment_method_details as $i => $payment_method_details ) {
567-
$this->mock_gateway->set_payment_method_title_for_order( $order, $payment_method_details['type'], $payment_method_details );
568-
$this->assertEquals( $expected_payment_method_titles[ $i ], $order->get_payment_method_title() );
569-
}
570-
}
571-
572-
public function test_payment_methods_show_correct_default_outputs() {
573-
$mock_token = WC_Helper_Token::create_token( 'pm_mock' );
574-
$this->mock_token_service->expects( $this->any() )
575-
->method( 'add_payment_method_to_user' )
576-
->will(
577-
$this->returnValue( $mock_token )
578-
);
579-
580-
$mock_user = 'mock_user';
581-
$mock_payment_method_id = 'pm_mock';
582-
583-
$mock_visa_details = [
584-
'type' => 'card',
585-
'card' => [
586-
'network' => 'visa',
587-
'funding' => 'debit',
588-
],
589-
];
590-
$mock_mastercard_details = [
591-
'type' => 'card',
592-
'card' => [
593-
'network' => 'mastercard',
594-
'funding' => 'credit',
595-
],
596-
];
597-
$mock_giropay_details = [
598-
'type' => 'giropay',
599-
];
600-
$mock_p24_details = [
601-
'type' => 'p24',
602-
];
603-
$mock_sofort_details = [
604-
'type' => 'sofort',
605-
];
606-
$mock_bancontact_details = [
607-
'type' => 'bancontact',
608-
];
609-
$mock_eps_details = [
610-
'type' => 'eps',
611-
];
612-
$mock_sepa_details = [
613-
'type' => 'sepa_debit',
614-
];
615-
$mock_ideal_details = [
616-
'type' => 'ideal',
617-
];
618-
$mock_becs_details = [
619-
'type' => 'au_becs_debit',
620-
];
621-
$mock_affirm_details = [
622-
'type' => 'affirm',
623-
];
624-
$mock_afterpay_details = [
625-
'type' => 'afterpay_clearpay',
626-
];
627-
628-
$this->set_cart_contains_subscription_items( false );
629-
$card_method = $this->mock_payment_methods['card'];
630-
$giropay_method = $this->mock_payment_methods['giropay'];
631-
$p24_method = $this->mock_payment_methods['p24'];
632-
$sofort_method = $this->mock_payment_methods['sofort'];
633-
$bancontact_method = $this->mock_payment_methods['bancontact'];
634-
$eps_method = $this->mock_payment_methods['eps'];
635-
$sepa_method = $this->mock_payment_methods['sepa_debit'];
636-
$ideal_method = $this->mock_payment_methods['ideal'];
637-
$becs_method = $this->mock_payment_methods['au_becs_debit'];
638-
$affirm_method = $this->mock_payment_methods['affirm'];
639-
$afterpay_method = $this->mock_payment_methods['afterpay_clearpay'];
640-
641-
$this->assertEquals( 'card', $card_method->get_id() );
642-
$this->assertEquals( 'Credit card / debit card', $card_method->get_title() );
643-
$this->assertEquals( 'Visa debit card', $card_method->get_title( $mock_visa_details ) );
644-
$this->assertEquals( 'Mastercard credit card', $card_method->get_title( $mock_mastercard_details ) );
645-
$this->assertTrue( $card_method->is_enabled_at_checkout( 'US' ) );
646-
$this->assertTrue( $card_method->is_reusable() );
647-
$this->assertEquals( $mock_token, $card_method->get_payment_token_for_user( $mock_user, $mock_payment_method_id ) );
648-
649-
$this->assertEquals( 'giropay', $giropay_method->get_id() );
650-
$this->assertEquals( 'giropay', $giropay_method->get_title() );
651-
$this->assertEquals( 'giropay', $giropay_method->get_title( $mock_giropay_details ) );
652-
$this->assertTrue( $giropay_method->is_enabled_at_checkout( 'US' ) );
653-
$this->assertFalse( $giropay_method->is_reusable() );
654-
655-
$this->assertEquals( 'p24', $p24_method->get_id() );
656-
$this->assertEquals( 'Przelewy24 (P24)', $p24_method->get_title() );
657-
$this->assertEquals( 'Przelewy24 (P24)', $p24_method->get_title( $mock_p24_details ) );
658-
$this->assertTrue( $p24_method->is_enabled_at_checkout( 'US' ) );
659-
$this->assertFalse( $p24_method->is_reusable() );
660-
661-
$this->assertEquals( 'sofort', $sofort_method->get_id() );
662-
$this->assertEquals( 'Sofort', $sofort_method->get_title() );
663-
$this->assertEquals( 'Sofort', $sofort_method->get_title( $mock_sofort_details ) );
664-
$this->assertTrue( $sofort_method->is_enabled_at_checkout( 'US' ) );
665-
$this->assertFalse( $sofort_method->is_reusable() );
666-
667-
$this->assertEquals( 'bancontact', $bancontact_method->get_id() );
668-
$this->assertEquals( 'Bancontact', $bancontact_method->get_title() );
669-
$this->assertEquals( 'Bancontact', $bancontact_method->get_title( $mock_bancontact_details ) );
670-
$this->assertTrue( $bancontact_method->is_enabled_at_checkout( 'US' ) );
671-
$this->assertFalse( $bancontact_method->is_reusable() );
672-
673-
$this->assertEquals( 'eps', $eps_method->get_id() );
674-
$this->assertEquals( 'EPS', $eps_method->get_title() );
675-
$this->assertEquals( 'EPS', $eps_method->get_title( $mock_eps_details ) );
676-
$this->assertTrue( $eps_method->is_enabled_at_checkout( 'US' ) );
677-
$this->assertFalse( $eps_method->is_reusable() );
678-
679-
$this->assertEquals( 'sepa_debit', $sepa_method->get_id() );
680-
$this->assertEquals( 'SEPA Direct Debit', $sepa_method->get_title() );
681-
$this->assertEquals( 'SEPA Direct Debit', $sepa_method->get_title( $mock_sepa_details ) );
682-
$this->assertTrue( $sepa_method->is_enabled_at_checkout( 'US' ) );
683-
$this->assertFalse( $sepa_method->is_reusable() );
684-
685-
$this->assertEquals( 'ideal', $ideal_method->get_id() );
686-
$this->assertEquals( 'iDEAL', $ideal_method->get_title() );
687-
$this->assertEquals( 'iDEAL', $ideal_method->get_title( $mock_ideal_details ) );
688-
$this->assertTrue( $ideal_method->is_enabled_at_checkout( 'US' ) );
689-
$this->assertFalse( $ideal_method->is_reusable() );
690-
691-
$this->assertEquals( 'au_becs_debit', $becs_method->get_id() );
692-
$this->assertEquals( 'BECS Direct Debit', $becs_method->get_title() );
693-
$this->assertEquals( 'BECS Direct Debit', $becs_method->get_title( $mock_becs_details ) );
694-
$this->assertTrue( $becs_method->is_enabled_at_checkout( 'US' ) );
695-
$this->assertFalse( $becs_method->is_reusable() );
696-
697-
$this->assertSame( 'affirm', $affirm_method->get_id() );
698-
$this->assertSame( 'Affirm', $affirm_method->get_title() );
699-
$this->assertSame( 'Affirm', $affirm_method->get_title( $mock_affirm_details ) );
700-
$this->assertTrue( $affirm_method->is_enabled_at_checkout( 'US' ) );
701-
$this->assertFalse( $affirm_method->is_reusable() );
702-
703-
$this->assertSame( 'afterpay_clearpay', $afterpay_method->get_id() );
704-
$this->assertSame( 'Afterpay', $afterpay_method->get_title() );
705-
$this->assertSame( 'Afterpay', $afterpay_method->get_title( $mock_afterpay_details ) );
706-
$this->assertTrue( $afterpay_method->is_enabled_at_checkout( 'US' ) );
707-
$this->assertFalse( $afterpay_method->is_reusable() );
708-
}
709-
710357
public function test_only_reusabled_payment_methods_enabled_with_subscription_item_present() {
711358
$this->set_cart_contains_subscription_items( true );
712359

0 commit comments

Comments
 (0)