| @@ -12,109 +12,109 @@ | ||
| 12 | 12 | */ | 
| 13 | 13 |  class GetPaid_Payment_Form_Submission_Fees { | 
| 14 | 14 | |
| 15 | - /** | |
| 16 | - * The fee validation error. | |
| 17 | - * @var string | |
| 18 | - */ | |
| 19 | - public $fee_error; | |
| 20 | - | |
| 21 | - /** | |
| 22 | - * Submission fees. | |
| 23 | - * @var array | |
| 24 | - */ | |
| 25 | - public $fees = array(); | |
| 15 | + /** | |
| 16 | + * The fee validation error. | |
| 17 | + * @var string | |
| 18 | + */ | |
| 19 | + public $fee_error; | |
| 20 | + | |
| 21 | + /** | |
| 22 | + * Submission fees. | |
| 23 | + * @var array | |
| 24 | + */ | |
| 25 | + public $fees = array(); | |
| 26 | + | |
| 27 | + /** | |
| 28 | + * Class constructor | |
| 29 | + * | |
| 30 | + * @param GetPaid_Payment_Form_Submission $submission | |
| 31 | + */ | |
| 32 | +    public function __construct( $submission ) { | |
| 33 | + | |
| 34 | + // Process any existing invoice fees. | |
| 35 | +        if ( $submission->has_invoice() ) { | |
| 36 | + $this->fees = $submission->get_invoice()->get_fees(); | |
| 37 | + } | |
| 38 | + | |
| 39 | + // Process price fields. | |
| 40 | + $data = $submission->get_data(); | |
| 41 | + $payment_form = $submission->get_payment_form(); | |
| 42 | + | |
| 43 | +        foreach ( $payment_form->get_elements() as $element ) { | |
| 44 | + | |
| 45 | +            if ( 'price_input' == $element['type'] ) { | |
| 46 | + $this->process_price_input( $element, $data, $submission ); | |
| 47 | + } | |
| 48 | + | |
| 49 | +            if ( 'price_select' == $element['type'] ) { | |
| 50 | + $this->process_price_select( $element, $data ); | |
| 51 | + } | |
| 52 | + | |
| 53 | + } | |
| 54 | + | |
| 55 | + } | |
| 56 | + | |
| 57 | + /** | |
| 58 | + * Process a price input field. | |
| 59 | + * | |
| 60 | + * @param array $element | |
| 61 | + * @param array $data | |
| 62 | + * @param GetPaid_Payment_Form_Submission $submission | |
| 63 | + */ | |
| 64 | +    public function process_price_input( $element, $data, $submission ) { | |
| 65 | + | |
| 66 | + // Abort if not passed. | |
| 67 | +        if ( empty( $data[ $element['id'] ] ) ) { | |
| 68 | + return; | |
| 69 | + } | |
| 70 | + | |
| 71 | + $amount = (float) wpinv_sanitize_amount( $data[ $element['id'] ] ); | |
| 72 | + $minimum = empty( $element['minimum'] ) ? 0 : (float) wpinv_sanitize_amount( $element['minimum'] ); | |
| 73 | + | |
| 74 | +        if ( $amount < $minimum ) { | |
| 75 | + throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), wpinv_price( $minimum, $submission->get_currency() ) ) ); | |
| 76 | + } | |
| 77 | + | |
| 78 | + $this->fees[ $element['label'] ] = array( | |
| 79 | + 'name' => $element['label'], | |
| 80 | + 'initial_fee' => $amount, | |
| 81 | + 'recurring_fee' => 0, | |
| 82 | + ); | |
| 83 | + | |
| 84 | + } | |
| 26 | 85 | |
| 27 | 86 | /** | 
| 28 | - * Class constructor | |
| 29 | - * | |
| 30 | - * @param GetPaid_Payment_Form_Submission $submission | |
| 31 | - */ | |
| 32 | -	public function __construct( $submission ) { | |
| 33 | - | |
| 34 | - // Process any existing invoice fees. | |
| 35 | -		if ( $submission->has_invoice() ) { | |
| 36 | - $this->fees = $submission->get_invoice()->get_fees(); | |
| 37 | - } | |
| 38 | - | |
| 39 | - // Process price fields. | |
| 40 | - $data = $submission->get_data(); | |
| 41 | - $payment_form = $submission->get_payment_form(); | |
| 42 | - | |
| 43 | -		foreach ( $payment_form->get_elements() as $element ) { | |
| 44 | - | |
| 45 | -			if ( 'price_input' == $element['type'] ) { | |
| 46 | - $this->process_price_input( $element, $data, $submission ); | |
| 47 | - } | |
| 48 | - | |
| 49 | -			if ( 'price_select' == $element['type'] ) { | |
| 50 | - $this->process_price_select( $element, $data ); | |
| 51 | - } | |
| 52 | - | |
| 53 | - } | |
| 54 | - | |
| 55 | - } | |
| 56 | - | |
| 57 | - /** | |
| 58 | - * Process a price input field. | |
| 59 | - * | |
| 60 | - * @param array $element | |
| 61 | - * @param array $data | |
| 62 | - * @param GetPaid_Payment_Form_Submission $submission | |
| 63 | - */ | |
| 64 | -	public function process_price_input( $element, $data, $submission ) { | |
| 65 | - | |
| 66 | - // Abort if not passed. | |
| 67 | -		if ( empty( $data[ $element['id'] ] ) ) { | |
| 68 | - return; | |
| 69 | - } | |
| 70 | - | |
| 71 | - $amount = (float) wpinv_sanitize_amount( $data[ $element['id'] ] ); | |
| 72 | - $minimum = empty( $element['minimum'] ) ? 0 : (float) wpinv_sanitize_amount( $element['minimum'] ); | |
| 73 | - | |
| 74 | -		if ( $amount < $minimum ) { | |
| 75 | - throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), wpinv_price( $minimum, $submission->get_currency() ) ) ); | |
| 76 | - } | |
| 77 | - | |
| 78 | - $this->fees[ $element['label'] ] = array( | |
| 79 | - 'name' => $element['label'], | |
| 80 | - 'initial_fee' => $amount, | |
| 81 | - 'recurring_fee' => 0, | |
| 82 | - ); | |
| 83 | - | |
| 84 | - } | |
| 85 | - | |
| 86 | - /** | |
| 87 | - * Process a price select field. | |
| 88 | - * | |
| 89 | - * @param array $element | |
| 90 | - * @param array $data | |
| 91 | - */ | |
| 92 | -	public function process_price_select( $element, $data ) { | |
| 93 | - | |
| 94 | - // Abort if not passed. | |
| 95 | -		if ( empty( $data[ $element['id'] ] ) ) { | |
| 96 | - return; | |
| 97 | - } | |
| 98 | - | |
| 99 | - $options = getpaid_convert_price_string_to_options( $element['options'] ); | |
| 100 | - $selected = wpinv_parse_list( $data[ $element['id'] ] ); | |
| 101 | - $total = 0; | |
| 102 | - | |
| 103 | -		foreach ( $selected as $price ) { | |
| 104 | - | |
| 105 | -			if ( ! isset( $options[ $price ] ) ) { | |
| 106 | - throw new Exception( __( 'You have selected an invalid amount', 'invoicing' ) ); | |
| 107 | - } | |
| 108 | - | |
| 109 | - $total += (float) wpinv_sanitize_amount( $price ); | |
| 110 | - } | |
| 111 | - | |
| 112 | - $this->fees[ $element['label'] ] = array( | |
| 113 | - 'name' => $element['label'], | |
| 114 | - 'initial_fee' => $total, | |
| 115 | - 'recurring_fee' => 0, | |
| 116 | - ); | |
| 117 | - | |
| 118 | - } | |
| 87 | + * Process a price select field. | |
| 88 | + * | |
| 89 | + * @param array $element | |
| 90 | + * @param array $data | |
| 91 | + */ | |
| 92 | +    public function process_price_select( $element, $data ) { | |
| 93 | + | |
| 94 | + // Abort if not passed. | |
| 95 | +        if ( empty( $data[ $element['id'] ] ) ) { | |
| 96 | + return; | |
| 97 | + } | |
| 98 | + | |
| 99 | + $options = getpaid_convert_price_string_to_options( $element['options'] ); | |
| 100 | + $selected = wpinv_parse_list( $data[ $element['id'] ] ); | |
| 101 | + $total = 0; | |
| 102 | + | |
| 103 | +        foreach ( $selected as $price ) { | |
| 104 | + | |
| 105 | +            if ( ! isset( $options[ $price ] ) ) { | |
| 106 | + throw new Exception( __( 'You have selected an invalid amount', 'invoicing' ) ); | |
| 107 | + } | |
| 108 | + | |
| 109 | + $total += (float) wpinv_sanitize_amount( $price ); | |
| 110 | + } | |
| 111 | + | |
| 112 | + $this->fees[ $element['label'] ] = array( | |
| 113 | + 'name' => $element['label'], | |
| 114 | + 'initial_fee' => $total, | |
| 115 | + 'recurring_fee' => 0, | |
| 116 | + ); | |
| 117 | + | |
| 118 | + } | |
| 119 | 119 | |
| 120 | 120 | } | 
| @@ -4,7 +4,7 @@ discard block | ||
| 4 | 4 | * | 
| 5 | 5 | */ | 
| 6 | 6 | |
| 7 | -defined( 'ABSPATH' ) || exit; | |
| 7 | +defined('ABSPATH') || exit; | |
| 8 | 8 | |
| 9 | 9 | /** | 
| 10 | 10 | * Payment form submission fees class | 
| @@ -29,10 +29,10 @@ discard block | ||
| 29 | 29 | * | 
| 30 | 30 | * @param GetPaid_Payment_Form_Submission $submission | 
| 31 | 31 | */ | 
| 32 | -	public function __construct( $submission ) { | |
| 32 | +	public function __construct($submission) { | |
| 33 | 33 | |
| 34 | 34 | // Process any existing invoice fees. | 
| 35 | -		if ( $submission->has_invoice() ) { | |
| 35 | +		if ($submission->has_invoice()) { | |
| 36 | 36 | $this->fees = $submission->get_invoice()->get_fees(); | 
| 37 | 37 | } | 
| 38 | 38 | |
| @@ -40,14 +40,14 @@ discard block | ||
| 40 | 40 | $data = $submission->get_data(); | 
| 41 | 41 | $payment_form = $submission->get_payment_form(); | 
| 42 | 42 | |
| 43 | -		foreach ( $payment_form->get_elements() as $element ) { | |
| 43 | +		foreach ($payment_form->get_elements() as $element) { | |
| 44 | 44 | |
| 45 | -			if ( 'price_input' == $element['type'] ) { | |
| 46 | - $this->process_price_input( $element, $data, $submission ); | |
| 45 | +			if ('price_input' == $element['type']) { | |
| 46 | + $this->process_price_input($element, $data, $submission); | |
| 47 | 47 | } | 
| 48 | 48 | |
| 49 | -			if ( 'price_select' == $element['type'] ) { | |
| 50 | - $this->process_price_select( $element, $data ); | |
| 49 | +			if ('price_select' == $element['type']) { | |
| 50 | + $this->process_price_select($element, $data); | |
| 51 | 51 | } | 
| 52 | 52 | |
| 53 | 53 | } | 
| @@ -61,21 +61,21 @@ discard block | ||
| 61 | 61 | * @param array $data | 
| 62 | 62 | * @param GetPaid_Payment_Form_Submission $submission | 
| 63 | 63 | */ | 
| 64 | -	public function process_price_input( $element, $data, $submission ) { | |
| 64 | +	public function process_price_input($element, $data, $submission) { | |
| 65 | 65 | |
| 66 | 66 | // Abort if not passed. | 
| 67 | -		if ( empty( $data[ $element['id'] ] ) ) { | |
| 67 | +		if (empty($data[$element['id']])) { | |
| 68 | 68 | return; | 
| 69 | 69 | } | 
| 70 | 70 | |
| 71 | - $amount = (float) wpinv_sanitize_amount( $data[ $element['id'] ] ); | |
| 72 | - $minimum = empty( $element['minimum'] ) ? 0 : (float) wpinv_sanitize_amount( $element['minimum'] ); | |
| 71 | + $amount = (float) wpinv_sanitize_amount($data[$element['id']]); | |
| 72 | + $minimum = empty($element['minimum']) ? 0 : (float) wpinv_sanitize_amount($element['minimum']); | |
| 73 | 73 | |
| 74 | -		if ( $amount < $minimum ) { | |
| 75 | - throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), wpinv_price( $minimum, $submission->get_currency() ) ) ); | |
| 74 | +		if ($amount < $minimum) { | |
| 75 | +			throw new Exception(sprintf(__('The minimum allowed amount is %s', 'invoicing'), wpinv_price($minimum, $submission->get_currency()))); | |
| 76 | 76 | } | 
| 77 | 77 | |
| 78 | - $this->fees[ $element['label'] ] = array( | |
| 78 | + $this->fees[$element['label']] = array( | |
| 79 | 79 | 'name' => $element['label'], | 
| 80 | 80 | 'initial_fee' => $amount, | 
| 81 | 81 | 'recurring_fee' => 0, | 
| @@ -89,27 +89,27 @@ discard block | ||
| 89 | 89 | * @param array $element | 
| 90 | 90 | * @param array $data | 
| 91 | 91 | */ | 
| 92 | -	public function process_price_select( $element, $data ) { | |
| 92 | +	public function process_price_select($element, $data) { | |
| 93 | 93 | |
| 94 | 94 | // Abort if not passed. | 
| 95 | -		if ( empty( $data[ $element['id'] ] ) ) { | |
| 95 | +		if (empty($data[$element['id']])) { | |
| 96 | 96 | return; | 
| 97 | 97 | } | 
| 98 | 98 | |
| 99 | - $options = getpaid_convert_price_string_to_options( $element['options'] ); | |
| 100 | - $selected = wpinv_parse_list( $data[ $element['id'] ] ); | |
| 99 | + $options = getpaid_convert_price_string_to_options($element['options']); | |
| 100 | + $selected = wpinv_parse_list($data[$element['id']]); | |
| 101 | 101 | $total = 0; | 
| 102 | 102 | |
| 103 | -		foreach ( $selected as $price ) { | |
| 103 | +		foreach ($selected as $price) { | |
| 104 | 104 | |
| 105 | -			if ( ! isset( $options[ $price ] ) ) { | |
| 106 | - throw new Exception( __( 'You have selected an invalid amount', 'invoicing' ) ); | |
| 105 | +			if (!isset($options[$price])) { | |
| 106 | +				throw new Exception(__('You have selected an invalid amount', 'invoicing')); | |
| 107 | 107 | } | 
| 108 | 108 | |
| 109 | - $total += (float) wpinv_sanitize_amount( $price ); | |
| 109 | + $total += (float) wpinv_sanitize_amount($price); | |
| 110 | 110 | } | 
| 111 | 111 | |
| 112 | - $this->fees[ $element['label'] ] = array( | |
| 112 | + $this->fees[$element['label']] = array( | |
| 113 | 113 | 'name' => $element['label'], | 
| 114 | 114 | 'initial_fee' => $total, | 
| 115 | 115 | 'recurring_fee' => 0, |