Last active
October 25, 2024 10:06
-
-
Save rvdsteege/fd71c0a984a14de1375fcaffd85d6902 to your computer and use it in GitHub Desktop.
Update field in Gravity Forms entry with IBAN on successful payment with Pronamic Pay.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Gravity Forms - Update field in entry with IBAN / account number from Pronamic Pay payment. | |
* | |
* @link https://github.com/pronamic/wp-pronamic-pay-gravityforms/blob/2200b1e0d275f3207326e3fcbb925a5c2b16bc1d/src/Extension.php#L1057-L1067 | |
* | |
* @param array $entry Gravity Forms entry. | |
* @param \Pronamic\WordPress\Pay\Extensions\GravityForms\PayFeed $feed Payment feed. | |
*/ | |
function gform_ideal_fulfillment_update_entry( $entry, $feed ) { | |
// Set form and field ID you want to update with IBAN / account number. | |
$form_id = 2; | |
$field_id = 26; | |
// Check if we want to update for this form. | |
if ( $form_id !== (int) $entry['form_id'] ) { | |
return; | |
} | |
// Get Pronamic payment. | |
$payment_id = gform_get_meta( $entry['id'], 'pronamic_payment_id' ); | |
$payment = get_pronamic_payment( $payment_id ); | |
if ( null === $payment ) { | |
return; | |
} | |
$consumer_bank_details = $payment->get_consumer_bank_details(); | |
if ( null === $consumer_bank_details ) { | |
return; | |
} | |
// Use account number... | |
$consumer_account = $consumer_bank_details->get_account_number(); | |
if ( ! empty( $consumer_account ) ) { | |
$entry[ $field_id ] = $consumer_account; | |
} | |
// ...or IBAN. | |
$consumer_iban = $consumer_bank_details->get_iban(); | |
if ( ! empty( $consumer_iban ) ) { | |
$entry[ $field_id ] = $consumer_iban; | |
} | |
GFAPI::update_entry( $entry ); | |
} | |
add_action( 'gform_ideal_fulfillment', 'gform_ideal_fulfillment_update_entry', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment