@@ -851,4 +851,186 @@ function( $item ) {
851851
852852 $ this ->assertEquals ( $ expected , $ actual );
853853 }
854+
855+ public function testCheckoutOrderMutationWithPrepaidOrder () {
856+ update_option ( 'woocommerce_enable_guest_checkout ' , 'yes ' );
857+ $ product_ids = array (
858+ $ this ->product ->create_simple (
859+ array (
860+ 'virtual ' => true ,
861+ 'downloadable ' => true ,
862+ )
863+ ),
864+ $ this ->product ->create_simple (
865+ array (
866+ 'virtual ' => true ,
867+ 'downloadable ' => true ,
868+ )
869+ ),
870+ );
871+ $ coupon = new WC_Coupon (
872+ $ this ->coupon ->create ( array ( 'product_ids ' => $ product_ids ) )
873+ );
874+ WC ()->cart ->add_to_cart ( $ product_ids [0 ], 3 );
875+ WC ()->cart ->add_to_cart ( $ product_ids [1 ], 6 );
876+ WC ()->cart ->apply_coupon ( $ coupon ->get_code () );
877+
878+ $ input = array (
879+ 'clientMutationId ' => 'someId ' ,
880+ 'paymentMethod ' => 'bacs ' ,
881+ 'isPaid ' => true ,
882+ 'transactionId ' => 'transaction_id ' ,
883+ 'shippingMethod ' => 'flat rate ' ,
884+ 'billing ' => array (
885+ 'firstName ' => 'May ' ,
886+ 'lastName ' => 'Parker ' ,
887+ 'address1 ' => '20 Ingram St ' ,
888+ 'city ' => 'New York City ' ,
889+ 'state ' => 'NY ' ,
890+ 'postcode ' => '12345 ' ,
891+ 'country ' => 'US ' ,
892+ 893+ 'phone ' => '555-555-1234 ' ,
894+ ),
895+ 'shipping ' => array (
896+ 'firstName ' => 'May ' ,
897+ 'lastName ' => 'Parker ' ,
898+ 'address1 ' => '20 Ingram St ' ,
899+ 'city ' => 'New York City ' ,
900+ 'state ' => 'NY ' ,
901+ 'postcode ' => '12345 ' ,
902+ 'country ' => 'US ' ,
903+ ),
904+ );
905+
906+ /**
907+ * Assertion One
908+ *
909+ * Test mutation and input.
910+ */
911+ $ actual = $ this ->checkout ( $ input );
912+
913+ // use --debug flag to view.
914+ codecept_debug ( $ actual );
915+
916+ $ this ->assertArrayHasKey ('data ' , $ actual );
917+ $ this ->assertArrayHasKey ('checkout ' , $ actual ['data ' ] );
918+ $ this ->assertArrayHasKey ('order ' , $ actual ['data ' ]['checkout ' ] );
919+ $ this ->assertArrayHasKey ('id ' , $ actual ['data ' ]['checkout ' ]['order ' ] );
920+ $ this ->assertEquals ('COMPLETED ' , $ actual ['data ' ]['checkout ' ]['order ' ]['status ' ] );
921+ $ order = \WC_Order_Factory::get_order ( $ actual ['data ' ]['checkout ' ]['order ' ]['orderId ' ] );
922+
923+ // Get Available payment gateways.
924+ $ available_gateways = WC ()->payment_gateways ->get_available_payment_gateways ();
925+
926+ $ expected = array (
927+ 'data ' => array (
928+ 'checkout ' => array (
929+ 'clientMutationId ' => 'someId ' ,
930+ 'order ' => array_merge (
931+ $ this ->order ->print_restricted_query ( $ order ->get_id () ),
932+ array (
933+ 'metaData ' => array (
934+ array (
935+ 'key ' => 'is_vat_exempt ' ,
936+ 'value ' => 'no ' ,
937+ ),
938+ ),
939+ 'couponLines ' => array (
940+ 'nodes ' => array_reverse (
941+ array_map (
942+ function ( $ item ) {
943+ return array (
944+ 'itemId ' => $ item ->get_id (),
945+ 'orderId ' => $ item ->get_order_id (),
946+ 'code ' => $ item ->get_code (),
947+ 'discount ' => ! empty ( $ item ->get_discount () ) ? $ item ->get_discount () : null ,
948+ 'discountTax ' => ! empty ( $ item ->get_discount_tax () ) ? $ item ->get_discount_tax () : null ,
949+ 'coupon ' => null ,
950+ );
951+ },
952+ $ order ->get_items ( 'coupon ' )
953+ )
954+ ),
955+ ),
956+ 'feeLines ' => array (
957+ 'nodes ' => array_reverse (
958+ array_map (
959+ function ( $ item ) {
960+ return array (
961+ 'itemId ' => $ item ->get_id (),
962+ 'orderId ' => $ item ->get_order_id (),
963+ 'amount ' => $ item ->get_amount (),
964+ 'name ' => $ item ->get_name (),
965+ 'taxStatus ' => strtoupper ( $ item ->get_tax_status () ),
966+ 'total ' => $ item ->get_total (),
967+ 'totalTax ' => ! empty ( $ item ->get_total_tax () ) ? $ item ->get_total_tax () : null ,
968+ 'taxClass ' => ! empty ( $ item ->get_tax_class () )
969+ ? WPEnumType::get_safe_name ( $ item ->get_tax_class () )
970+ : 'STANDARD ' ,
971+ );
972+ },
973+ $ order ->get_items ( 'fee ' )
974+ )
975+ ),
976+ ),
977+ 'shippingLines ' => null ,
978+ 'taxLines ' => array (
979+ 'nodes ' => array_reverse (
980+ array_map (
981+ function ( $ item ) {
982+ return array (
983+ 'rateCode ' => $ item ->get_rate_code (),
984+ 'label ' => $ item ->get_label (),
985+ 'taxTotal ' => $ item ->get_tax_total (),
986+ 'shippingTaxTotal ' => $ item ->get_shipping_tax_total (),
987+ 'isCompound ' => $ item ->is_compound (),
988+ 'taxRate ' => array ( 'rateId ' => $ item ->get_rate_id () ),
989+ );
990+ },
991+ $ order ->get_items ( 'tax ' )
992+ )
993+ ),
994+ ),
995+ 'lineItems ' => array (
996+ 'nodes ' => array_values (
997+ array_map (
998+ function ( $ item ) {
999+ return array (
1000+ 'productId ' => $ item ->get_product_id (),
1001+ 'variationId ' => ! empty ( $ item ->get_variation_id () )
1002+ ? $ item ->get_variation_id ()
1003+ : null ,
1004+ 'quantity ' => $ item ->get_quantity (),
1005+ 'taxClass ' => ! empty ( $ item ->get_tax_class () )
1006+ ? strtoupper ( $ item ->get_tax_class () )
1007+ : 'STANDARD ' ,
1008+ 'subtotal ' => ! empty ( $ item ->get_subtotal () ) ? $ item ->get_subtotal () : null ,
1009+ 'subtotalTax ' => ! empty ( $ item ->get_subtotal_tax () ) ? $ item ->get_subtotal_tax () : null ,
1010+ 'total ' => ! empty ( $ item ->get_total () ) ? $ item ->get_total () : null ,
1011+ 'totalTax ' => ! empty ( $ item ->get_total_tax () ) ? $ item ->get_total_tax () : null ,
1012+ 'taxStatus ' => strtoupper ( $ item ->get_tax_status () ),
1013+ 'product ' => array ( 'id ' => $ this ->product ->to_relay_id ( $ item ->get_product_id () ) ),
1014+ 'variation ' => ! empty ( $ item ->get_variation_id () )
1015+ ? array (
1016+ 'id ' => $ this ->variation ->to_relay_id ( $ item ->get_variation_id () )
1017+ )
1018+ : null ,
1019+ );
1020+ },
1021+ $ order ->get_items ()
1022+ )
1023+ ),
1024+ ),
1025+ )
1026+ ),
1027+ 'customer ' => null ,
1028+ 'result ' => 'success ' ,
1029+ 'redirect ' => $ available_gateways ['bacs ' ]->process_payment ( $ order ->get_id () )['redirect ' ],
1030+ ),
1031+ )
1032+ );
1033+
1034+ $ this ->assertEquals ( $ expected , $ actual );
1035+ }
8541036}
0 commit comments