Exemplo n.º 1
0
/**
 * Processes the purchase data and uses the Manual Payment gateway to record
 * the transaction in the Purchase History
 *
 * @since 1.0
 *
 * @param array $purchase_data Purchase Data
 *
 * @return void
 */
function give_manual_payment($purchase_data)
{
    if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'give-gateway')) {
        wp_die(esc_html__('Nonce verification has failed', 'give'), esc_html__('Error', 'give'), array('response' => 403));
    }
    //Create payment_data array
    $payment_data = array('price' => $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(), 'user_info' => $purchase_data['user_info'], 'status' => 'pending');
    // Record the pending payment
    $payment = give_insert_payment($payment_data);
    if ($payment) {
        give_update_payment_status($payment, 'publish');
        give_send_to_success_page();
    } else {
        give_record_gateway_error(esc_html__('Payment Error', 'give'), sprintf(esc_html__('The payment creation failed while processing a manual (free or test) donation. Payment data: %s', 'give'), json_encode($payment_data)), $payment);
        // If errors are present, send the user back to the purchase page so they can be corrected
        give_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['give-gateway']);
    }
}
Exemplo n.º 2
0
/**
 * Process web accept (one time) payment IPNs.
 *
 * @since 1.0
 *
 * @param array $data       IPN Data
 * @param int   $payment_id The payment ID from Give.
 *
 * @return void
 */
function give_process_paypal_web_accept_and_cart($data, $payment_id)
{
    //Only allow through these transaction types.
    if ($data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && strtolower($data['payment_status']) != 'refunded') {
        return;
    }
    //Need $payment_id to continue.
    if (empty($payment_id)) {
        return;
    }
    // Collect donation payment details.
    $paypal_amount = $data['mc_gross'];
    $payment_status = strtolower($data['payment_status']);
    $currency_code = strtolower($data['mc_currency']);
    $business_email = isset($data['business']) && is_email($data['business']) ? trim($data['business']) : trim($data['receiver_email']);
    $payment_meta = give_get_payment_meta($payment_id);
    // Must be a PayPal standard IPN.
    if (give_get_payment_gateway($payment_id) != 'paypal') {
        return;
    }
    // Verify payment recipient
    if (strcasecmp($business_email, trim(give_get_option('paypal_email'))) != 0) {
        give_record_gateway_error(esc_html__('IPN Error', 'give'), sprintf(esc_html__('Invalid business email in IPN response. IPN data: %s', 'give'), json_encode($data)), $payment_id);
        give_update_payment_status($payment_id, 'failed');
        give_insert_payment_note($payment_id, esc_html__('Payment failed due to invalid PayPal business email.', 'give'));
        return;
    }
    // Verify payment currency.
    if ($currency_code != strtolower($payment_meta['currency'])) {
        give_record_gateway_error(esc_html__('IPN Error', 'give'), sprintf(esc_html__('Invalid currency in IPN response. IPN data: %s', 'give'), json_encode($data)), $payment_id);
        give_update_payment_status($payment_id, 'failed');
        give_insert_payment_note($payment_id, esc_html__('Payment failed due to invalid currency in PayPal IPN.', 'give'));
        return;
    }
    //Process refunds & reversed.
    if ($payment_status == 'refunded' || $payment_status == 'reversed') {
        give_process_paypal_refund($data, $payment_id);
        return;
    }
    // Only complete payments once.
    if (get_post_status($payment_id) == 'publish') {
        return;
    }
    // Retrieve the total donation amount (before PayPal).
    $payment_amount = give_get_payment_amount($payment_id);
    //Check that the donation PP and local db amounts match.
    if (number_format((double) $paypal_amount, 2) < number_format((double) $payment_amount, 2)) {
        // The prices don't match
        give_record_gateway_error(esc_html__('IPN Error', 'give'), sprintf(esc_html__('Invalid payment amount in IPN response. IPN data: %s', 'give'), json_encode($data)), $payment_id);
        give_update_payment_status($payment_id, 'failed');
        give_insert_payment_note($payment_id, esc_html__('Payment failed due to invalid amount in PayPal IPN.', 'give'));
        return;
    }
    //Process completed donations.
    if ($payment_status == 'completed' || give_is_test_mode()) {
        give_insert_payment_note($payment_id, sprintf(esc_html__('PayPal Transaction ID: %s', 'give'), $data['txn_id']));
        give_set_payment_transaction_id($payment_id, $data['txn_id']);
        give_update_payment_status($payment_id, 'publish');
    } elseif ('pending' == $payment_status && isset($data['pending_reason'])) {
        // Look for possible pending reasons, such as an echeck.
        $note = give_paypal_get_pending_donation_note(strtolower($data['pending_reason']));
        if (!empty($note)) {
            give_insert_payment_note($payment_id, $note);
        }
    }
}
Exemplo n.º 3
0
/**
 * Process web accept (one time) payment IPNs
 *
 * @since 1.0
 *
 * @param array $data IPN Data
 *
 * @return void
 */
function give_process_paypal_web_accept_and_cart($data, $payment_id)
{
    if ($data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded') {
        return;
    }
    if (empty($payment_id)) {
        return;
    }
    // Collect payment details
    $purchase_key = isset($data['invoice']) ? $data['invoice'] : $data['item_number'];
    $paypal_amount = $data['mc_gross'];
    $payment_status = strtolower($data['payment_status']);
    $currency_code = strtolower($data['mc_currency']);
    $business_email = isset($data['business']) && is_email($data['business']) ? trim($data['business']) : trim($data['receiver_email']);
    $payment_meta = give_get_payment_meta($payment_id);
    if (give_get_payment_gateway($payment_id) != 'paypal') {
        return;
        // this isn't a PayPal standard IPN
    }
    // Verify payment recipient
    if (strcasecmp($business_email, trim(give_get_option('paypal_email'))) != 0) {
        give_record_gateway_error(__('IPN Error', 'give'), sprintf(__('Invalid business email in IPN response. IPN data: %s', 'give'), json_encode($data)), $payment_id);
        give_update_payment_status($payment_id, 'failed');
        give_insert_payment_note($payment_id, __('Payment failed due to invalid PayPal business email.', 'give'));
        return;
    }
    // Verify payment currency
    if ($currency_code != strtolower($payment_meta['currency'])) {
        give_record_gateway_error(__('IPN Error', 'give'), sprintf(__('Invalid currency in IPN response. IPN data: %s', 'give'), json_encode($data)), $payment_id);
        give_update_payment_status($payment_id, 'failed');
        give_insert_payment_note($payment_id, __('Payment failed due to invalid currency in PayPal IPN.', 'give'));
        return;
    }
    if (!give_get_payment_user_email($payment_id)) {
        // No email associated with purchase, so store from PayPal
        give_update_payment_meta($payment_id, '_give_payment_user_email', $data['payer_email']);
        // Setup and store the donors's details
        $address = array();
        $address['line1'] = !empty($data['address_street']) ? sanitize_text_field($data['address_street']) : false;
        $address['city'] = !empty($data['address_city']) ? sanitize_text_field($data['address_city']) : false;
        $address['state'] = !empty($data['address_state']) ? sanitize_text_field($data['address_state']) : false;
        $address['country'] = !empty($data['address_country_code']) ? sanitize_text_field($data['address_country_code']) : false;
        $address['zip'] = !empty($data['address_zip']) ? sanitize_text_field($data['address_zip']) : false;
        $user_info = array('id' => '-1', 'email' => sanitize_text_field($data['payer_email']), 'first_name' => sanitize_text_field($data['first_name']), 'last_name' => sanitize_text_field($data['last_name']), 'discount' => '', 'address' => $address);
        $payment_meta['user_info'] = $user_info;
        give_update_payment_meta($payment_id, '_give_payment_meta', $payment_meta);
    }
    if ($payment_status == 'refunded' || $payment_status == 'reversed') {
        // Process a refund
        give_process_paypal_refund($data, $payment_id);
    } else {
        if (get_post_status($payment_id) == 'publish') {
            return;
            // Only complete payments once
        }
        // Retrieve the total purchase amount (before PayPal)
        $payment_amount = give_get_payment_amount($payment_id);
        if (number_format((double) $paypal_amount, 2) < number_format((double) $payment_amount, 2)) {
            // The prices don't match
            give_record_gateway_error(__('IPN Error', 'give'), sprintf(__('Invalid payment amount in IPN response. IPN data: %s', 'give'), json_encode($data)), $payment_id);
            give_update_payment_status($payment_id, 'failed');
            give_insert_payment_note($payment_id, __('Payment failed due to invalid amount in PayPal IPN.', 'give'));
            return;
        }
        if ($purchase_key != give_get_payment_key($payment_id)) {
            // Purchase keys don't match
            give_record_gateway_error(__('IPN Error', 'give'), sprintf(__('Invalid purchase key in IPN response. IPN data: %s', 'give'), json_encode($data)), $payment_id);
            give_update_payment_status($payment_id, 'failed');
            give_insert_payment_note($payment_id, __('Payment failed due to invalid purchase key in PayPal IPN.', 'give'));
            return;
        }
        if ($payment_status == 'completed' || give_is_test_mode()) {
            give_insert_payment_note($payment_id, sprintf(__('PayPal Transaction ID: %s', 'give'), $data['txn_id']));
            give_set_payment_transaction_id($payment_id, $data['txn_id']);
            give_update_payment_status($payment_id, 'publish');
        } else {
            if ('pending' == $payment_status && isset($data['pending_reason'])) {
                // Look for possible pending reasons, such as an echeck
                $note = '';
                switch (strtolower($data['pending_reason'])) {
                    case 'echeck':
                        $note = __('Payment made via eCheck and will clear automatically in 5-8 days', 'give');
                        break;
                    case 'address':
                        $note = __('Payment requires a confirmed donor address and must be accepted manually through PayPal', 'give');
                        break;
                    case 'intl':
                        $note = __('Payment must be accepted manually through PayPal due to international account regulations', 'give');
                        break;
                    case 'multi-currency':
                        $note = __('Payment received in non-shop currency and must be accepted manually through PayPal', 'give');
                        break;
                    case 'paymentreview':
                    case 'regulatory_review':
                        $note = __('Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'give');
                        break;
                    case 'unilateral':
                        $note = __('Payment was sent to non-confirmed or non-registered email address.', 'give');
                        break;
                    case 'upgrade':
                        $note = __('PayPal account must be upgraded before this payment can be accepted', 'give');
                        break;
                    case 'verify':
                        $note = __('PayPal account is not verified. Verify account in order to accept this payment', 'give');
                        break;
                    case 'other':
                        $note = __('Payment is pending for unknown reasons. Contact PayPal support for assistance', 'give');
                        break;
                }
                if (!empty($note)) {
                    give_insert_payment_note($payment_id, $note);
                }
            }
        }
    }
}
Exemplo n.º 4
0
 /**
  * Process purchase.
  *
  * @since 1.0.0
  *
  * @param array $purchase_data Purchase Data
  *
  * @return void
  */
 function process_purchase($purchase_data)
 {
     if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'give-gateway')) {
         wp_die(__('Nonce verification has failed', 'pronamic_ideal'), __('Error', 'pronamic_ideal'), array('response' => 403));
     }
     $form_id = intval($purchase_data['post_data']['give-form-id']);
     // Collect payment data
     $payment_data = array('price' => $purchase_data['price'], 'give_form_title' => $purchase_data['post_data']['give-form-title'], 'give_form_id' => $form_id, 'date' => $purchase_data['date'], 'user_email' => $purchase_data['user_email'], 'purchase_key' => $purchase_data['purchase_key'], 'currency' => give_get_currency(), 'user_info' => $purchase_data['user_info'], 'status' => 'pending', 'gateway' => $this->id);
     // Record the pending payment
     $donation_id = give_insert_payment($payment_data);
     if (!$donation_id) {
         // Record the error
         // /wp-admin/edit.php?post_type=give_forms&page=give-reports&tab=logs&view=gateway_errors
         // @see https://github.com/WordImpress/Give/blob/1.3.6/includes/gateways/functions.php#L267-L285
         give_record_gateway_error(__('Payment Error', 'pronamic_ideal'), sprintf(__('Payment creation failed before sending buyer to payment provider. Payment data: %s', 'pronamic_ideal'), json_encode($payment_data)), $donation_id);
         // Problems? send back
         // @see https://github.com/WordImpress/Give/blob/1.3.6/includes/forms/functions.php#L150-L184
         give_send_back_to_checkout(array('payment-error' => true, 'payment-mode' => $purchase_data['post_data']['give-gateway']));
     } else {
         $config_id = give_get_option(sprintf('give_%s_configuration', $this->id));
         $gateway = Pronamic_WP_Pay_Plugin::get_gateway($config_id);
         if ($gateway) {
             // Data
             $data = new Pronamic_WP_Pay_Extensions_Give_PaymentData($donation_id, $this);
             $gateway->set_payment_method($this->payment_method);
             $payment = Pronamic_WP_Pay_Plugin::start($config_id, $gateway, $data, $this->payment_method);
             $error = $gateway->get_error();
             if (is_wp_error($error)) {
                 // Record the error
                 // /wp-admin/edit.php?post_type=give_forms&page=give-reports&tab=logs&view=gateway_errors
                 // @see https://github.com/WordImpress/Give/blob/1.3.6/includes/gateways/functions.php#L267-L285
                 give_record_gateway_error(__('Payment Error', 'pronamic_ideal'), implode('<br />', $error->get_error_messages()), $donation_id);
                 // Problems? send back
                 // @see https://github.com/WordImpress/Give/blob/1.3.6/includes/forms/functions.php#L150-L184
                 give_send_back_to_checkout(array('payment-error' => true, 'payment-mode' => $purchase_data['post_data']['give-gateway']));
             } else {
                 // Redirect
                 $gateway->redirect($payment);
             }
         }
     }
 }