Beispiel #1
0
 /**
  *
  */
 static function server_callback()
 {
     global $wpdb;
     //** Get request body */
     $body = @file_get_contents('php://input');
     $event_object = json_decode($body);
     switch ($event_object->type) {
         //** Used only for subscriptions since single payments processed without Webhook */
         case 'charge.succeeded':
             $post_id = $wpdb->get_col("SELECT post_id\r\n          FROM {$wpdb->postmeta}\r\n          WHERE meta_key = '_stripe_customer_id'\r\n            AND meta_value = '{$event_object->data->object->customer}'");
             $invoice_object = new WPI_Invoice();
             $invoice_object->load_invoice("id=" . $post_id[0]);
             if (empty($invoice_object->data['ID'])) {
                 die("Can't load invoice");
             }
             if (!class_exists('Stripe')) {
                 require_once WPI_Path . '/third-party/stripe/lib/Stripe.php';
             }
             $pk = trim($invoice_object->data['billing']['wpi_stripe']['settings'][$invoice_object->data['billing']['wpi_stripe']['settings']['mode']['value'] . '_secret_key']['value']);
             Stripe::setApiKey($pk);
             $event = Stripe_Event::retrieve($event_object->id);
             if ($event->data->object->paid == 1) {
                 $event_amount = (double) ($event->data->object->amount / 100);
                 $event_note = WPI_Functions::currency_format(abs($event_amount), $invoice_object->data['invoice_id']) . ' ' . __('Stripe Subscription Payment', WPI);
                 $event_type = 'add_payment';
                 $invoice_object->add_entry("attribute=balance&note={$event_note}&amount={$event_amount}&type={$event_type}");
                 $invoice_object->save_invoice();
             }
             break;
         case 'customer.subscription.deleted':
             $post_id = $wpdb->get_col("SELECT post_id\r\n          FROM {$wpdb->postmeta}\r\n          WHERE meta_key = '_stripe_customer_id'\r\n            AND meta_value = '{$event_object->data->object->customer}'");
             $invoice_object = new WPI_Invoice();
             $invoice_object->load_invoice("id=" . $post_id[0]);
             if (empty($invoice_object->data['ID'])) {
                 die("Can't load invoice");
             }
             if (!class_exists('Stripe')) {
                 require_once WPI_Path . '/third-party/stripe/lib/Stripe.php';
             }
             $pk = trim($invoice_object->data['billing']['wpi_stripe']['settings'][$invoice_object->data['billing']['wpi_stripe']['settings']['mode']['value'] . '_secret_key']['value']);
             Stripe::setApiKey($pk);
             $event = Stripe_Event::retrieve($event_object->id);
             if ($event->data->object->status == 'canceled') {
                 $invoice_object->add_entry("attribute=invoice&note=" . __('Stripe Subscription has been canceled', WPI) . "&type=update");
                 $invoice_object->save_invoice();
                 wp_invoice_mark_as_paid($invoice_object->data['invoice_id']);
             }
             break;
         default:
             break;
     }
 }
