Skip to content

Commit

Permalink
feat: add popup info to donation block
Browse files Browse the repository at this point in the history
feat: add popup info to donation block
  • Loading branch information
leogermani authored Feb 24, 2023
2 parents 7b9483a + 777685a commit 9493990
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/blocks/donate/class-wp-rest-newspack-donate-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,26 @@ public function api_process_donation( $request ) {
}
}

$referer = $request->get_param( '_wp_http_referer' );
if ( ! $referer ) {
$referer = \wp_get_referer();
}

$payment_metadata = [
'referer' => \wp_get_referer(),
'referer' => $referer,
];

if ( class_exists( 'Newspack\NRH' ) && method_exists( 'Newspack\NRH', 'get_nrh_config' ) ) {
$nrh_config = \Newspack\NRH::get_nrh_config();
if ( isset( $nrh_config['nrh_salesforce_campaign_id'] ) ) {
$payment_metadata['sf_campaign_id'] = $nrh_config['nrh_salesforce_campaign_id'];
}
}

if ( ! empty( $request->get_param( 'newspack_popup_id' ) ) ) {
$payment_metadata['newspack_popup_id'] = $request->get_param( 'newspack_popup_id' );
}

$frequency = $request->get_param( 'frequency' );
$full_name = $request->get_param( 'full_name' );
$origin = $request->get_param( 'origin' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,11 @@ protected static function render_streamlined_payment_ui( $attributes ) {
*/
protected static function render_donate_form_input() {
ob_start();
/**
* Action to add custom fields before the form fields of the donation block.
*/
do_action( 'newspack_blocks_donate_before_form_fields' );
wp_referer_field();
?>
<input type='hidden' name='newspack_donate' value='1' />
<?php
Expand Down
2 changes: 2 additions & 0 deletions src/blocks/donate/streamlined/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ export const processStreamlinedElements = ( parentElement = document ) =>
full_name: formValues.full_name,
frequency: formValues.donation_frequency,
newsletter_opt_in: Boolean( formValues.newsletter_opt_in ),
newspack_popup_id: formValues.newspack_popup_id,
_wp_http_referer: formValues._wp_http_referer,
clientId: formValues.cid,
origin,
additional_fields: additionalFields,
Expand Down
2 changes: 2 additions & 0 deletions src/blocks/donate/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export type DonationFormValues = {
cid?: string;
agree_to_pay_fees?: string;
newsletter_opt_in?: string;
newspack_popup_id?: string;
_wp_http_referer?: string;
};

export type DonationSettings = {
Expand Down

0 comments on commit 9493990

Please sign in to comment.