| @@ -438,9 +438,9 @@ | ||
| 438 | 438 | * @param array $metadata |
| 439 | 439 | * |
| 440 | 440 | * @return void |
| 441 | 441 | */ |
| 442 | - public static function save_transaction_metadata($order, $metadata) | |
| 442 | + public static function save_transaction_metadata($order, $metadata): void | |
| 443 | 443 | { |
| 444 | 444 | if (self::is_pre_30()) { |
| 445 | 445 | update_post_meta($order->id, '_payplug_metadata', $metadata); |
| 446 | 446 | } else { |
| @@ -457,9 +457,9 @@ | ||
| 457 | 457 | * @param bool $flag |
| 458 | 458 | * |
| 459 | 459 | * @return void |
| 460 | 460 | */ |
| 461 | - public static function set_flag_ipn_order($order, $metadata, $flag) | |
| 461 | + public static function set_flag_ipn_order($order, $metadata, $flag): void | |
| 462 | 462 | { |
| 463 | 463 | $metadata['transaction_in_progress'] = $flag; |
| 464 | 464 | self::save_transaction_metadata($order, $metadata); |
| 465 | 465 | } |
| @@ -558,34 +558,18 @@ | ||
| 558 | 558 | if (empty($options) || !isset($options['api_key']) || !isset($options['jwt'])) { |
| 559 | 559 | return []; |
| 560 | 560 | } |
| 561 | 561 | |
| 562 | - $api_key = json_decode($options['api_key'], true); | |
| 563 | - $jwt = json_decode($options['jwt'], true); | |
| 562 | + // get_bearer_token() refreshes the JWT if it's close to expiry (OAuth2 accounts). | |
| 563 | + $mode = (bool) $options['mode'] ? 'live' : 'test'; | |
| 564 | + $key = (string) $helper->get_api()->get_bearer_token($mode); | |
| 564 | 565 | |
| 565 | - $test_key = !empty($api_key['test']) ? $api_key['test'] : ''; | |
| 566 | - $live_key = !empty($api_key['live']) ? $api_key['live'] : ''; | |
| 567 | - | |
| 568 | - if (empty($test_key) && isset($jwt['test']['access_token'])) { | |
| 569 | - $test_key = $jwt['test']['access_token']; | |
| 570 | - } | |
| 571 | - if (empty($live_key) && isset($jwt['live']['access_token'])) { | |
| 572 | - $live_key = $jwt['live']['access_token']; | |
| 573 | - } | |
| 574 | - if (empty($test_key) && empty($live_key)) { | |
| 566 | + if (empty($key)) { | |
| 575 | 567 | return []; |
| 576 | 568 | } |
| 577 | 569 | |
| 578 | - if ((bool) $options['mode'] && empty($live_key)) { | |
| 579 | - return []; | |
| 580 | - } | |
| 581 | - | |
| 582 | - if (!(bool) $options['mode'] && empty($test_key)) { | |
| 583 | - return []; | |
| 584 | - } | |
| 585 | - | |
| 586 | 570 | try { |
| 587 | - $parameters_account = Authentication::getAccount(new Payplug((bool) $options['mode'] ? $live_key : $test_key)); | |
| 571 | + $parameters_account = Authentication::getAccount(new Payplug($key)); | |
| 588 | 572 | self::set_transient_data($parameters_account, $options); |
| 589 | 573 | } catch (\Payplug\Exception\UnauthorizedException $e) { |
| 590 | 574 | self::exception_handler_400_logout($e->getCode(), __('payplug_enable_feature', 'payplug'), sprintf('Account request error from PayPlug API : %s <br><b> ' . __('Successfully logged out.', 'payplug') . '</b>', wc_print_r($e->getMessage(), true))); |
| 591 | 575 | } catch (\Payplug\Exception\ConfigurationNotSetException $e) { |
| @@ -595,26 +579,8 @@ | ||
| 595 | 579 | } |
| 596 | 580 | } |
| 597 | 581 | |
| 598 | 582 | /** |
| 599 | - * Get min and max for oney payment | |
| 600 | - * | |
| 601 | - * @return array | |
| 602 | - */ | |
| 603 | - public static function get_min_max_oney() | |
| 604 | - { | |
| 605 | - $account = self::get_account_data_from_options(); | |
| 606 | - if (!$account) { | |
| 607 | - return []; | |
| 608 | - } | |
| 609 | - | |
| 610 | - return [ | |
| 611 | - 'min' => floatval($account['configuration']['oney']['min_amounts']['EUR']) / 100, | |
| 612 | - 'max' => floatval($account['configuration']['oney']['max_amounts']['EUR']) / 100, | |
| 613 | - ]; | |
| 614 | - } | |
| 615 | - | |
| 616 | - /** | |
| 617 | 583 | * Check if oney is available with current settings |
| 618 | 584 | * |
| 619 | 585 | * @return bool |
| 620 | 586 | */ |
| @@ -678,25 +644,8 @@ | ||
| 678 | 644 | |
| 679 | 645 | return load_textdomain($domain, $path . '/' . $mofile); |
| 680 | 646 | } |
| 681 | 647 | |
| 682 | - /** | |
| 683 | - * Check and update value for oney simulation | |
| 684 | - * | |
| 685 | - * @return void | |
| 686 | - */ | |
| 687 | - public static function oney_simulation_values($keys_array, &$array) | |
| 688 | - { | |
| 689 | - foreach ($keys_array as $key) { | |
| 690 | - if (array_key_exists($key, $array)) { | |
| 691 | - $array[$key]['down_payment_amount'] = floatval($array[$key]['down_payment_amount']) / 100; | |
| 692 | - foreach ($array[$key]['installments'] as $k => $value) { | |
| 693 | - $array[$key]['installments'][$k]['amount'] = floatval($value['amount']) / 100; | |
| 694 | - } | |
| 695 | - } | |
| 696 | - } | |
| 697 | - } | |
| 698 | - | |
| 699 | 648 | public static function getISOCountryCode() |
| 700 | 649 | { |
| 701 | 650 | preg_match('([a-z-]+)', get_locale(), $country); |
| 702 | 651 | |
| @@ -777,26 +726,15 @@ | ||
| 777 | 726 | } |
| 778 | 727 | |
| 779 | 728 | public static function get_live_key() |
| 780 | 729 | { |
| 781 | - $options = self::get_payplug_options(); | |
| 782 | - $jwt = json_decode($options['jwt'], true); | |
| 783 | - $api_key = json_decode($options['api_key'], true); | |
| 784 | - | |
| 785 | - return isset($jwt['live']) && isset($jwt['live']['access_token']) | |
| 786 | - ? $jwt['live']['access_token'] | |
| 787 | - : $api_key['live']; | |
| 730 | + // get_bearer_token() refreshes the JWT if it's close to expiry (OAuth2 accounts). | |
| 731 | + return (new self())->get_api()->get_bearer_token('live'); | |
| 788 | 732 | } |
| 789 | 733 | |
| 790 | 734 | public static function get_test_key() |
| 791 | 735 | { |
| 792 | - $options = self::get_payplug_options(); | |
| 793 | - $jwt = json_decode($options['jwt'], true); | |
| 794 | - $api_key = json_decode($options['api_key'], true); | |
| 795 | - | |
| 796 | - return isset($jwt['test']) && isset($jwt['test']['access_token']) | |
| 797 | - ? $jwt['test']['access_token'] | |
| 798 | - : $api_key['test']; | |
| 736 | + return (new self())->get_api()->get_bearer_token('test'); | |
| 799 | 737 | } |
| 800 | 738 | |
| 801 | 739 | public static function check_mode() |
| 802 | 740 | { |
| @@ -802,16 +740,42 @@ | ||
| 802 | 740 | { |
| 803 | 741 | return self::get_payplug_options()['mode']; |
| 804 | 742 | } |
| 805 | 743 | |
| 806 | - public static function payplug_logout() | |
| 744 | + /** | |
| 745 | + * Domain the Integrated Payment SDK should submit card-tokenization requests to. Depends | |
| 746 | + * on whether the connected merchant account is QA or production, which is a build-time | |
| 747 | + * distinction (see SECURE_DOMAIN in payplug-config.php), not something this can derive | |
| 748 | + * from the Test/Live mode toggle at runtime. | |
| 749 | + * | |
| 750 | + * @return string | |
| 751 | + */ | |
| 752 | + public static function get_secure_domain(): string | |
| 807 | 753 | { |
| 754 | + return SECURE_DOMAIN; | |
| 755 | + } | |
| 756 | + | |
| 757 | + /** | |
| 758 | + * URL of the official Oney widget loader script. Depends on whether the connected | |
| 759 | + * merchant account is QA or production, which is a build-time distinction (see | |
| 760 | + * ONEY_LOADER_URL in payplug-config.php), not something this can derive from the | |
| 761 | + * Test/Live mode toggle at runtime. | |
| 762 | + * | |
| 763 | + * @return string | |
| 764 | + */ | |
| 765 | + public static function get_oney_loader_url(): string | |
| 766 | + { | |
| 767 | + return ONEY_LOADER_URL; | |
| 768 | + } | |
| 769 | + | |
| 770 | + public static function payplug_logout(): void | |
| 771 | + { | |
| 808 | 772 | $helper = new self(); |
| 809 | 773 | $helper->get_service('configuration')->clean_option(); |
| 810 | 774 | set_transient(self::get_transient_key(self::get_payplug_options()), null); |
| 811 | 775 | } |
| 812 | 776 | |
| 813 | - public static function plugin_deactivation() | |
| 777 | + public static function plugin_deactivation(): void | |
| 814 | 778 | { |
| 815 | 779 | $option_name = 'woocommerce_payplug_settings'; |
| 816 | 780 | delete_option($option_name); |
| 817 | 781 | // for site options in Multisite |