-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue in gateways with METHOD_HTML_FORM redirection method, if multidimensional is passed. #73
Comments
You want to pass in a an array like: return [
'key_id' => 'YOUR_KEY_ID',
'amount' => '1001',
'order_id' => 'razorpay_order_id',
'name' => 'Acme Corp',
'description' => 'A Wild Sheep Chase',
'image' => 'https://cdn.razorpay.com/logos/BUVwvgaqVByGp2_large.jpg',
'prefill' => [
'name' => 'Gaurav Kumar',
'contact' => '9123456780',
'email' => '[email protected]',
],
'notes' => [
'shipping address' => 'L-16, The Business Centre, 61 Wellfield Road, New Delhi - 110001',
],
'callback_url' => 'https://example.com/payment-callback',
'cancel_url' => 'https://example.com/payment-cancel',
]; You can just build a flat array? return [
'key_id' => 'YOUR_KEY_ID',
'amount' => '1001',
'order_id' => 'razorpay_order_id',
'name' => 'Acme Corp',
'description' => 'A Wild Sheep Chase',
'image' => 'https://cdn.razorpay.com/logos/BUVwvgaqVByGp2_large.jpg',
'prefill[name]' => 'Gaurav Kumar',
'prefill[contact]' => '9123456780',
'prefill[email]' => '[email protected]',
'notes[shipping address]' => 'L-16, The Business Centre, 61 Wellfield Road, New Delhi - 110001',
'callback_url' => 'https://example.com/payment-callback',
'cancel_url' => 'https://example.com/payment-cancel',
]; We could implement support for multidimensional arrays, we don't really need this ourselves, so maybe this should remain gateway territory? https://www.php.net/manual/en/function.http-build-query.php Solution with
|
Yes, I need to pass an array like the first one in post form.
Yes, need to pass a flat array like the one you provided. The first array is getting used for another purpose also. So, developing a second array directly is not possible. Either I will have to convert the normal array to a flat array within the
Yes, this function is good for creating query strings.
Thanks for the suggestion, I will try to use this also. What do you think, I should handle this within gateway or you can include it in wp-pay-core also? |
I think we could include this in the core library, it might be useful if this works like for example like the
function flat( $data, $parent = '', $result = [] ) {
foreach ( $data as $key => $item ) {
if ( '' !== $parent ) {
$key = $parent . '[' . $key . ']';
}
if ( is_array( $item ) ) {
$result = flat( $item, $key, $result );
} else {
$result[ $key ] = $item;
}
}
return $result;
}
var_dump( flat( $data ) ); |
Naming helper function, perhaps like private static function array_square_bracket( $data, $parent = '', $result = [] ) {
foreach ( $data as $key => $item ) {
if ( '' !== $parent ) {
$key = $parent . '[' . $key . ']';
}
if ( is_array( $item ) ) {
$result = self::array_square_bracket( $item, $key, $result );
} else {
$result[ $key ] = $item;
}
}
return $result;
} |
…)` method (#76). * Add support for multi-dimensional array in `Util::html_hidden_fields( $data )` method. #73 Co-authored-by: Reüel van der Steege <[email protected]>
The below code fails if we pass a multidimensional array to
html_hidden_fields
function.wp-pay-core/src/Util.php
Lines 211 to 213 in ecb3e11
In Some payment gateways, data is passed as multidimensional array. See example below
https://razorpay.com/docs/payments/payment-gateway/web-integration/hosted/build-integration/#code-to-add-pay-button
Here field
prefill[name]
is creating an issue.Before running the loop, if we will call below function, issue will be fixed.
Do you have any better suggestion for the same?
The text was updated successfully, but these errors were encountered: