/** * Build the NVP data array for submitting the current checkout to PayPal as an Authorization request * * @param SI_Checkouts $checkout * @return array */ private function set_nvp_data(SI_Checkouts $checkout) { $invoice = $checkout->get_invoice(); $client = $invoice->get_client(); $user = si_who_is_paying($invoice); // User email or none $user_email = $user ? $user->user_email : ''; $nvpData = array(); $nvpData['USER'] = self::$api_username; $nvpData['PWD'] = self::$api_password; $nvpData['SIGNATURE'] = self::$api_signature; $nvpData['VERSION'] = self::$version; $nvpData['CANCELURL'] = self::$cancel_url; $nvpData['RETURNURL'] = $checkout->checkout_complete_url($this->get_slug()); $nvpData['METHOD'] = 'SetExpressCheckout'; $nvpData['PAYMENTREQUEST_0_PAYMENTACTION'] = 'Authorization'; $nvpData['EMAIL'] = $user_email; $nvpData['LANDINGPAGE'] = 'Billing'; $nvpData['SOLUTIONTYPE'] = 'Sole'; $payment_amount = si_has_invoice_deposit($invoice->get_id()) ? $invoice->get_deposit() : $invoice->get_balance(); $nvpData['PAYMENTREQUEST_0_AMT'] = si_get_number_format($payment_amount); $nvpData['PAYMENTREQUEST_0_CURRENCYCODE'] = self::get_currency_code($invoice->get_id()); $item_amount = si_has_invoice_deposit($invoice->get_id()) ? $invoice->get_deposit() : $invoice->get_balance() - ($invoice->get_tax_total() + $invoice->get_tax2_total()); $nvpData['PAYMENTREQUEST_0_ITEMAMT'] = si_get_number_format($item_amount); // $nvpData['PAYMENTREQUEST_0_SHIPPINGAMT'] = si_get_number_format( $invoice->get_shipping_total() ); // FUTURE $tax_amount = si_has_invoice_deposit($invoice->get_id()) ? 0 : $invoice->get_tax_total() + $invoice->get_tax2_total(); $nvpData['PAYMENTREQUEST_0_TAXAMT'] = si_get_number_format($tax_amount); $nvpData['BUTTONSOURCE'] = self::PLUGIN_NAME; $nvpData += self::payment_request_line_items($invoice); // Recurring billing agreement if (si_is_invoice_recurring($invoice)) { $nvpData['L_BILLINGTYPE0'] = 'RecurringPayments'; $nvpData['L_BILLINGAGREEMENTDESCRIPTION0'] = $this->recurring_desc($invoice); } $nvpData = apply_filters('si_paypal_ec_set_nvp_data', $nvpData); do_action('si_log', __CLASS__ . '::' . __FUNCTION__ . ' - PayPal EC SetCheckout Data', $nvpData); return apply_filters('si_set_nvp_data', $nvpData, $checkout, $i); }
/** * Charge via Stripe API using a token or the full credit card data. * * @param SI_Checkouts $checkout * @param SI_Invoice $purchase * @return array */ private function charge_stripe(SI_Checkouts $checkout, SI_Invoice $invoice) { $invoice = $checkout->get_invoice(); $client = $invoice->get_client(); $user_id = si_whos_user_id_is_paying($invoice); self::setup_stripe(); try { // Create the payment data for the customer $purchase_data = $this->purchase_data($checkout, $invoice); if (!$purchase_data) { return false; } // Create the customer $customer_id = $this->get_customer($user_id, $purchase_data); if (!$customer_id) { self::set_error_messages('ERROR: No customer id was created.'); return false; } $payment_amount = si_has_invoice_deposit($invoice->get_id()) ? $invoice->get_deposit() : $invoice->get_balance(); // Charge the card! $charge = Stripe_Charge::create(array('amount' => self::convert_money_to_cents(sprintf('%0.2f', $payment_amount)), 'currency' => self::get_currency_code($invoice->get_id()), 'customer' => $customer_id, 'description' => get_the_title($invoice->get_id()))); $response = array('id' => $charge->id, 'amount' => $charge->amount, 'customer' => $charge->customer, 'card' => $charge->card->id); // Return something for the response return $response; } catch (Exception $e) { self::set_error_messages($e->getMessage()); return false; } }