Beispiel #2
0
 /**
  * Handler for PayPal IPN queries
  * @author korotkov@ud
  * Full callback URL: http://domain/wp-admin/admin-ajax.php?action=wpi_gateway_server_callback&type=wpi_paypal
  */
 static function server_callback()
 {
     if (empty($_POST)) {
         die(__('Direct access not allowed', WPI));
     }
     $invoice = new WPI_Invoice();
     $invoice->load_invoice("id={$_POST['invoice']}");
     /** Verify callback request */
     if (self::_ipn_verified($invoice)) {
         switch ($_POST['txn_type']) {
             /** New PayPal Subscription */
             case 'subscr_signup':
                 /** PayPal Subscription created */
                 WPI_Functions::log_event(wpi_invoice_id_to_post_id($_POST['invoice']), 'invoice', 'update', '', __('PayPal Subscription created', WPI));
                 wp_invoice_mark_as_pending($_POST['invoice']);
                 do_action('wpi_paypal_subscr_signup_ipn', $_POST);
                 break;
             case 'subscr_cancel':
                 /** PayPal Subscription cancelled */
                 WPI_Functions::log_event(wpi_invoice_id_to_post_id($_POST['invoice']), 'invoice', 'update', '', __('PayPal Subscription cancelled', WPI));
                 do_action('wpi_paypal_subscr_cancel_ipn', $_POST);
                 break;
             case 'subscr_failed':
                 /** PayPal Subscription failed */
                 WPI_Functions::log_event(wpi_invoice_id_to_post_id($_POST['invoice']), 'invoice', 'update', '', __('PayPal Subscription payment failed', WPI));
                 do_action('wpi_paypal_subscr_failed_ipn', $_POST);
                 break;
             case 'subscr_payment':
                 /** Payment of Subscription */
                 switch ($_POST['payment_status']) {
                     case 'Completed':
                         /** Add payment amount */
                         $event_note = sprintf(__('%1s paid for subscription %2s', WPI), WPI_Functions::currency_format(abs($_POST['mc_gross']), $_POST['invoice']), $_POST['subscr_id']);
                         $event_amount = (double) $_POST['mc_gross'];
                         $event_type = 'add_payment';
                         /** Log balance changes */
                         $invoice->add_entry("attribute=balance&note={$event_note}&amount={$event_amount}&type={$event_type}");
                         $invoice->save_invoice();
                         send_notification($invoice->data);
                         break;
                     default:
                         break;
                 }
                 do_action('wpi_paypal_subscr_payment_ipn', $_POST);
                 break;
             case 'subscr_eot':
                 /** PayPal Subscription end of term */
                 WPI_Functions::log_event(wpi_invoice_id_to_post_id($_POST['invoice']), 'invoice', 'update', '', __('PayPal Subscription term is finished', WPI));
                 wp_invoice_mark_as_paid($_POST['invoice'], $check = false);
                 do_action('wpi_paypal_subscr_eot_ipn', $_POST);
                 break;
             case 'subscr_modify':
                 /** PayPal Subscription modified */
                 WPI_Functions::log_event(wpi_invoice_id_to_post_id($_POST['invoice']), 'invoice', 'update', '', __('PayPal Subscription modified', WPI));
                 do_action('wpi_paypal_subscr_modify_ipn', $_POST);
                 break;
             case 'web_accept':
                 /** PayPal simple button */
                 switch ($_POST['payment_status']) {
                     case 'Pending':
                         /** Mark invoice as Pending */
                         wp_invoice_mark_as_pending($_POST['invoice']);
                         do_action('wpi_paypal_pending_ipn', $_POST);
                         break;
                     case 'Completed':
                         /** Add payment amount */
                         $event_note = sprintf(__('%s paid via PayPal', WPI), WPI_Functions::currency_format(abs($_POST['mc_gross']), $_POST['invoice']));
                         $event_amount = (double) $_POST['mc_gross'];
                         $event_type = 'add_payment';
                         /** Log balance changes */
                         $invoice->add_entry("attribute=balance&note={$event_note}&amount={$event_amount}&type={$event_type}");
                         /** Log payer email */
                         $payer_email = sprintf(__("PayPal Payer email: %s", WPI), $_POST['payer_email']);
                         $invoice->add_entry("attribute=invoice&note={$payer_email}&type=update");
                         $invoice->save_invoice();
                         /** ... and mark invoice as paid */
                         wp_invoice_mark_as_paid($_POST['invoice'], $check = true);
                         send_notification($invoice->data);
                         do_action('wpi_paypal_complete_ipn', $_POST);
                         break;
                     default:
                         break;
                 }
                 break;
             case 'cart':
                 /** PayPal Cart. Used for SPC */
                 switch ($_POST['payment_status']) {
                     case 'Pending':
                         /** Mark invoice as Pending */
                         wp_invoice_mark_as_pending($_POST['invoice']);
                         do_action('wpi_paypal_pending_ipn', $_POST);
                         break;
                     case 'Completed':
                         /** Add payment amount */
                         $event_note = sprintf(__('%s paid via PayPal', WPI), WPI_Functions::currency_format(abs($_POST['mc_gross']), $_POST['invoice']));
                         $event_amount = (double) $_POST['mc_gross'];
                         $event_type = 'add_payment';
                         /** Log balance changes */
                         $invoice->add_entry("attribute=balance&note={$event_note}&amount={$event_amount}&type={$event_type}");
                         /** Log payer email */
                         $payer_email = sprintf(__("PayPal Payer email: %s", WPI), $_POST['payer_email']);
                         $invoice->add_entry("attribute=invoice&note={$payer_email}&type=update");
                         $invoice->save_invoice();
                         /** ... and mark invoice as paid */
                         wp_invoice_mark_as_paid($_POST['invoice'], $check = true);
                         send_notification($invoice->data);
                         do_action('wpi_paypal_complete_ipn', $_POST);
                         break;
                     default:
                         break;
                 }
                 break;
             default:
                 break;
         }
         echo ' ';
     }
 }
 /**
  * Handler for 2Checkout Callback
  * @author Craig Christenson
  * Full callback URL: http://domain/wp-admin/admin-ajax.php?action=wpi_gateway_server_callback&type=wpi_twocheckout
  */
 static function server_callback()
 {
     if (empty($_REQUEST)) {
         die(__('Direct access not allowed', WPI));
     }
     $invoice = new WPI_Invoice();
     $invoice->load_invoice("id={$_REQUEST['merchant_order_id']}");
     /** Verify callback request */
     if (self::_ipn_verified($invoice)) {
         if ($_REQUEST['key']) {
             $event_note = sprintf(__('%s paid via 2Checkout', WPI), WPI_Functions::currency_format(abs($_REQUEST['total']), $_REQUEST['merchant_order_id']));
             $event_amount = (double) $_REQUEST['total'];
             $event_type = 'add_payment';
             /** Log balance changes */
             $invoice->add_entry("attribute=balance&note={$event_note}&amount={$event_amount}&type={$event_type}");
             /** Log payer email */
             $payer_email = sprintf(__("2Checkout buyer email: %s", WPI), $_REQUEST['email']);
             $invoice->add_entry("attribute=invoice&note={$payer_email}&type=update");
             $invoice->save_invoice();
             /** ... and mark invoice as paid */
             wp_invoice_mark_as_paid($_REQUEST['invoice_id'], $check = true);
             send_notification($invoice->data);
             echo '<script type="text/javascript">window.location="' . get_invoice_permalink($invoice->data['ID']) . '";</script>';
             /** Handle INS messages */
         } elseif ($_POST['md5_hash']) {
             switch ($_POST['message_type']) {
                 case 'FRAUD_STATUS_CHANGED':
                     if ($_POST['fraud_status'] == 'pass') {
                         WPI_Functions::log_event(wpi_invoice_id_to_post_id($_POST['vendor_order_id']), 'invoice', 'update', '', __('Passed 2Checkout fraud review.', WPI));
                     } elseif (condition) {
                         WPI_Functions::log_event(wpi_invoice_id_to_post_id($_POST['vendor_order_id']), 'invoice', 'update', '', __('Failed 2Checkout fraud review.', WPI));
                         wp_invoice_mark_as_pending($_POST['vendor_order_id']);
                     }
                     break;
                 case 'RECURRING_STOPPED':
                     WPI_Functions::log_event(wpi_invoice_id_to_post_id($_POST['vendor_order_id']), 'invoice', 'update', '', __('Recurring billing stopped.', WPI));
                     break;
                 case 'RECURRING_INSTALLMENT_FAILED':
                     WPI_Functions::log_event(wpi_invoice_id_to_post_id($_POST['vendor_order_id']), 'invoice', 'update', '', __('Recurring installment failed.', WPI));
                     break;
                 case 'RECURRING_INSTALLMENT_SUCCESS':
                     $event_note = sprintf(__('%1s paid for subscription %2s', WPI), WPI_Functions::currency_format(abs($_POST['item_rec_list_amount_1']), $_POST['vendor_order_id']), $_POST['sale_id']);
                     $event_amount = (double) $_POST['item_rec_list_amount_1'];
                     $event_type = 'add_payment';
                     $invoice->add_entry("attribute=balance&note={$event_note}&amount={$event_amount}&type={$event_type}");
                     $invoice->save_invoice();
                     send_notification($invoice->data);
                     break;
                 case 'RECURRING_COMPLETE':
                     WPI_Functions::log_event(wpi_invoice_id_to_post_id($_POST['vendor_order_id']), 'invoice', 'update', '', __('Recurring installments completed.', WPI));
                     wp_invoice_mark_as_paid($_POST['invoice'], $check = false);
                     break;
                 case 'RECURRING_RESTARTED':
                     WPI_Functions::log_event(wpi_invoice_id_to_post_id($_POST['vendor_order_id']), 'invoice', 'update', '', __('Recurring sale restarted.', WPI));
                     break;
                 default:
                     break;
             }
         }
     }
 }
