Changeset 3228622
- Timestamp:
- 01/26/2025 12:50:04 AM (14 months ago)
- File:
-
- 1 edited
-
payaza/trunk/includes/class-wc-gateway-payaza.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
payaza/trunk/includes/class-wc-gateway-payaza.php
r3199420 r3228622 337 337 'default' => '', 338 338 ), 339 //'autocomplete_order' => array(340 //'title' => __( 'Autocomplete Order After Payment', 'woo-payaza' ),341 //'label' => __( 'Autocomplete Order', 'woo-payaza' ),342 //'type' => 'checkbox',343 //'class' => 'wc-payaza-autocomplete-order',344 //'description' => __( 'If enabled, the order will be marked as complete after successful payment', 'woo-payaza' ),345 //'default' => 'no',346 //'desc_tip' => true,347 //),339 'autocomplete_order' => array( 340 'title' => __( 'Autocomplete Order After Payment', 'woo-payaza' ), 341 'label' => __( 'Autocomplete Order', 'woo-payaza' ), 342 'type' => 'checkbox', 343 'class' => 'wc-payaza-autocomplete-order', 344 'description' => __( 'If enabled, the order will be marked as complete after successful payment', 'woo-payaza' ), 345 'default' => 'no', 346 'desc_tip' => true, 347 ), 348 348 'remove_cancel_order_button' => array( 349 349 'title' => __( 'Remove Cancel Order & Restore Cart Button', 'woo-payaza' ), … … 400 400 * Outputs scripts used for payaza payment. 401 401 */ 402 // public function payment_scripts() { 403 404 // if ( isset( $_GET['pay_for_order'] ) || ! is_checkout_pay_page() ) { 405 // return; 406 // } 407 408 // if ( $this->enabled === 'no' ) { 409 // return; 410 // } 411 412 // $order_key = isset( $_GET['key'] ) ? sanitize_text_field( wp_unslash( $_GET['key'] ) ) : ''; 413 // $order_id = absint( get_query_var( 'order-pay' ) ); 414 415 // $order = wc_get_order( $order_id ); 416 417 // if ( ! $order || $this->id !== $order->get_payment_method() ) { 418 // return; 419 // } 420 421 // $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; 422 423 // wp_enqueue_script( 'jquery' ); 424 // wp_enqueue_script( 'payaza', 'https://checkout-v2.payaza.africa/js/v1/bundle.js', array( 'jquery' ), WC_PAYAZA_VERSION, false ); 425 // wp_enqueue_script( 'wc_payaza', plugins_url( 'assets/js/payaza' . $suffix . '.js', WC_PAYAZA_MAIN_FILE ), array( 'jquery', 'payaza' ), WC_PAYAZA_VERSION, false ); 426 427 // $payaza_params = array( 428 // 'key' => $this->public_key, 429 // 'connection_mode' => $this->testmode ? 'Test' : 'Live', 430 // ); 431 // if ( is_checkout_pay_page() && get_query_var( 'order-pay' ) ) { 432 433 // $email = $order->get_billing_email(); 434 // $first_name = $order->get_billing_first_name(); 435 // $last_name = $order->get_billing_last_name(); 436 // $phone_number = $order->get_billing_phone(); 437 // $amount = $order->get_total() * 100; 438 // $txnref = $order_id . '_' . time(); 439 // $the_order_id = $order->get_id(); 440 // $the_order_key = $order->get_order_key(); 441 // $currency = $order->get_currency(); 442 443 444 445 // if ( $the_order_id == $order_id && $the_order_key == $order_key ) { 446 447 // $payaza_params['email'] = $email; 448 // $payaza_params['first_name'] = $first_name; 449 // $payaza_params['last_name'] = $last_name; 450 // $payaza_params['phone_number'] = $phone_number; 451 // $payaza_params['amount'] = $amount; 452 // $payaza_params['txnref'] = $txnref; 453 // $payaza_params['currency'] = $currency; 454 455 456 457 // } 458 459 460 461 // update_post_meta( $order_id, '_payaza_txn_ref', $txnref ); 462 // } 463 // wp_localize_script( 'wc_payaza', 'wc_payaza_params', $payaza_params ); 464 465 466 467 // } 468 402 469 public function payment_scripts() { 403 470 404 471 if ( isset( $_GET['pay_for_order'] ) || ! is_checkout_pay_page() ) { 405 472 return; … … 428 495 'key' => $this->public_key, 429 496 'connection_mode' => $this->testmode ? 'Test' : 'Live', 497 'thank_you_url' => wc_get_endpoint_url( 'order-received', '', wc_get_checkout_url() ), 498 430 499 ); 500 431 501 if ( is_checkout_pay_page() && get_query_var( 'order-pay' ) ) { 432 502 433 503 $email = $order->get_billing_email(); 434 504 $first_name = $order->get_billing_first_name(); … … 440 510 $the_order_key = $order->get_order_key(); 441 511 $currency = $order->get_currency(); 442 443 512 444 445 513 if ( $the_order_id == $order_id && $the_order_key == $order_key ) { 446 514 447 $payaza_params['email'] = $email; 448 $payaza_params['first_name'] = $first_name; 449 $payaza_params['last_name'] = $last_name; 450 $payaza_params['phone_number'] = $phone_number; 451 $payaza_params['amount'] = $amount; 452 $payaza_params['txnref'] = $txnref; 515 // Additional parameters for the checkout payment page 516 $payaza_params['email'] = $email; 517 $payaza_params['first_name'] = $first_name; 518 $payaza_params['last_name'] = $last_name; 519 $payaza_params['phone_number'] = $phone_number; 520 $payaza_params['amount'] = absint( $amount ); 521 $payaza_params['txnref'] = $txnref; 453 522 $payaza_params['currency'] = $currency; 454 455 456 457 523 } 458 459 // $email = $order->get_billing_email(); 460 // $first_name = $order->get_billing_first_name(); 461 // $last_name = $order->get_billing_last_name(); 462 // $phone_number = $order->get_billing_phone(); 463 // $amount = $order->get_total() * 100; 464 // $txnref = $order_id . '_' . time(); 465 // $the_order_id = $order->get_id(); 466 // $the_order_key = $order->get_order_key(); 467 // $currency = $order->get_currency(); 468 469 // if ( $the_order_id == $order_id && $the_order_key == $order_key ) { 470 // $payaza_params['email'] = $email; 471 // $payaza_params['first_name'] = $first_name; 472 // $payaza_params['last_name'] = $last_name; 473 // $payaza_params['phone_number'] = $phone_number; 474 // $payaza_params['amount'] = absint( $amount ); 475 // $payaza_params['txnref'] = $txnref; 476 // $payaza_params['currency'] = $currency; 477 // } 478 479 update_post_meta( $order_id, '_payaza_txn_ref', $txnref ); 480 } 524 525 526 527 528 $order->update_meta_data( '_paystack_txn_ref', $txnref ); 529 $order->save(); 530 531 } 481 532 wp_localize_script( 'wc_payaza', 'wc_payaza_params', $payaza_params ); 482 483 // Simulate payment success for testing. Replace with actual payment success check. 484 //$payment_success = true; 485 486 //if ( $payment_success ) { 487 // $order->payment_complete( $txnref ); 488 // $order->add_order_note( sprintf( __( 'Payment via Payaza successful (Transaction Reference: %s)', 'woo-payaza' ), $txnref ) ); 489 490 // if ( $this->is_autocomplete_order_enabled( $order ) ) { 491 // $order->update_status( 'completed' ); 492 //} 493 // WC()->cart->empty_cart(); 494 // function_exists( 'wc_reduce_stock_levels' ) ? wc_reduce_stock_levels( $order_id ) : $order->reduce_order_stock(); 495 //} else { 496 // $order->update_status( 'on-hold', __( 'Payment is pending. Please confirm payment with Payaza.', 'woo-payaza' ) ); 497 //} 498 499 // Redirect to the WooCommerce "Thank You" page 500 //return array( 501 // 'result' => 'success', 502 // 'redirect' => $order->get_checkout_payment_url(true), 503 //); 504 } 505 506 507 533 } 534 535 536 508 537 509 538 … … 527 556 528 557 wp_localize_script( 'wc_payaza_admin', 'wc_payaza_admin_params', $payaza_admin_params ); 529 558 530 559 } 531 560 … … 538 567 * @return array|void 539 568 */ 540 public function process_payment( $order_id ) { 541 $payment_token = 'wc-' . trim( $this->id ) . '-payment-token'; 542 543 544 if ( isset( $_POST[ $payment_token ] ) && 'new' !== wc_clean( $_POST[ $payment_token ] ) ) { 545 546 $token_id = wc_clean( $_POST[ $payment_token ] ); 547 $token = \WC_Payment_Tokens::get( $token_id ); 548 549 if ( $token->get_user_id() !== get_current_user_id() ) { 550 551 wc_add_notice( 'Invalid token ID', 'error' ); 552 553 return; 554 } 555 556 $token_payment_status = $this->process_token_payment( $token->get_token(), $order_id ); 557 558 if ( ! $token_payment_status ) { 559 return; 560 } 561 562 $order = wc_get_order( $order_id ); 563 569 function process_payment( $order_id ) { 570 global $woocommerce; 571 $order = new WC_Order( $order_id ); 572 573 574 ///$order->payment_complete(); 575 576 // Remove cart 577 $woocommerce->cart->empty_cart(); 578 579 // Return thankyou redirect 564 580 return array( 565 'result' => 'success',566 'redirect' => $ this->get_return_url( $order),581 'result' => 'success', 582 'redirect' => $order->get_checkout_payment_url( true ), 567 583 ); 568 } 569 570 $order = wc_get_order( $order_id ); 571 572 $new_payment_method = 'wc-' . trim( $this->id ) . '-new-payment-method'; 573 574 // phpcs:ignore WordPress.Security.NonceVerification 575 if ( isset( $_POST[ $new_payment_method ] ) && ( true === (bool) $_POST[ $new_payment_method ] && $this->saved_cards ) && is_user_logged_in() ) { 576 577 $order->update_meta_data( '_wc_payaza_save_card', true ); 578 579 $order->save(); 580 } 581 582 583 584 return array( 585 'result' => 'success', 586 'redirect' => $order->get_checkout_payment_url( true ), 587 ); 588 589 } 590 591 592 593 584 585 } 586 587 588 589 590 // public function process_payment( $order_id ) { 591 // $payment_token = 'wc-' . trim( $this->id ) . '-payment-token'; 592 593 // // // Check if a saved token is used for payment. 594 // if ( isset( $_POST[ $payment_token ] ) && 'new' !== wc_clean( $_POST[ $payment_token ] ) ) { 595 // $token_id = wc_clean( $_POST[ $payment_token ] ); 596 // $token = \WC_Payment_Tokens::get( $token_id ); 597 598 // // Verify token ownership. 599 // if ( $token->get_user_id() !== get_current_user_id() ) { 600 // wc_add_notice( 'Invalid token ID', 'error' ); 601 // return; 602 // } 603 604 // // Process payment with token. 605 // $token_payment_status = $this->process_token_payment( $token->get_token(), $order_id ); 606 607 // if ( ! $token_payment_status ) { 608 // return; 609 // } 610 611 // $order = wc_get_order( $order_id ); 612 613 // // Redirect to the receipt page after successful payment. 614 // return array( 615 // 'result' => 'success', 616 // 'redirect' => $this->get_return_url( $order ), 617 // //'redirect' => $order->get_checkout_payment_url( true ), 618 619 620 // ); 621 // } 622 623 // $order = wc_get_order( $order_id ); 624 // $new_payment_method = 'wc-' . trim( $this->id ) . '-new-payment-method'; 625 626 // // // Check if a new payment method is being saved. 627 // if ( isset( $_POST[ $new_payment_method ] ) && ( true === (bool) $_POST[ $new_payment_method ] ) && $this->saved_cards && is_user_logged_in() ) { 628 // $order->update_meta_data( '_wc_payaza_save_card', true ); 629 // $order->save(); 630 // } 631 632 // // Redirect to the receipt page. 633 // return array( 634 // 'result' => 'success', 635 // 'redirect' => $order->get_checkout_payment_url( true ), 636 // ); 637 // } 638 639 594 640 /** 595 641 * Show new card can only be added when placing an order notice.
Note: See TracChangeset
for help on using the changeset viewer.