Support

Home Forums Event Espresso Premium Billing_Info question

Billing_Info question

Posted: March 18, 2024 at 9:17 pm

Viewing 1 reply thread


zorrove

March 18, 2024 at 9:17 pm

I’m developing a new custom payment method. I have created my billing info form with a form field tye select this way

‘bank_name’ => new EE_Select_Input(
array(
” => ”,
‘0156’ => ‘100%Banco’,
‘0196’ => ‘Abn Amrg Bank’)

When the fuction doDirectPayment is called i get the form inpunt value this way

$billing_info[ ‘bank_name’ ]

but i get labeled name and not the option-value

I debug the $billing_var and this is what i get

array(6) { [“bank_name”]=> string(36) “Abn Amrg Bank” [“phone_payer_code”]=> string(3) “414” [“phone_payer”]=> string(7) “1600818” [“transfer_date”]=> string(10) “2024-03-19” [“transfer_id”]=> string(6) “123456” [“amount_paid”]=> float(2895.2) }

i want this element [“bank_name”]=> string(36) “Abn Amrg Bank” to be
[“bank_name”]=> string(4) “0196”

Cheers,


Brent Christensen

  • Support Staff

March 28, 2024 at 10:44 am

Hi zorrove,

I’m Event Espresso’s lead developer, my apologies for the delay getting back to you.

Unfortunately it looks like that portion of our payments system was designed to return the display values for inputs and not the values since we are only interested in the user supplied data for most billing form questions.

Here’s what I would do to solve this problem:


class YourPaymentMethod
{
    public static function bankOptions(): array
    {
        return [
            '' => '',
            '0156' => '100%Banco',
            '0196' => 'Abn Amrg Bank',
        ];
    }

    public function yourPaymentForm()
    {
        // other code

        'bank_name' => new EE_Select_Input(YourPaymentMethod::bankOptions()),

        // other code
    }

    public static function selectedBank(string $bank_name): string
    {
        $banks = array_reverse(YourPaymentMethod::bankOptions(), true);
        return $banks[$bank_name] ?? '';
    }

    public function do_direct_payment($payment, $billing_info = null) {
        $bank_name = $billing_info['bank_name'];
        $selected_bank = YourPaymentMethod::selectedBank($bank_name);

        // other code
    }
}

I’ve just thrown everything into one class but you should be able to move things around to where they make the most sense. But basically this is what the above code does:

  • Instead of hardcoding the bank IDs and names into the array passed to EE_Select_Input we’ve moved that into a static function named bankOptions() which returns an array with that data in it.
  • Then in your payment form, just call bankOptions() within the EE_Select_Input contructor to get your options.
  • When do_direct_payment() is called, retrieve the bank name from the $billing_info array and pass it to selectedBank() to get the ID for the selected bank.

Hope that helps, let us know how it goes.

Viewing 1 reply thread

The support post ‘Billing_Info question’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso