/**
  * Create a simple donation payment.
  *
  * @since 1.0
  */
 public static function create_simple_payment()
 {
     global $give_options;
     // Enable a few options
     $give_options['enable_sequential'] = '1';
     $give_options['sequential_prefix'] = 'GIVE-';
     update_option('give_settings', $give_options);
     $simple_form = Give_Helper_Form::create_simple_form();
     $multilevel_form = Give_Helper_Form::create_multilevel_form();
     /** Generate some donations */
     $user = get_userdata(1);
     $user_info = array('id' => $user->ID, 'email' => $user->user_email, 'first_name' => $user->first_name, 'last_name' => $user->last_name);
     $total = 0;
     $simple_price = get_post_meta($simple_form->ID, 'give_price', true);
     $variable_prices = get_post_meta($multilevel_form->ID, 'give_variable_prices', true);
     $variable_item_price = $variable_prices[1]['amount'];
     // == $100
     $total += $variable_item_price + $simple_price;
     $purchase_data = array('price' => number_format((double) $total, 2), 'give_form_title' => 'Test Donation', 'give_form_id' => $simple_form->ID, 'date' => date('Y-m-d H:i:s', strtotime('-1 day')), 'purchase_key' => strtolower(md5(uniqid())), 'user_email' => $user_info['email'], 'user_info' => $user_info, 'currency' => 'USD', 'status' => 'pending');
     $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
     $_SERVER['SERVER_NAME'] = 'give_virtual';
     $payment_id = give_insert_payment($purchase_data);
     $key = $purchase_data['purchase_key'];
     $transaction_id = 'FIR3SID3';
     give_set_payment_transaction_id($payment_id, $transaction_id);
     give_insert_payment_note($payment_id, sprintf(__('PayPal Transaction ID: %s', 'give'), $transaction_id));
     return $payment_id;
 }
 /**
  * Set it Up
  */
 public function setUp()
 {
     parent::setUp();
     $payment_id = Give_Helper_Payment::create_simple_payment();
     $this->_payment_key = give_get_payment_key($payment_id);
     $this->_payment_id = $payment_id;
     $this->_key = $this->_payment_key;
     $this->_transaction_id = 'FIR3SID3';
     give_set_payment_transaction_id($payment_id, $this->_transaction_id);
     give_insert_payment_note($payment_id, sprintf(esc_html__('PayPal Transaction ID: %s', 'give'), $this->_transaction_id));
     // Make sure we're working off a clean object caching in WP Core.
     // Prevents some payment_meta from not being present.
     clean_post_cache($payment_id);
     update_postmeta_cache(array($payment_id));
 }
Exemple #3
0
/**
 * Process PayPal IPN Refunds
 *
 * @since 1.0
 *
 * @param array $data       IPN Data
 * @param int   $payment_id The payment ID.
 *
 * @return void
 */
function give_process_paypal_refund($data, $payment_id = 0)
{
    // Collect payment details
    if (empty($payment_id)) {
        return;
    }
    if (get_post_status($payment_id) == 'refunded') {
        return;
        // Only refund payments once
    }
    $payment_amount = give_get_payment_amount($payment_id);
    $refund_amount = $data['payment_gross'] * -1;
    if (number_format((double) $refund_amount, 2) < number_format((double) $payment_amount, 2)) {
        give_insert_payment_note($payment_id, sprintf(esc_html__('Partial PayPal refund processed: %s', 'give'), $data['parent_txn_id']));
        return;
        // This is a partial refund
    }
    give_insert_payment_note($payment_id, sprintf(esc_html__('PayPal Payment #%s Refunded for reason: %s', 'give'), $data['parent_txn_id'], $data['reason_code']));
    give_insert_payment_note($payment_id, sprintf(esc_html__('PayPal Refund Transaction ID: %s', 'give'), $data['txn_id']));
    give_update_payment_status($payment_id, 'refunded');
}
Exemple #4
0
/**
 * Record payment status change
 *
 * @since  1.0
 *
 * @param  int    $payment_id The ID number of the payment.
 * @param  string $new_status The status of the payment, probably "publish".
 * @param  string $old_status The status of the payment prior to being marked as "complete", probably "pending".
 *
 * @return void
 */
function give_record_status_change($payment_id, $new_status, $old_status)
{
    // Get the list of statuses so that status in the payment note can be translated
    $stati = give_get_payment_statuses();
    $old_status = isset($stati[$old_status]) ? $stati[$old_status] : $old_status;
    $new_status = isset($stati[$new_status]) ? $stati[$new_status] : $new_status;
    $status_change = sprintf(esc_html__('Status changed from %1$s to %2$s.', 'give'), $old_status, $new_status);
    give_insert_payment_note($payment_id, $status_change);
}
 /**
  * Create Simple Donation w/ Fee
  *
  * @return bool|int
  */
 public static function create_simple_payment_with_fee()
 {
     global $give_options;
     // Enable a few options
     $give_options['sequential_prefix'] = 'GIVE-';
     $simple_form = Give_Helper_Form::create_simple_form();
     // Generate some sales
     $user = get_userdata(1);
     $user_info = array('id' => $user->ID, 'email' => $user->user_email, 'first_name' => $user->first_name, 'last_name' => $user->last_name);
     $donation_details = array(array('id' => $simple_form->ID, 'options' => array('price_id' => 0), 'quantity' => 2));
     $total = 0;
     $simple_price = get_post_meta($simple_form->ID, 'give_price', true);
     $total += $simple_price;
     $payment_details = array(array('name' => 'Test Donation', 'id' => $simple_form->ID, 'options' => array('price_id' => 1), 'price' => $simple_price * 2, 'item_price' => $simple_price, 'quantity' => 2));
     $purchase_data = array('price' => number_format((double) $total, 2), 'date' => date('Y-m-d H:i:s', strtotime('-1 day')), 'purchase_key' => strtolower(md5(uniqid())), 'user_email' => $user_info['email'], 'user_info' => $user_info, 'currency' => 'USD', 'donations' => $donation_details, 'payment_details' => $payment_details, 'status' => 'pending');
     $fee_args = array('label' => 'Test Fee', 'type' => 'test', 'amount' => 5);
     //@TODO: Incorporate Fees
     //Give()->fees->add_fee( $fee_args );
     $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
     $_SERVER['SERVER_NAME'] = 'give_virtual';
     $payment_id = give_insert_payment($purchase_data);
     $transaction_id = 'FIR3SID3';
     $payment = new Give_Payment($payment_id);
     $payment->transaction_id = $transaction_id;
     $payment->save();
     give_insert_payment_note($payment_id, sprintf(esc_html__('PayPal Transaction ID: %s', 'give'), $transaction_id));
     return $payment_id;
 }
 /**
  * Add a note to a payment
  *
  * @since  1.0
  * @access public
  *
  * @param  string $note The note to add
  *
  * @return void
  */
 public function add_note($note = false)
 {
     // Bail if no note specified
     if (!$note) {
         return false;
     }
     give_insert_payment_note($this->ID, $note);
 }
Exemple #7
0
function give_ajax_store_payment_note()
{
    $payment_id = absint($_POST['payment_id']);
    $note = wp_kses($_POST['note'], array());
    if (!current_user_can('edit_give_payments', $payment_id)) {
        wp_die(__('You do not have permission to edit this payment record', 'give'), __('Error', 'give'), array('response' => 403));
    }
    if (empty($payment_id)) {
        die('-1');
    }
    if (empty($note)) {
        die('-1');
    }
    $note_id = give_insert_payment_note($payment_id, $note);
    die(give_get_payment_note_html($note_id));
}