Beispiel #4
0
 /**
  * Handler for Silent Post Url
  */
 static function server_callback()
 {
     $arb = false;
     $fields = array();
     foreach ($_REQUEST as $name => $value) {
         $fields[$name] = $value;
         if ($name == 'x_subscription_id') {
             $arb = true;
         }
     }
     // Handle recurring billing payments
     if ($arb == true && $fields['x_response_code'] == 1) {
         $paynum = $fields['x_subscription_paynum'];
         $subscription_id = $fields['x_subscription_id'];
         $amount = $fields['x_amount'];
         $invoice_id = wpi_post_id_to_invoice_id(wpi_subscription_id_to_post_id($subscription_id));
         $invoice_obj = new WPI_Invoice();
         $invoice_obj->load_invoice("id={$invoice_id}");
         // Add payment amount
         $event_note = WPI_Functions::currency_format(abs($amount), $invoice_id) . ". ARB payment {$paynum} of {$invoice_obj->data['recurring']['wpi_authorize']['cycles']}";
         $event_amount = $amount;
         $event_type = 'add_payment';
         $invoice_obj->add_entry("attribute=balance&note={$event_note}&amount={$event_amount}&type={$event_type}");
         // Complete subscription if last payment done
         if ($invoice_obj->data['recurring']['wpi_authorize']['cycles'] <= $paynum) {
             WPI_Functions::log_event(wpi_invoice_id_to_post_id($invoice_id), 'invoice', 'update', '', __('Subscription completely paid', WPI));
             wp_invoice_mark_as_paid($invoice_id);
         }
         $invoice_obj->save_invoice();
     }
 }
 /**
  * Merchant CB handler
  */
 static function server_callback()
 {
     if (empty($_POST)) {
         die(__('Direct access not allowed', WPI));
     }
     $invoice = new WPI_Invoice();
     $invoice->load_invoice("id={$_POST['ik_pm_no']}");
     if ($_POST['ik_inv_st'] != 'success') {
         header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error [Cannot process payment]', true, 500);
         return;
     }
     if (!self::_hash_verified($invoice)) {
         header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error [Hash or Shop ID is wrong]', true, 500);
         return;
     }
     if (get_post_meta($invoice->data['ID'], 'wpi_processed_by_interkassa', 1) == 'true') {
         header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error [Already processed]', true, 500);
         return;
     }
     update_post_meta($invoice->data['ID'], 'wpi_processed_by_interkassa', 'true');
     /** Add payment amount */
     $event_note = sprintf(__('%s paid via InterKassa [%s]', WPI), WPI_Functions::currency_format(abs($_POST['ik_am']), $_POST['ik_pm_no']), $_POST['ik_pw_via']);
     $event_amount = (double) $_POST['ik_am'];
     $event_type = 'add_payment';
     //** Log balance changes */
     $invoice->add_entry("attribute=balance&note={$event_note}&amount={$event_amount}&type={$event_type}");
     //** Log payer email */
     $trans_id = sprintf(__("Transaction ID: %s", WPI), $_POST['ik_trn_id']);
     $invoice->add_entry("attribute=invoice&note={$trans_id}&type=update");
     $invoice->save_invoice();
     //** ... and mark invoice as paid */
     wp_invoice_mark_as_paid($_POST['ik_pm_no'], $check = true);
     send_notification($invoice->data);
     echo 'OK';
 }