/**
  * Update a referral to Unpaid when a payment is completed
  *
  * @access  public
  * @since   1.6
  */
 public function mark_referral_complete(SI_Payment $payment)
 {
     $payment_id = $payment->get_id();
     $this->complete_referral($payment_id);
     $referral = affiliate_wp()->referrals->get_by('reference', $payment_id, $this->context);
     if (!is_object($referral)) {
         return;
     }
     $amount = affwp_currency_filter(affwp_format_amount($referral->amount));
     $name = affiliate_wp()->affiliates->get_affiliate_name($referral->affiliate_id);
     $note = sprintf(__('Referral #%d for %s recorded for %s', 'affiliate-wp'), $referral->referral_id, $amount, $name);
     $new_data = wp_parse_args($payment->get_data(), array('affwp_notes' => $note));
     $payment->set_data($new_data);
 }
 public static function payment_data(SI_Payment $payment)
 {
     $payment_data = array('title' => $payment->get_title(), 'id' => $payment->get_id(), 'status' => $payment->get_status(), 'payment_method' => $payment->get_payment_method(), 'amount' => $payment->get_amount(), 'invoice_id' => $payment->get_invoice_id(), 'data' => $payment->get_data());
     $invoice = SI_Invoice::get_instance($payment->get_invoice_id());
     if (is_a($invoice, 'SI_Invoice')) {
         $payment_data['invoice_data'] = self::invoice_data($invoice);
     }
     return $payment_data;
 }
 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;
 }
 public static function invoice_has_subscription_payments($bool, SI_Invoice $invoice, SI_Payment $payment)
 {
     // Set the payment token on the invoice.
     $data = $payment->get_data();
     if (isset($data['payment_token'])) {
         self::set_token($invoice->get_id(), $data['payment_token']);
         // has subscription options
         return self::has_subscription_payment($invoice->get_id());
     }
     return $bool;
 }