unicodeveloper / laravel-paystack

:credit_card: :package: :moneybag: Laravel 6, 7, 8, 9, 10 and 11 Package for Paystack
https://paystack.co
MIT License
597 stars 310 forks source link

Modified makePaymentRequest to accept multiple metadata as different inputs #94

Closed meshmmanuel closed 4 years ago

meshmmanuel commented 4 years ago

I wanted to populate the metadata input dynamically with more than one data using ajax and input id. I noticed the input below would be easier to accept multiple input.

<input type="hidden" id="meta..." name="custom_metadata[key]" value="value">

instead of this:

<input type="hidden" name="metadata" value="{{ json_encode($array = ['key_name' => 'value',]) }}" >

For example:

<input type="hidden" id="meta..." name="custom_metadata[key1]" value="value1">
<input type="hidden" id="meta..." name="custom_metadata[key2]" value="value2">

Would be passed to PHP as: array:2 [▼ "key1" => "value1" "key2" => "value2" ]

and when encoded as json, would be: "{"key1":"value1","key2":"value2"}"

achieving the same thing.