Skip to content

Instantly share code, notes, and snippets.

@mehul0810
Last active April 1, 2020 12:42
Show Gist options
  • Save mehul0810/8d1dd038257127c7caccf9ac67e8a27a to your computer and use it in GitHub Desktop.
Save mehul0810/8d1dd038257127c7caccf9ac67e8a27a to your computer and use it in GitHub Desktop.
<?php
/**
* Pass custom field data to Stripe when payment is processed.
*
* Retrieves custom form field data from the $_POST variable and merges it into
* the array that is passed to Stripe when a payment is made. Custom field data
* can be found under Metadata in the Stripe payment details screen.
*
* @param array $charge_args Arguments passed to Stripe payment gateway.
*
* @return array
*/
function give_stripe_custom_payment_meta( $intent_args, $donation_id, $donation_data ) {
// Sanitize the input posted data to the form.
$posted_data = give_clean( filter_input_array( INPUT_POST ) );
$donor_id = give_get_payment_donor_id($donation_id);
$donation_date = $donation_data['date'];
// Prepare metadata fields list.
$custom_meta_fields = array(
'Date' => $donation_date,
'Partner ID' => ! empty( $posted_data['give_donor_id'] ) ? $posted_data['give_donor_id'] : '',
'Title' => ! empty( $posted_data['give_title'] ) ? $posted_data['give_title'] : '',
'First Name' => ! empty( $posted_data['give_first'] ) ? $posted_data['give_first'] : '',
'Last Name' => ! empty( $posted_data['give_last'] ) ? $posted_data['give_last'] : '',
'Business/Church' => ! empty( $posted_data['give_company_name'] ) ? $posted_data['give_company_name'] : '',
'Recipient ID' => ! empty( $posted_data['recipient_id'] ) ? $posted_data['recipient_id'] : '',
'Recipient' => ! empty( $posted_data['give-form-title'] ) ? $posted_data['give-form-title'] : '',
'Motivation Code' => ! empty( $posted_data['motivation_code'] ) ? $posted_data['motivation_code'] : '',
'Appeal Code' => ! empty( $posted_data['appeal_code'] ) ? $posted_data['appeal_code'] : '',
'Comment 1' => ! empty( $posted_data['_give_comment'] ) ? $posted_data['_give_comment'] : '',
'Comment 2' => ! empty( $posted_data['comment_2'] ) ? $posted_data['comment_2'] : '',
'Total Amount' => ! empty( $posted_data['price'] ) ? $posted_data['price'] : '',
'Gift Amount - With Fee' => ! empty( $posted_data['_give_fee_donation_amount'] ) ? $posted_data['_give_fee_donation_amount'] : '',
'Fee Amount' => ! empty( $posted_data['give-fee-amount'] ) ? $posted_data['give-fee-amount'] : '',
'Confidential Donor' => ! empty( $posted_data['_give_anonymous_donation'] ) ? $posted_data['_give_anonymous_donation'] : '',
'Payment Method' => ! empty( $posted_data['_give_payment_gateway'] ) ? $posted_data['_give_payment_gateway'] : '',
'Payment Gateway' => ! empty( $posted_data['_give_payment_gateway'] ) ? $posted_data['_give_payment_gateway'] : '',
'Payment Method' => ! empty( $posted_data['_give_payment_gateway'] ) ? $posted_data['_give_payment_gateway'] : '',
'Address Line 1' => ! empty( $posted_data['line1'] ) ? $posted_data['line1'] : '',
'Address Line 2' => ! empty( $posted_data['line2'] ) ? $posted_data['line2'] : '',
'City' => ! empty( $posted_data['city'] ) ? $posted_data['city'] : '',
'State' => ! empty( $posted_data['state'] ) ? $posted_data['state'] : '',
'Postcode' => ! empty( $posted_data['zip'] ) ? $posted_data['zip'] : '',
'Country' => ! empty( $posted_data['country'] ) ? $posted_data['country'] : '',
'Email' => ! empty( $posted_data['give_email'] ) ? $posted_data['give_email'] : '',
'Phone' => ! empty( $posted_data['give_phone'] ) ? $posted_data['give_phone'] : '',
'OMer First Name *ACF' => ! empty( $posted_data['omer_first_name'] ) ? $posted_data['omer_first_name'] : '',
'OMer Last Name *ACF' => ! empty( $posted_data['omer_last_name'] ) ? $posted_data['omer_last_name'] : '',
'OMer Secure Name *ACF' => ! empty( $posted_data['omer_secure_name'] ) ? $posted_data['omer_secure_name'] : '',
'OMer Email *ACF' => ! empty( $posted_data['omer_email_address'] ) ? $posted_data['omer_email_address'] : '',
);
$intent_args['metadata'] = array_merge( $intent_args['metadata'], $custom_meta_fields );
return $intent_args;
}
add_filter( 'give_stripe_create_intent_args', 'give_stripe_custom_payment_meta', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment