@@ -19,7 +19,7 @@ class Confirm_Payment {
1919 /**
2020 * The helpers class.
2121 *
22- * @var object
22+ * @var \paystack\payment_forms\Helpers
2323 */
2424 public $ helpers ;
2525
@@ -65,6 +65,14 @@ class Confirm_Payment {
6565 */
6666 protected $ oamount = 0 ;
6767
68+ /**
69+ * The transaction column to update.
70+ * Defaults to 'txn_code' and 'txn_code_2' when a payment retry is triggered.
71+ *
72+ * @var integer
73+ */
74+ protected $ txn_column = 'txn_code ' ;
75+
6876 /**
6977 * Constructor
7078 */
@@ -74,13 +82,12 @@ public function __construct() {
7482 }
7583
7684 /**
77- * Undocumented function
85+ * Sets up our data for processing.
7886 *
7987 * @return void
8088 */
8189 protected function setup_data ( $ payment ) {
8290 $ this ->payment_meta = $ payment ;
83- $ this ->helpers = new Helpers ();
8491 $ this ->meta = $ this ->helpers ->parse_meta_values ( get_post ( $ this ->payment_meta ->post_id ) );
8592 $ this ->amount = $ this ->payment_meta ->amount ;
8693 $ this ->oamount = $ this ->meta ['amount ' ];
@@ -103,13 +110,18 @@ public function confirm_payment() {
103110
104111 exit ( wp_json_encode ( $ response ) );
105112 }
113+
114+ // If this is a retry payment then set the colum accordingly.
115+ if ( isset ( $ _POST ['retry ' ] ) ) {
116+ $ this ->txn_column = 'txn_code_2 ' ;
117+ }
106118
107-
108- $ code = sanitize_text_field ( $ _POST ['code ' ] );
109- $ record = $ this ->helpers ->get_db_record ( $ code );
119+ $ this -> helpers = new Helpers ();
120+ $ code = sanitize_text_field ( $ _POST ['code ' ] );
121+ $ record = $ this ->helpers ->get_db_record ( $ code, $ this -> txn_column );
110122
111123 if ( false !== $ record ) {
112-
124+
113125 $ this ->setup_data ( $ record );
114126
115127 // Verify our transaction with the Paystack API.
@@ -221,7 +233,6 @@ protected function update_payment_dates( $data ) {
221233 'result ' => 'failed ' ,
222234 ];
223235
224- $ customer_code = $ data ->customer ->customer_code ;
225236 $ amount_paid = $ data ->amount / 100 ;
226237 $ paystack_ref = $ data ->reference ;
227238 $ paid_at = $ data ->transaction_date ;
@@ -233,7 +244,7 @@ protected function update_payment_dates( $data ) {
233244 'amount ' => $ amount_paid ,
234245 'paid_at ' => $ paid_at ,
235246 ),
236- array ( ' txn_code ' => $ paystack_ref )
247+ array ( $ this -> txn_column => $ paystack_ref )
237248 );
238249 $ return = [
239250 'message ' => $ this ->meta ['successmsg ' ],
@@ -249,7 +260,7 @@ protected function update_payment_dates( $data ) {
249260 'amount ' => $ amount_paid ,
250261 'paid_at ' => $ paid_at ,
251262 ),
252- array ( ' txn_code ' => $ paystack_ref )
263+ array ( $ this -> txn_column => $ paystack_ref )
253264 );
254265 $ return = [
255266 'message ' => $ this ->meta ['successmsg ' ],
@@ -268,7 +279,7 @@ protected function update_payment_dates( $data ) {
268279 'paid ' => 1 ,
269280 'paid_at ' => $ paid_at ,
270281 ),
271- array ( ' txn_code ' => $ paystack_ref )
282+ array ( $ this -> txn_column => $ paystack_ref )
272283 );
273284 $ return = [
274285 'message ' => $ this ->meta ['successmsg ' ],
0 commit comments