@@ -97,11 +97,15 @@ public function process_subscription_payment( $order, $amount ) {
9797
9898 $ order_id = $ order ->get_id ();
9999
100- $ auth_code = get_post_meta ( $ order_id , '_paystack_token ' , true );
100+ $ paystack_token = $ order -> get_meta ( '_paystack_token ' );
101101
102- if ( $ auth_code ) {
102+ if ( ! empty ( $ paystack_token ) ) {
103103
104104 $ order_amount = $ amount * 100 ;
105+ $ txnref = $ order_id . '_ ' . time ();
106+
107+ $ order ->update_meta_data ( '_paystack_txn_ref ' , $ txnref );
108+ $ order ->save ();
105109
106110 $ paystack_url = 'https://api.paystack.co/transaction/charge_authorization ' ;
107111
@@ -112,11 +116,21 @@ public function process_subscription_payment( $order, $amount ) {
112116
113117 $ metadata ['custom_fields ' ] = $ this ->get_custom_fields ( $ order_id );
114118
119+ if ( strpos ( $ paystack_token , '### ' ) !== false ) {
120+ $ payment_token = explode ( '### ' , $ paystack_token );
121+ $ auth_code = $ payment_token [0 ];
122+ $ customer_email = $ payment_token [1 ];
123+ } else {
124+ $ auth_code = $ paystack_token ;
125+ $ customer_email = $ order ->get_billing_email ();
126+ }
127+
115128 $ body = array (
116- 'email ' => $ order -> get_billing_email () ,
129+ 'email ' => $ customer_email ,
117130 'amount ' => $ order_amount ,
118131 'metadata ' => $ metadata ,
119132 'authorization_code ' => $ auth_code ,
133+ 'reference ' => $ txnref ,
120134 );
121135
122136 $ args = array (
0 commit comments