Last active
January 27, 2022 09:30
-
-
Save rvdsteege/297470c12876e52ae20bf1b939d4510e to your computer and use it in GitHub Desktop.
Update Gravity Forms entry with payment details on successful payment.
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 | |
function gform_ideal_fulfillment_update_entry( $entry, $feed ) { | |
// Check entry fulfillment. | |
if ( '1' !== $entry['is_fulfilled'] ) { | |
return; | |
} | |
// Get Pronamic payment. | |
$payment_id = gform_get_meta( $entry['id'], 'pronamic_payment_id' ); | |
$payment = get_pronamic_payment( $payment_id ); | |
if ( null === $payment ) { | |
return; | |
} | |
// Define fields to update. | |
$update_fields = array( | |
'ideal-transaction-id' => $payment->get_transaction_id(), | |
); | |
$bank_details = $payment->get_consumer_bank_details(); | |
if ( null !== $bank_details ) { | |
$update_fields = array_merge( | |
$update_fields, | |
array( | |
'ideal-iban' => $bank_details->get_iban(), | |
'ideal-consumer-bic' => $bank_details->get_bic(), | |
'ideal-consumer-name' => $bank_details->get_name(), | |
) | |
); | |
} | |
// Update entry. | |
$form = GFAPI::get_form( $entry['form_id'] ); | |
foreach ( $update_fields as $class => $value ) { | |
foreach ( $form['fields'] as $field ) { | |
$field_classes = explode( ' ', $field->cssClass ); | |
if ( ! in_array( $class, $field_classes ) ) { | |
continue; | |
} | |
$entry[ $field->id ] = $value; | |
break; | |
} | |
} | |
GFAPI::update_entry( $entry ); | |
} | |
add_action( 'gform_post_payment_completed', 'gform_ideal_fulfillment_update_entry', 10, 2 ); | |
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