@@ -60,9 +60,9 @@ function kkd_pff_paystack_add_paystack_charge($amount)
6060 // $amountinkobo = $amount; // * 100;
6161 $ amount = intval ($ amount );
6262 if ($ amount <= 2500 ) {
63- $ amount = $ amount + ($ amount *KKD_PFF_PAYSTACK_PERCENTAGE );
63+ $ amount = $ amount + floatval ($ amount *KKD_PFF_PAYSTACK_PERCENTAGE );
6464 }else {
65- $ amount = $ amount + ($ amount *KKD_PFF_PAYSTACK_PERCENTAGE )+100 ;
65+ $ amount = $ amount + floatval ($ amount *KKD_PFF_PAYSTACK_PERCENTAGE )+100 ;
6666
6767 }
6868 return $ amount ;
@@ -1361,6 +1361,7 @@ function kkd_pff_paystack_submit_action() {
13611361 unset($ metadata ['pf-plancode ' ]);
13621362 }
13631363 }
1364+
13641365 if ($ plancode != 'none ' ){
13651366 $ fixedmetadata [] = array (
13661367 'display_name ' => 'Plan ' ,
@@ -1410,20 +1411,23 @@ function kkd_pff_paystack_submit_action() {
14101411 if ($ transaction_charge == "" || $ transaction_charge == 0 || $ transaction_charge == NULL ) {
14111412 $ transaction_charge = NULL ;
14121413 }
1414+
1415+ $ amount = floatval ($ insert ['amount ' ])*100 ;
14131416 $ response = array (
14141417 'result ' => 'success ' ,
14151418 'code ' => $ insert ['txn_code ' ],
14161419 'plan ' => $ insert ['plan ' ],
14171420 'quantity ' => $ quantity ,
14181421 'email ' => $ insert ['email ' ],
14191422 'name ' => $ fullname ,
1420- 'total ' => $ insert [ ' amount ' ]* 100 ,
1423+ 'total ' => round ( $ amount) ,
14211424 'custom_fields ' => $ fixedmetadata ,
14221425 'subaccount ' => $ subaccount ,
14231426 'txnbearer ' => $ txnbearer ,
14241427 'transaction_charge ' => $ transaction_charge
14251428 );
1426- echo json_encode ($ response );
1429+ // print_r($response);
1430+ echo json_encode ($ response ,JSON_NUMERIC_CHECK );
14271431
14281432 die ();
14291433}
@@ -1534,6 +1538,7 @@ function kkd_pff_paystack_confirm_payment() {
15341538 if ( ! is_wp_error ( $ request ) && 200 == wp_remote_retrieve_response_code ( $ request ) ) {
15351539 $ paystack_response = json_decode ( wp_remote_retrieve_body ( $ request ) );
15361540 if ( 'success ' == $ paystack_response ->data ->status ) {
1541+ $ customer_code = $ paystack_response ->data ->customer ->customer_code ;
15371542 $ amount_paid = $ paystack_response ->data ->amount / 100 ;
15381543 $ paystack_ref = $ paystack_response ->data ->reference ;
15391544 if ($ recur == 'optional ' || $ recur == 'plan ' ) {
@@ -1601,6 +1606,47 @@ function kkd_pff_paystack_confirm_payment() {
16011606 }
16021607
16031608 if ($ result == 'success ' ) {
1609+ ///
1610+ //Create Plan
1611+ $ enabled_custom_plan = get_post_meta ($ payment_array ->post_id , '_startdate_enabled ' , true );
1612+ if ($ enabled_custom_plan == 1 ) {
1613+ $ mode = esc_attr ( get_option ('mode ' ) );
1614+ if ($ mode == 'test ' ) {
1615+ $ key = esc_attr ( get_option ('tsk ' ) );
1616+ }else {
1617+ $ key = esc_attr ( get_option ('lsk ' ) );
1618+ }
1619+ //Create Plan
1620+ $ paystack_url = 'https://api.paystack.co/subscription ' ;
1621+ $ headers = array (
1622+ 'Content-Type ' => 'application/json ' ,
1623+ 'Authorization ' => 'Bearer ' . $ key
1624+ );
1625+ $ custom_plan = get_post_meta ($ payment_array ->post_id , '_startdate_plan_code ' , true );
1626+ $ days = get_post_meta ($ payment_array ->post_id , '_startdate_days ' , true );
1627+
1628+ $ start_date = date ("c " , strtotime ("+ " .$ days ." days " ));
1629+ $ body = array (
1630+ 'start_date ' => $ start_date ,
1631+ 'plan ' => $ custom_plan ,
1632+ 'customer ' => $ customer_code
1633+ );
1634+ $ args = array (
1635+ 'body ' => json_encode ( $ body ),
1636+ 'headers ' => $ headers ,
1637+ 'timeout ' => 60
1638+ );
1639+
1640+ $ request = wp_remote_post ( $ paystack_url , $ args );
1641+ if ( ! is_wp_error ( $ request )) {
1642+ $ paystack_response = json_decode (wp_remote_retrieve_body ($ request ));
1643+ $ plancode = $ paystack_response ->data ->subscription_code ;
1644+ // $message.= $message.'Subscribed<br>'.$plancode.'sssss';
1645+
1646+
1647+ }
1648+ }
1649+
16041650 $ sendreceipt = get_post_meta ($ payment_array ->post_id , '_sendreceipt ' , true );
16051651 if ($ sendreceipt == 'yes ' ){
16061652 $ decoded = json_decode ($ payment_array ->metadata );
0 commit comments