$purchase_data['price'],
'give_form_title' => $purchase_data['post_data']['give-form-title'],
'give_form_id' => intval( $purchase_data['post_data']['give-form-id'] ),
'give_price_id' => isset( $purchase_data['post_data']['give-price-id'] ) ? $purchase_data['post_data']['give-price-id'] : '',
'date' => $purchase_data['date'],
'user_email' => $purchase_data['user_email'],
'purchase_key' => $purchase_data['purchase_key'],
'currency' => give_get_currency( $purchase_data['post_data']['give-form-id'], $purchase_data ),
'user_info' => $purchase_data['user_info'],
'status' => 'pending',
'gateway' => 'offline',
];
// record the pending payment
$payment = give_insert_payment( $payment_data );
if ( $payment ) {
give_send_to_success_page();
} else {
// if errors are present, send the user back to the donation form so they can be corrected
give_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['give-gateway'] );
}
}
add_action( 'give_gateway_offline', 'give_offline_process_payment' );
/**
* Send Offline Donation Instructions
*
* Sends a notice to the donor with offline instructions; can be customized per form
*
* @param int $payment_id
*
* @since 1.0
* @return void
*/
function give_offline_send_donor_instructions( $payment_id = 0 ) {
$payment_data = give_get_payment_meta( $payment_id );
$post_offline_customization_option = give_get_meta( $payment_data['form_id'], '_give_customize_offline_donations', true );
// Customize email content depending on whether the single form has been customized
$email_content = give_get_option( 'global_offline_donation_email' );
if ( give_is_setting_enabled( $post_offline_customization_option, 'enabled' ) ) {
$email_content = give_get_meta( $payment_data['form_id'], '_give_offline_donation_email', true );
}
$from_name = give_get_option( 'from_name', wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ) );
/**
* Filters the from name.
*
* @since 1.7
*/
$from_name = apply_filters( 'give_donation_from_name', $from_name, $payment_id, $payment_data );
$from_email = give_get_option( 'from_email', get_bloginfo( 'admin_email' ) );
/**
* Filters the from email.
*
* @since 1.7
*/
$from_email = apply_filters( 'give_donation_from_address', $from_email, $payment_id, $payment_data );
$to_email = give_get_payment_user_email( $payment_id );
$subject = give_get_option( 'offline_donation_subject', __( 'Offline Donation Instructions', 'give' ) );
if ( give_is_setting_enabled( $post_offline_customization_option, 'enabled' ) ) {
$subject = give_get_meta( $payment_data['form_id'], '_give_offline_donation_subject', true );
}
$subject = apply_filters( 'give_offline_donation_subject', wp_strip_all_tags( $subject ), $payment_id );
$subject = give_do_email_tags( $subject, $payment_id );
$attachments = apply_filters( 'give_offline_donation_attachments', [], $payment_id, $payment_data );
$message = give_do_email_tags( $email_content, $payment_id );
$emails = Give()->emails;
$emails->__set( 'from_name', $from_name );
$emails->__set( 'from_email', $from_email );
$emails->__set( 'heading', __( 'Offline Donation Instructions', 'give' ) );
$headers = apply_filters( 'give_receipt_headers', $emails->get_headers(), $payment_id, $payment_data );
$emails->__set( 'headers', $headers );
$emails->send( $to_email, $subject, $message, $attachments );
}
/**
* Send Offline Donation Admin Notice.
*
* Sends a notice to site admins about the pending donation.
*
* @since 1.0
*
* @param int $payment_id
*
* @return void
*/
function give_offline_send_admin_notice( $payment_id = 0 ) {
/* Send an email notification to the admin */
$admin_email = give_get_admin_notice_emails();
$user_info = give_get_payment_meta_user_info( $payment_id );
if ( isset( $user_info['id'] ) && $user_info['id'] > 0 ) {
$user_data = get_userdata( $user_info['id'] );
$name = $user_data->display_name;
} elseif ( isset( $user_info['first_name'] ) && isset( $user_info['last_name'] ) ) {
$name = $user_info['first_name'] . ' ' . $user_info['last_name'];
} else {
$name = $user_info['email'];
}
$amount = give_donation_amount( $payment_id );
$admin_subject = apply_filters( 'give_offline_admin_donation_notification_subject', __( 'New Pending Donation', 'give' ), $payment_id );
$admin_message = __( 'Dear Admin,', 'give' ) . "\n\n";
$admin_message .= sprintf( __( 'A new offline donation has been made on your website for %s.', 'give' ), $amount ) . "\n\n";
$admin_message .= __( 'The donation is in a pending status and is awaiting payment. Donation instructions have been emailed to the donor. Once you receive payment, be sure to mark the donation as complete using the link below.', 'give' ) . "\n\n";
$admin_message .= '' . __( 'Donor:', 'give' ) . ' {fullname}' . "\n";
$admin_message .= '' . __( 'Amount:', 'give' ) . ' {amount}' . "\n\n";
$admin_message .= sprintf(
'%2$s',
admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&view=view-payment-details&id=' . $payment_id ),
__( 'View Donation Details »', 'give' )
) . "\n\n";
$admin_message = apply_filters( 'give_offline_admin_donation_notification', $admin_message, $payment_id );
$admin_message = give_do_email_tags( $admin_message, $payment_id );
$attachments = apply_filters( 'give_offline_admin_donation_notification_attachments', [], $payment_id );
$admin_headers = apply_filters( 'give_offline_admin_donation_notification_headers', [], $payment_id );
// Send Email
$emails = Give()->emails;
$emails->__set( 'heading', __( 'New Offline Donation', 'give' ) );
if ( ! empty( $admin_headers ) ) {
$emails->__set( 'headers', $admin_headers );
}
$emails->send( $admin_email, $admin_subject, $admin_message, $attachments );
}
/**
* Register gateway settings.
*
* @param $settings
*
* @return array
*/
function give_offline_add_settings( $settings ) {
// Bailout: Do not show offline gateways setting in to metabox if its disabled globally.
if ( in_array( 'offline', (array) give_get_option( 'gateways' ) ) ) {
return $settings;
}
// Vars
$prefix = '_give_';
$is_gateway_active = give_is_gateway_active( 'offline' );
// this gateway isn't active
if ( ! $is_gateway_active ) {
// return settings and bounce
return $settings;
}
// Fields
$check_settings = [
[
'name' => __( 'Offline Donations', 'give' ),
'desc' => __( 'Do you want to customize the donation instructions for this form?', 'give' ),
'id' => $prefix . 'customize_offline_donations',
'type' => 'radio_inline',
'default' => 'global',
'options' => apply_filters(
'give_forms_content_options_select',
[
'global' => __( 'Global Option', 'give' ),
'enabled' => __( 'Customize', 'give' ),
'disabled' => __( 'Disable', 'give' ),
]
),
],
[
'name' => __( 'Billing Fields', 'give' ),
'desc' => __( 'This option will enable the billing details section for this form\'s offline donation payment gateway. The fieldset will appear above the offline donation instructions.', 'give' ),
'id' => $prefix . 'offline_donation_enable_billing_fields_single',
'row_classes' => 'give-subfield give-hidden',
'type' => 'radio_inline',
'default' => 'disabled',
'options' => [
'enabled' => __( 'Enabled', 'give' ),
'disabled' => __( 'Disabled', 'give' ),
],
],
[
'id' => $prefix . 'offline_checkout_notes',
'name' => __( 'Donation Instructions', 'give' ),
'desc' => __( 'Enter the instructions you want to display to the donor during the donation process. Most likely this would include important information like mailing address and who to make the check out to.', 'give' ),
'default' => give_get_default_offline_donation_content(),
'type' => 'wysiwyg',
'row_classes' => 'give-subfield give-hidden',
'options' => [
'textarea_rows' => 6,
],
],
[
'name' => 'offline_docs',
'type' => 'docs_link',
'url' => 'http://docs.givewp.com/settings-gateway-offline-donations',
'title' => __( 'Offline Donations', 'give' ),
],
];
return array_merge( $settings, $check_settings );
}
add_filter( 'give_forms_offline_donations_metabox_fields', 'give_offline_add_settings' );
/**
* Offline Donation Content
*
* Get default offline donation text
*
* @return string
*/
function give_get_default_offline_donation_content() {
$default_text = '
' . __( 'To make an offline donation toward this cause, follow these steps:', 'give' ) . '
';
$default_text .= '';
$default_text .= '
';
$default_text .= sprintf(
/* translators: %s: site name */
__( 'Write a check payable to "{sitename}"', 'give' )
);
$default_text .= '
';
$default_text .= '
';
$default_text .= sprintf(
/* translators: %s: site name */
__( 'On the memo line of the check, indicate that the donation is for "{sitename}"', 'give' )
);
$default_text .= '
' . __( 'Thank you for letting us know that you\'re mailing a check! Your generosity is greatly appreciated. Here are those steps again:', 'give' ) . '
';
$default_text .= '';
$default_text .= '
';
$default_text .= esc_html__( 'Write a check payable to "{sitename}"', 'give' );
$default_text .= '
';
$default_text .= '
';
$default_text .= esc_html__( 'On the memo line of the check, indicate that the donation is for "{form_title}"', 'give' );
$default_text .= '
' . esc_html__( 'Once we receive the check, we will mark it as complete in our system, which will generate an email receipt for your records. Please contact us with any questions you may have!', 'give' ) . '
';
$default_text .= '
' . esc_html__( 'Thanks in advance!', 'give' ) . '