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; }
/** * Create the recurring payment profile. */ private function create_recurring_payment_plan(SI_Checkouts $checkout, SI_Invoice $invoice) { self::setup_stripe(); try { $invoice_id = $invoice->get_id(); $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); // Recurring Plan the customer will be changed to. $plan = Stripe_Plan::create(array('amount' => self::convert_money_to_cents(sprintf('%0.2f', $price)), 'currency' => self::get_currency_code($invoice_id), 'interval' => $term, 'name' => get_the_title($invoice_id), 'id' => $invoice_id . self::convert_money_to_cents(sprintf('%0.2f', $price)))); do_action('si_log', __CLASS__ . '::' . __FUNCTION__ . ' - Stripe PLAN Response', $plan); do_action('si_stripe_recurring_payment_plan_created', $plan); // Return something for the response return true; } catch (Exception $e) { self::set_error_messages($e->getMessage()); return false; } }