@@ -187,13 +187,13 @@ function kkd_pff_paystack_send_invoice($currency,$amount,$name,$email,$code){
187187 <table class="primary_btn" align="center" border="0" cellspacing="0" cellpadding="0" style="border-spacing:0;mso-table-lspace:0;mso-table-rspace:0;clear:both;margin:0 auto">
188188 <tbody>
189189 <tr>
190- <!-- < p style="font-family:Helvetica,Arial,sans-serif;font-size:15px;line-height:23px;margin-top:16px;margin-bottom:24px"><small class="text-muted" style="font-size:86%;font-weight:normal;color:#b3b3b5">Use this link below to try again, if you encountered <br />any issue while trying to make the payment.</small><br>
190+ <p style="font-family:Helvetica,Arial,sans-serif;font-size:15px;line-height:23px;margin-top:16px;margin-bottom:24px"><small class="text-muted" style="font-size:86%;font-weight:normal;color:#b3b3b5">Use this link below to try again, if you encountered <br />any issue while trying to make the payment.</small><br>
191191 </p>
192192 <td class="font_default" style="padding:12px 24px;font-family:Helvetica,Arial,sans-serif;font-size:16px;mso-line-height-rule:exactly;text-align:center;vertical-align:middle;-webkit-border-radius:4px;border-radius:4px;background-color:#666">
193- <a href="<?php echo $ code ; ?> " style="display:block;text-decoration:none;font-family:Helvetica,Arial,sans-serif;color:#fff;font-weight:bold;text-align:center">
193+ <a href="<?php echo get_site_url (). ' /paystackinvoice/?code= ' . $ code ; ?> " style="display:block;text-decoration:none;font-family:Helvetica,Arial,sans-serif;color:#fff;font-weight:bold;text-align:center">
194194 <span style="text-decoration:none;color:#fff;text-align:center;display:block">Try Again</span>
195195 </a>
196- </td> -->
196+ </td>
197197 </tr>
198198 </tbody>
199199 </table>
@@ -527,6 +527,7 @@ function kkd_pff_paystack_form_shortcode($atts) {
527527 if ((($ user_id != 0 ) && ($ loggedin == 'yes ' )) || $ loggedin == 'no ' ) {
528528
529529 echo "<h1 id='pf-form " .$ id ."'> " .$ obj ->post_title ."</h1> " ;
530+ // echo get_site_url().'/paystackinvoice/?code=ddddddd';
530531 echo '<form enctype="multipart/form-data" action=" ' . admin_url ('admin-ajax.php ' ) . '" url=" ' . admin_url () . '" method="post" class="paystack-form j-forms" novalidate>
531532 <div class="j-row"> ' ;
532533 echo '<input type="hidden" name="action" value="kkd_pff_paystack_submit_action"> ' ;
@@ -1120,7 +1121,7 @@ function kkd_pff_paystack_confirm_payment() {
11201121
11211122 exit (json_encode ($ response ));
11221123 }
1123- global $ wpdb ;
1124+ global $ wpdb ;
11241125 $ table = $ wpdb ->prefix .KKD_PFF_PAYSTACK_TABLE ;
11251126 $ code = $ _POST ['code ' ];
11261127 $ record = $ wpdb ->get_results ("SELECT * FROM $ table WHERE (txn_code = ' " .$ code ."') " );
@@ -1230,3 +1231,178 @@ function kkd_pff_paystack_confirm_payment() {
12301231
12311232 die ();
12321233}
1234+
1235+
1236+ add_action ( 'wp_ajax_kkd_pff_paystack_retry_action ' , 'kkd_pff_paystack_retry_action ' );
1237+ add_action ( 'wp_ajax_nopriv_kkd_pff_paystack_retry_action ' , 'kkd_pff_paystack_retry_action ' );
1238+ function kkd_pff_paystack_retry_action () {
1239+ if (trim ($ _POST ['code ' ]) == '' ) {
1240+ $ response ['result ' ] = 'failed ' ;
1241+ $ response ['message ' ] = 'Cde is required ' ;
1242+
1243+ // Exit here, for not processing further because of the error
1244+ exit (json_encode ($ response ));
1245+ }
1246+ do_action ( 'kkd_pff_paystack_before_save ' );
1247+
1248+ global $ wpdb ;
1249+ $ code = $ _POST ['code ' ];
1250+ $ newcode = kkd_pff_paystack_generate_code ();
1251+ $ newcode = $ newcode .'_2 ' ;
1252+ $ insert = [];
1253+ $ table = $ wpdb ->prefix .KKD_PFF_PAYSTACK_TABLE ;
1254+ $ record = $ wpdb ->get_results ("SELECT * FROM $ table WHERE (txn_code = ' " .$ code ."') " );
1255+ if (array_key_exists ("0 " , $ record )) {
1256+ $ dbdata = $ record [0 ];
1257+ $ plan = $ dbdata ->plan ;
1258+ $ quantity = 1 ;
1259+ $ wpdb ->update ( $ table , array ( 'txn_code_2 ' => $ newcode ),array ('txn_code ' => $ code ));
1260+
1261+ $ currency = get_post_meta ($ dbdata ->post_id ,'_currency ' ,true );
1262+ $ fixedmetadata = kkd_pff_paystack_meta_as_custom_fields ($ dbdata ->metadata );
1263+ $ nmeta = json_decode ($ dbdata ->metadata );
1264+ foreach ($ nmeta as $ nkey => $ nvalue ) {
1265+ if ($ nvalue ->variable_name == 'Quantity ' ) {
1266+ $ quantity = $ nvalue ->value ;
1267+ }
1268+ if ($ nvalue ->variable_name == 'Full_Name ' ) {
1269+ $ fullname = $ nvalue ->value ;
1270+ }
1271+ }
1272+
1273+ }
1274+
1275+ $ response = array (
1276+ 'result ' => 'success ' ,
1277+ 'code ' => $ newcode ,
1278+ 'plan ' => $ plan ,
1279+ 'quantity ' => $ quantity ,
1280+ 'email ' => $ dbdata ->email ,
1281+ 'name ' => $ fullname ,
1282+ 'total ' => $ dbdata ->amount *100 ,
1283+ 'custom_fields ' => $ fixedmetadata
1284+ );
1285+ echo json_encode ($ response );
1286+
1287+ die ();
1288+ }
1289+ add_action ( 'wp_ajax_kkd_pff_paystack_rconfirm_payment ' , 'kkd_pff_paystack_rconfirm_payment ' );
1290+ add_action ( 'wp_ajax_nopriv_kkd_pff_paystack_rconfirm_payment ' , 'kkd_pff_paystack_rconfirm_payment ' );
1291+
1292+ function kkd_pff_paystack_rconfirm_payment () {
1293+ if (trim ($ _POST ['code ' ]) == '' ) {
1294+ $ response ['error ' ] = true ;
1295+ $ response ['error_message ' ] = "Did you make a payment? " ;
1296+
1297+ exit (json_encode ($ response ));
1298+ }
1299+ global $ wpdb ;
1300+ $ table = $ wpdb ->prefix .KKD_PFF_PAYSTACK_TABLE ;
1301+ $ code = $ _POST ['code ' ];
1302+ $ record = $ wpdb ->get_results ("SELECT * FROM $ table WHERE (txn_code_2 = ' " .$ code ."') " );
1303+ if (array_key_exists ("0 " , $ record )) {
1304+
1305+ $ payment_array = $ record [0 ];
1306+ $ amount = get_post_meta ($ payment_array ->post_id ,'_amount ' ,true );
1307+ $ recur = get_post_meta ($ payment_array ->post_id ,'_recur ' ,true );
1308+ $ currency = get_post_meta ($ payment_array ->post_id ,'_currency ' ,true );
1309+ $ txncharge = get_post_meta ($ payment_array ->post_id ,'_txncharge ' ,true );
1310+ $ redirect = get_post_meta ($ payment_array ->post_id ,'_redirect ' ,true );
1311+
1312+
1313+ $ mode = esc_attr ( get_option ('mode ' ) );
1314+ if ($ mode == 'test ' ) {
1315+ $ key = esc_attr ( get_option ('tsk ' ) );
1316+ }else {
1317+ $ key = esc_attr ( get_option ('lsk ' ) );
1318+ }
1319+ $ paystack_url = 'https://api.paystack.co/transaction/verify/ ' . $ code ;
1320+ $ headers = array (
1321+ 'Authorization ' => 'Bearer ' . $ key
1322+ );
1323+ $ args = array (
1324+ 'headers ' => $ headers ,
1325+ 'timeout ' => 60
1326+ );
1327+ $ request = wp_remote_get ( $ paystack_url , $ args );
1328+ if ( ! is_wp_error ( $ request ) && 200 == wp_remote_retrieve_response_code ( $ request ) ) {
1329+ $ paystack_response = json_decode ( wp_remote_retrieve_body ( $ request ) );
1330+ if ( 'success ' == $ paystack_response ->data ->status ) {
1331+ $ amount_paid = $ paystack_response ->data ->amount / 100 ;
1332+ $ paystack_ref = $ paystack_response ->data ->reference ;
1333+ if ($ recur == 'optional ' || $ recur == 'plan ' ) {
1334+ $ wpdb ->update ( $ table , array ( 'paid ' => 1 ,'amount ' =>$ amount_paid ),array ('txn_code_2 ' =>$ paystack_ref ));
1335+ $ thankyou = get_post_meta ($ payment_array ->post_id ,'_successmsg ' ,true );
1336+ $ message = $ thankyou ;
1337+ $ result = "success " ;
1338+ }else {
1339+
1340+ if ($ amount == 0 ) {
1341+ $ wpdb ->update ( $ table , array ( 'paid ' => 1 ,'amount ' =>$ amount_paid ),array ('txn_code_2 ' =>$ paystack_ref ));
1342+ $ thankyou = get_post_meta ($ payment_array ->post_id ,'_successmsg ' ,true );
1343+ $ message = $ thankyou ;
1344+ $ result = "success " ;
1345+ // kkd_pff_paystack_send_receipt($currency,$amount,$name,$payment_array->email,$code,$metadata)
1346+ }else {
1347+ $ usequantity = get_post_meta ($ payment_array ->post_id ,'_usequantity ' ,true );
1348+ if ($ usequantity == 'no ' ) {
1349+ $ amount = (int )str_replace (' ' , '' , $ amount );
1350+ }else {
1351+ $ quantity = $ _POST ["quantity " ];
1352+ $ unitamount = (int )str_replace (' ' , '' , $ amount );
1353+ $ amount = $ quantity *$ unitamount ;
1354+ }
1355+
1356+
1357+ if ($ txncharge == 'customer ' ) {
1358+ $ amount = kkd_pff_paystack_add_paystack_charge ($ amount );
1359+ }
1360+ if ( $ amount != $ amount_paid ) {
1361+ $ message = "Invalid amount Paid. Amount required is " .$ currency ."<b> " .number_format ($ amount )."</b> " ;
1362+ $ result = "failed " ;
1363+ }else {
1364+
1365+ $ wpdb ->update ( $ table , array ( 'paid ' => 1 ),array ('txn_code_2 ' =>$ paystack_ref ));
1366+ $ thankyou = get_post_meta ($ payment_array ->post_id ,'_successmsg ' ,true );
1367+ $ message = $ thankyou ;
1368+ $ result = "success " ;
1369+ }
1370+ }
1371+ }
1372+
1373+ }else {
1374+ $ message = "Transaction Failed/Invalid Code " ;
1375+ $ result = "failed " ;
1376+ }
1377+
1378+ }
1379+ }else {
1380+ $ message = "Payment Verification Failed. " ;
1381+ $ result = "failed " ;
1382+
1383+ }
1384+
1385+ if ($ result == 'success ' ) {
1386+ $ sendreceipt = get_post_meta ($ payment_array ->post_id , '_sendreceipt ' , true );
1387+ if ($ sendreceipt == 'yes ' ){
1388+ $ decoded = json_decode ($ payment_array ->metadata );
1389+ $ fullname = $ decoded [0 ]->value ;
1390+ kkd_pff_paystack_send_receipt ($ payment_array ->post_id ,$ currency ,$ amount_paid ,$ fullname ,$ payment_array ->email ,$ paystack_ref ,$ payment_array ->metadata );
1391+
1392+ }
1393+
1394+ }
1395+ $ response = array (
1396+ 'result ' => $ result ,
1397+ 'message ' => $ message ,
1398+ );
1399+ if ($ result == 'success ' && $ redirect != '' ) {
1400+ $ response ['result ' ] = 'success2 ' ;
1401+ $ response ['link ' ] = $ redirect ;
1402+ }
1403+
1404+
1405+ echo json_encode ($ response );
1406+
1407+ die ();
1408+ }
0 commit comments