Last active
December 19, 2017 23:27
-
-
Save wturnerharris/e1d036ee50c0285a6a179ef72183e723 to your computer and use it in GitHub Desktop.
GF Addon Snippet using gform_post_payment_action
This file contains 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 | |
class GFDonorPerfectAddon extends GFFeedAddOn { | |
public function init() { | |
parent::init(); | |
add_action( 'gform_post_payment_action', array( $this, 'post_payment_action_hook' ), 10, 2 ); | |
} | |
public function post_payment_action_hook( $entry, $action ) { | |
$this->log_debug( __METHOD__ . "(): called." ); | |
$this->log_debug( __METHOD__ . ": \n" . print_r( array( 'action' => $action ), true) ); | |
if ( in_array( $action['type'], array( 'add_subscription_payment', 'complete_payment') ) ) { | |
$form = GFAPI::get_form( $entry['form_id'] ); | |
$feed = $this->get_single_submission_feed( $entry, $form ); | |
$entry['transaction_id_actual'] = $action['transaction_id']; | |
$this->process_feed( $feed, $entry, $form ); | |
} | |
} | |
public function process_feed( $feed, $entry, $form ) { | |
/* If DPO instance is not initialized, exit. */ | |
if ( ! $this->initialize_api() ) { | |
$this->log_error( __METHOD__ . '(): DonorPerfect API not configured; feed not processed.' ); | |
} | |
$this->log_debug( __METHOD__ . ": \n" . print_r( array( | |
'feed' => $feed, | |
'entry' => $entry, | |
), true) ); | |
$values = $this->get_feed_values( $feed, $entry ); | |
$feed_type = $feed['meta']['feed_type']; | |
if ( $feed_type === 'donate' ) { | |
$this->process_donate_feed( $values ); | |
} elseif ( $feed_type === 'membership' ) { | |
$this->process_membership_feed( $values ); | |
} else { | |
$this->log_error( __METHOD__ .': Error processing feed (Invalid feed type).' ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment