@@ -332,6 +332,7 @@ public function validate_payment($id = null, $save_request = true, $ipn = false)
332
332
if (strpos ($ transaction_id , 'pay_ ' ) !== 0 ) {
333
333
$ payment = $ this ->api ->payment_retrieve ( $ this ->hosted_fields ->populateGetTransaction ($ transaction_id ), true );
334
334
$ payment ->is_live = $ this ->get_current_mode () === 'live ' ;
335
+ $ payment ->alias = get_post_meta ($ order_id , '_transaction_alias ' , true );
335
336
336
337
//FIXME:: HF the amount unit is EURO not Cents
337
338
$ payment ->amount = $ payment ->amount * 100 ;
@@ -668,7 +669,7 @@ public function filter_tokens($tokens, $user_id, $gateway_id)
668
669
}
669
670
670
671
if ($ current_year === (int ) $ token ->get_expiry_year () && $ current_month > (int ) $ token ->get_expiry_month ()) {
671
- unset($ tokens [$ k ]);
672
+ unset($ tokens [$ k ]);
672
673
continue ;
673
674
}
674
675
}
@@ -878,8 +879,9 @@ public function process_standard_payment($order, $amount, $customer_id)
878
879
];
879
880
880
881
if ($ this ->payment_method === 'integrated ' && (defined ('USE_HOSTED_FIELDS ' ) && USE_HOSTED_FIELDS ) && isset ($ _POST ['hftoken ' ])) {
882
+ $ saved_card = isset ($ _POST ['savedcard ' ]) && $ _POST ['savedcard ' ] === '1 ' ;
881
883
$ hf_token = filter_var ($ _POST ['hftoken ' ], FILTER_SANITIZE_STRING );
882
- $ payment_data = $ this ->hosted_fields ->populateCreatePayment ($ payment_data , $ order , $ order_id , $ hf_token , $ amount );
884
+ $ payment_data = $ this ->hosted_fields ->populateCreatePayment ($ payment_data , $ order , $ order_id , $ hf_token , $ amount, $ saved_card );
883
885
$ payment_data ['metadata ' ]['woocommerce_block ' ] = "HOSTED_FIELDS " ;
884
886
}
885
887
@@ -909,14 +911,32 @@ public function process_standard_payment($order, $amount, $customer_id)
909
911
*/
910
912
$ payment_data = apply_filters ('payplug_gateway_payment_data ' , $ payment_data , $ order_id , [], $ address_data );
911
913
$ payment = $ this ->api ->payment_create ($ payment_data );
914
+ $ alias = isset ($ payment ['ALIAS ' ]) ? $ payment ['ALIAS ' ] : null ;
912
915
913
916
//TODO:: payment is not created we need to generate an error
914
917
//HF VS NORMAL
915
918
$ payment_id = isset ($ payment ['TRANSACTIONID ' ]) ? $ payment ['TRANSACTIONID ' ] : $ payment ->id ;
916
-
917
919
if (!empty ($ payment_id ) && strpos ($ payment_id , 'pay_ ' ) !== 0 ) {
918
- $ payment = $ this ->api ->payment_retrieve ( $ this ->hosted_fields ->populateGetTransaction ($ payment_id ), true );
920
+ $ payment = $ this ->api ->payment_retrieve ( $ this ->hosted_fields ->populateGetTransaction ($ payment_id ),true );
919
921
$ payment ->is_live = $ this ->get_current_mode () === 'live ' ;
922
+ if (isset ($ alias )){
923
+ $ user_id = $ payment ->metadata ['customer_id ' ];
924
+ // Get and sanitize POST values
925
+ $ card_last4 = isset ($ _POST ['cardlast4 ' ]) ? filter_var ($ _POST ['cardlast4 ' ], FILTER_SANITIZE_STRING ) :'' ;
926
+ $ expiry_date = isset ($ _POST ['cardexpiry ' ]) ? filter_var ($ _POST ['cardexpiry ' ], FILTER_SANITIZE_STRING ):'' ;
927
+ if (preg_match ('/^(\d{2})\/(\d{2})$/ ' , $ expiry_date , $ matches )) {
928
+ $ set_expiry_year = '20 ' . $ matches [2 ];
929
+ $ set_expiry_month = $ matches [1 ];
930
+ } else {
931
+ $ set_expiry_year = '' ;
932
+ $ set_expiry_month = '' ;
933
+ }
934
+ update_user_meta ($ order ->get_customer_id (), 'payplug_customer_id ' , $ user_id );
935
+ update_user_meta ($ order ->get_customer_id (), 'payplug_card_last4 ' , $ card_last4 );
936
+ update_user_meta ($ order ->get_customer_id (), 'payplug_card_expiry_year ' , $ set_expiry_year );
937
+ update_user_meta ($ order ->get_customer_id (), 'payplug_card_expiry_month ' , $ set_expiry_month );
938
+
939
+ }
920
940
}
921
941
922
942
//TODO if payment has 5xxxx error
@@ -926,6 +946,12 @@ public function process_standard_payment($order, $amount, $customer_id)
926
946
? update_post_meta ($ order_id , '_transaction_id ' , $ payment_id )
927
947
: $ order ->set_transaction_id ($ payment_id );
928
948
949
+ if ($ alias ) {
950
+ update_post_meta ($ order_id , '_transaction_alias ' , $ alias );
951
+ }
952
+
953
+ $ order_alias = get_post_meta ($ order_id , '_transaction_alias ' , true );
954
+
929
955
$ order ->set_payment_method ( $ this ->id );
930
956
$ order ->set_payment_method_title ($ this ->method_title );
931
957
@@ -976,7 +1002,6 @@ public function process_standard_payment($order, $amount, $customer_id)
976
1002
*/
977
1003
public function process_payment_with_token ($ order , $ amount , $ customer_id , $ token_id )
978
1004
{
979
-
980
1005
$ order_id = PayplugWoocommerceHelper::is_pre_30 () ? $ order ->id : $ order ->get_id ();
981
1006
$ payment_token = WC_Payment_Tokens::get ($ token_id );
982
1007
if (!$ payment_token || (int ) $ customer_id !== (int ) $ payment_token ->get_user_id ()) {
@@ -1014,6 +1039,16 @@ public function process_payment_with_token($order, $amount, $customer_id, $token
1014
1039
],
1015
1040
];
1016
1041
1042
+ if ( (defined ('USE_HOSTED_FIELDS ' ) && USE_HOSTED_FIELDS )) {
1043
+
1044
+ if ( $ payment_token ->get_gateway_id () =='payplug ' && strpos ($ payment_token ->get_token (), 'card ' ) !== 0 ) {
1045
+ $ payment_data = $ this ->hosted_fields ->populateCreateWithAliasPayment ($ payment_data , $ order , $ order_id , $ amount , $ payment_token ->get_token ());
1046
+ $ payment_data ['metadata ' ]['woocommerce_block ' ] = "HOSTED_FIELDS " ;
1047
+ }
1048
+
1049
+ }
1050
+
1051
+
1017
1052
$ is_subscription = PayplugWoocommerceHelper::is_subscription ();
1018
1053
if ( !empty ($ is_subscription ) && $ is_subscription === true ){
1019
1054
$ payment_data ['metadata ' ]['subscription ' ] = 'subscription ' ;
@@ -1024,10 +1059,12 @@ public function process_payment_with_token($order, $amount, $customer_id, $token
1024
1059
$ payment_data = apply_filters ('payplug_gateway_payment_data ' , $ payment_data , $ order_id , [], $ address_data );
1025
1060
$ payment = $ this ->api ->payment_create ($ payment_data );
1026
1061
1062
+ $ payment_id = isset ($ payment ['TRANSACTIONID ' ]) ? $ payment ['TRANSACTIONID ' ] : $ payment ->id ;
1063
+
1027
1064
// Save transaction id for the order
1028
1065
PayplugWoocommerceHelper::is_pre_30 ()
1029
- ? update_post_meta ($ order_id , '_transaction_id ' , $ payment -> id )
1030
- : $ order ->set_transaction_id ($ payment -> id );
1066
+ ? update_post_meta ($ order_id , '_transaction_id ' , $ payment_id )
1067
+ : $ order ->set_transaction_id ($ payment_id );
1031
1068
1032
1069
if (is_callable ([$ order , 'save ' ])) {
1033
1070
$ order ->save ();
@@ -1042,18 +1079,26 @@ public function process_payment_with_token($order, $amount, $customer_id, $token
1042
1079
1043
1080
$ this ->response ->process_payment ($ payment , true );
1044
1081
1045
- if (($ payment ->__get ('is_paid ' ))){
1082
+ if (isset ($ payment ['EXECCODE ' ] )&&( $ payment ['EXECCODE ' ] == 0000 ))
1083
+ {
1046
1084
$ redirect = $ order ->get_checkout_order_received_url ();
1047
- }else if (isset ($ payment ->__get ('hosted_payment ' )-> payment_url )){
1048
- $ redirect = $ payment -> __get ( ' hosted_payment ' )-> payment_url ;
1049
- }else {
1085
+ } else if (($ payment ->__get ('is_paid ' ) )){
1086
+ $ redirect = $ order -> get_checkout_order_received_url () ;
1087
+ } else {
1050
1088
$ redirect = $ return_url ;
1051
1089
}
1052
1090
1091
+ if (isset ($ payment ['EXECCODE ' ]) )
1092
+ {
1093
+ $ is_paid = $ payment ['EXECCODE ' ] == 00000 ? true : false ;
1094
+ } else {
1095
+ $ is_paid = $ payment ->__get ('is_paid ' );
1096
+ }
1097
+
1053
1098
return [
1054
- 'payment_id ' => $ payment -> id ,
1099
+ 'payment_id ' => $ payment_id ,
1055
1100
'result ' => 'success ' ,
1056
- 'is_paid ' => $ payment -> __get ( ' is_paid ' ) , // Use for path redirect before DSP2
1101
+ 'is_paid ' => $ is_paid , // Use for path redirect before DSP2
1057
1102
'redirect ' => $ redirect
1058
1103
];
1059
1104
} catch (HttpException $ e ) {
0 commit comments