private function create_recurring_payment_nvp_data(SI_Checkouts $checkout, SI_Invoice $invoice, SI_Payment $payment)
 {
     $invoice_id = $invoice->get_id();
     $payment_data = $payment->get_data();
     $term = SI_Subscription_Payments::get_term($invoice_id);
     // day, week, month, or year
     $duration = (int) SI_Subscription_Payments::get_duration($invoice_id);
     $price = SI_Subscription_Payments::get_renew_price($invoice_id);
     $terms = array('day' => 'Day', 'week' => 'Week', 'month' => 'Month', 'year' => 'Year');
     if (!isset($terms[$term])) {
         $term = 'day';
     }
     // The first payment was just now, so
     // the subscription starts based on the term
     $starts = strtotime(date('Y-m-d') . ' +' . $duration . ' ' . $term);
     $user = si_who_is_paying($invoice);
     // User email or none
     $user_email = $user ? $user->user_email : '';
     $nvp = array('USER' => self::$api_username, 'PWD' => self::$api_password, 'SIGNATURE' => self::$api_signature, 'VERSION' => self::$version, 'METHOD' => 'CreateRecurringPaymentsProfile', 'PROFILESTARTDATE' => date('Y-m-d', $starts) . 'T00:00:00Z', 'PROFILEREFERENCE' => $payment->get_id(), 'DESC' => $this->recurring_desc($invoice), 'MAXFAILEDPAYMENTS' => 2, 'AUTOBILLOUTAMT' => 'AddToNextBilling', 'BILLINGPERIOD' => $terms[$term], 'BILLINGFREQUENCY' => $duration, 'TOTALBILLINGCYCLES' => 0, 'AMT' => si_get_number_format($price), 'CURRENCYCODE' => self::get_currency_code($invoice_id), 'EMAIL' => $user_email, 'L_PAYMENTREQUEST_0_ITEMCATEGORY0' => 'Digital', 'L_PAYMENTREQUEST_0_NAME0' => $invoice->get_title(), 'L_PAYMENTREQUEST_0_AMT0' => si_get_number_format($price), 'L_PAYMENTREQUEST_0_NUMBER0' => $invoice_id, 'L_PAYMENTREQUEST_0_QTY0' => 1, 'CREDITCARDTYPE' => self::get_card_type($this->cc_cache['cc_number']), 'ACCT' => $this->cc_cache['cc_number'], 'EXPDATE' => self::expiration_date($this->cc_cache['cc_expiration_month'], $this->cc_cache['cc_expiration_year']), 'CVV2' => $this->cc_cache['cc_cvv'], 'FIRSTNAME' => $checkout->cache['billing']['first_name'], 'LASTNAME' => $checkout->cache['billing']['last_name'], 'STREET' => $checkout->cache['billing']['street'], 'CITY' => $checkout->cache['billing']['city'], 'STATE' => $checkout->cache['billing']['zone'], 'COUNTRYCODE' => self::country_code($checkout->cache['billing']['country']), 'ZIP' => $checkout->cache['billing']['postal_code']);
     return $nvp;
 }
Пример #2
0
 /**
  * Return the user object for the person responsible paying at the time of purchase.
  * @param  SI_Invoice $invoice
  * @return object/false
  */
 function si_whos_user_id_is_paying(SI_Invoice $invoice)
 {
     $user = si_who_is_paying($invoice);
     if (!is_a($user, 'WP_User')) {
         return $user;
     }
     return apply_filters('si_whos_user_id_is_paying', $user->ID, $invoice);
 }
Пример #3
0
 /**
  * Create the recurring payment profile.
  */
 private function add_customer_to_plan(SI_Checkouts $checkout, SI_Invoice $invoice)
 {
     $invoice_id = $invoice->get_id();
     self::setup_stripe();
     try {
         $user = si_who_is_paying($invoice);
         $purchase_data = $this->purchase_data($checkout, $invoice);
         if (!$purchase_data) {
             return false;
         }
         $price = SI_Subscription_Payments::get_renew_price($invoice_id);
         $amount_in_cents = self::convert_money_to_cents(sprintf('%0.2f', $price));
         $balance = si_has_invoice_deposit($invoice_id) ? $invoice->get_deposit() : $invoice->get_balance();
         $subscribe = Stripe_Customer::create(array('card' => $purchase_data, 'plan' => $invoice_id . $amount_in_cents, 'email' => $user->user_email, 'account_balance' => self::convert_money_to_cents(sprintf('%0.2f', $balance - $price))));
         $subscribe = array('id' => $subscribe->id, 'subscription_id' => $subscribe->subscriptions->data[0]->id, 'amount' => $amount_in_cents, 'plan' => $invoice_id . $amount_in_cents, 'card' => $purchase_data, 'email' => $user->user_email);
         // Payment
         $payment_id = SI_Payment::new_payment(array('payment_method' => self::PAYMENT_METHOD, 'invoice' => $invoice_id, 'amount' => $price, 'data' => array('live' => self::MODE_LIVE === self::$api_mode, 'api_response' => $subscribe)), SI_Payment::STATUS_RECURRING);
         do_action('si_stripe_recurring_payment_profile_created', $payment_id);
         // Passed back to create the initial payment
         $response = $subscribe;
         $response['amount'] = $amount_in_cents;
         $response['plan'] = $invoice_id . $amount_in_cents;
         return $response;
     } catch (Exception $e) {
         self::set_error_messages($e->getMessage());
         return false;
     }
 }