| @@ -804,8 +804,138 @@ | ||
| 804 | 804 | // not support direct charges |
| 805 | 805 | } |
| 806 | 806 | |
| 807 | 807 | /** |
| 808 | + * Checks whether the payment method allows off-session capturing. | |
| 809 | + * | |
| 810 | + * @return boolean | |
| 811 | + * | |
| 812 | + * @since 10.1.63 | |
| 813 | + */ | |
| 814 | + public function isOffSessionCaptureSupported() | |
| 815 | + { | |
| 816 | + // not supported by default | |
| 817 | + return false; | |
| 818 | + } | |
| 819 | + | |
| 820 | + /** | |
| 821 | + * Performs the off-session capture transaction. | |
| 822 | + * | |
| 823 | + * This method triggers the ACTION below to manipulate the payment details | |
| 824 | + * before they are used to execute the capture: | |
| 825 | + * - payment_before_offsession_capture | |
| 826 | + * | |
| 827 | + * This method triggers the ACTION below to manipulate the | |
| 828 | + * response evaluated by the capture: | |
| 829 | + * - payment_after_offsession_capture | |
| 830 | + * | |
| 831 | + * @return mixed An object describing the status of the transaction. | |
| 832 | + * | |
| 833 | + * @uses isOffSessionCaptureSupported() | |
| 834 | + * @uses doOffSessionCapture() | |
| 835 | + * | |
| 836 | + * @since 10.1.63 | |
| 837 | + */ | |
| 838 | + public function offSessionCapture() | |
| 839 | + { | |
| 840 | + // make sure off-session capturing is supported | |
| 841 | + if (!$this->isOffSessionCaptureSupported()) | |
| 842 | + { | |
| 843 | + // not supported | |
| 844 | + throw new Exception('Off session capturing not supported', 405); | |
| 845 | + } | |
| 846 | + | |
| 847 | + $status = new JPaymentStatus(); | |
| 848 | + | |
| 849 | + /** | |
| 850 | + * Plugins can manipulate the properties of this object. | |
| 851 | + * Fires before the off-session capturing is made. | |
| 852 | + * Global hook accessible by any drivers. | |
| 853 | + * | |
| 854 | + * @param self A reference to this object. | |
| 855 | + * | |
| 856 | + * @since 10.1.63 | |
| 857 | + */ | |
| 858 | + do_action($this->getHook('payment_before_offsession_capture'), array($this)); | |
| 859 | + | |
| 860 | + /** | |
| 861 | + * Plugins can manipulate the properties of this object. | |
| 862 | + * Fires before the off-session capturing is made. | |
| 863 | + * Hook specific for the current driver. | |
| 864 | + * | |
| 865 | + * @param self A reference to this object. | |
| 866 | + * | |
| 867 | + * @since 10.1.63 | |
| 868 | + */ | |
| 869 | + do_action($this->getDriverHook('payment_before_offsession_capture'), array($this)); | |
| 870 | + | |
| 871 | + // children payments will perform the off-session capturing | |
| 872 | + $this->doOffSessionCapture($status); | |
| 873 | + | |
| 874 | + $response = null; | |
| 875 | + | |
| 876 | + /** | |
| 877 | + * Plugins can manipulate the response object to return. | |
| 878 | + * By filling the &$response variable, this method will return | |
| 879 | + * it instead of the default &$status one. | |
| 880 | + * Fires after completing the off-session capturing. | |
| 881 | + * Hook specific for the current driver. | |
| 882 | + * | |
| 883 | + * @param self A reference to this object. | |
| 884 | + * @param JPaymentStatus A reference to the status object. | |
| 885 | + * @param mixed A reference to the final response (null by default). | |
| 886 | + * | |
| 887 | + * @since 10.1.63 | |
| 888 | + */ | |
| 889 | + do_action_ref_array($this->getDriverHook('payment_after_offsession_capture'), array($this, $status, &$response)); | |
| 890 | + | |
| 891 | + /** | |
| 892 | + * Plugins can manipulate the response object to return. | |
| 893 | + * By filling the &$response variable, this method will return | |
| 894 | + * it instead of the default &$status one. | |
| 895 | + * Fires after completing the off-session capturing. | |
| 896 | + * Global hook accessible by any drivers. | |
| 897 | + * | |
| 898 | + * @param self A reference to this object. | |
| 899 | + * @param JPaymentStatus A reference to the status object. | |
| 900 | + * @param mixed A reference to the final response (null by default). | |
| 901 | + * | |
| 902 | + * @since 10.1.63 | |
| 903 | + */ | |
| 904 | + do_action_ref_array($this->getHook('payment_after_offsession_capture'), array($this, $status, &$response)); | |
| 905 | + | |
| 906 | + if (is_null($response)) | |
| 907 | + { | |
| 908 | + // no hook fired, the response will be equal to the status object | |
| 909 | + $response = $status; | |
| 910 | + } | |
| 911 | + | |
| 912 | + return $response; | |
| 913 | + } | |
| 914 | + | |
| 915 | + /** | |
| 916 | + * Off-session capturing implementor. | |
| 917 | + * Children classes can inherit this method to use the API of the | |
| 918 | + * payment in order to perform an off-session capturing. | |
| 919 | + * | |
| 920 | + * @param JPaymentStatus $status The status object. In case the capturing was | |
| 921 | + * successful, you should invoke: $status->verified(). | |
| 922 | + * | |
| 923 | + * @return void | |
| 924 | + * | |
| 925 | + * @see JPaymentStatus | |
| 926 | + * | |
| 927 | + * @see Visibility must be public. | |
| 928 | + * | |
| 929 | + * @since 10.1.63 | |
| 930 | + */ | |
| 931 | + public function doOffSessionCapture(JPaymentStatus $status) | |
| 932 | + { | |
| 933 | + // do nothing as a plugin may | |
| 934 | + // not support off-session capturing | |
| 935 | + } | |
| 936 | + | |
| 937 | + /** | |
| 808 | 938 | * Returns the final hook that will be used for actions |
| 809 | 939 | * and filters. This hook can be accessed by any plugin. |
| 810 | 940 | * |
| 811 | 941 | * @param string $hook The base hook. |