Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $paypal_config = $this->config('uc_paypal.settings');
     $session = \Drupal::service('session');
     $order = Order::load($session->get('cart_order'));
     if (!$form_state->isValueEmpty('shippable')) {
         $quote_option = explode('---', $form_state->getValue(['quotes', 'quote_option']));
         $order->quote['method'] = $quote_option[0];
         $order->quote['accessorials'] = $quote_option[1];
         $method = ShippingQuoteMethod::load($quote_option[0]);
         $label = $method['quote']['accessorials'][$quote_option[1]];
         //      $label = $method->label();
         $quote_option = $form_state->getValue(['quotes', 'quote_option']);
         $order->quote['rate'] = $form_state->getValue(['quotes', $quote_option, 'rate']);
         $result = db_query("SELECT line_item_id FROM {uc_order_line_items} WHERE order_id = :id AND type = :type", [':id' => $order->id(), ':type' => 'shipping']);
         if ($lid = $result->fetchField()) {
             uc_order_update_line_item($lid, $label, $order->quote['rate']);
         } else {
             uc_order_line_item_add($order->id(), 'shipping', $label, $order->quote['rate']);
         }
     }
     if ($paypal_config->get('ec_review_company')) {
         $order->delivery_company = $form_state->getValue('delivery_company');
     }
     if ($paypal_config->get('ec_review_phone')) {
         $order->delivery_phone = $form_state->getValue('delivery_phone');
     }
     if ($paypal_config->get('ec_review_comment')) {
         db_delete('uc_order_comments')->condition('order_id', $order->id())->execute();
         uc_order_comment_save($order->id(), 0, $form_state->getValue('order_comments'), 'order');
     }
     $order->save();
     $form_state->setRedirect('uc_paypal.ec_submit');
 }
Exemplo n.º 2
0
// Create and load administrator
$user = UserFactory::registerUser('*****@*****.**', 'johnsmith', 'John Smith', 'Administrator');
// Load user by email
$user = new User('*****@*****.**');
// Load user by login
$user = new User('johndoe', 'login');
// Check if subscription is valid
$user->isSubscribed();
// Buy subscription via PayPal for 4 days
Subscription::buy($user, 4, new PayPal(), $paymentDetails);
// Buy subscription via PayPal for 10 days
Subscription::buy($user, 10, new WebMoney(), $paymentDetails);
// Load a product by title
$product = new Product('TV');
// Load a product by ID
$product = new Product(736);
// Get product info
$product->getProductInfo();
// Buy the product
$order = $product->buy($user, new PayPal(), $paymentDetails);
// Get order by ID
$order = new Order();
$order->load(123);
// Set different statuses of order
$order->changeStatus(Order::ORDER_STATUS_CANCELLED);
$order->changeStatus(Order::ORDER_STATUS_IN_PROGRESS);
$order->changeStatus(Order::ORDER_STATUS_CLOSED);
$adminUser = new User('*****@*****.**');
$report = new OrderCollection($adminUser);
// Get sum of sold special product in a date rang for specific user
$sum = $report->addDateRangeFilter('2015-02-05', '2015-02-09')->addUserFilter($user)->addSpecialProductsFilter();
Exemplo n.º 3
0
 public function wppCharge($order_id, $amount, $data)
 {
     $order = Order::load($order_id);
     $paypal_config = $this->config('uc_paypal.settings');
     if ($data['txn_type'] == UC_CREDIT_PRIOR_AUTH_CAPTURE) {
         $nvp_request = array('METHOD' => 'DoCapture', 'AUTHORIZATIONID' => $data['auth_id'], 'AMT' => uc_currency_format($amount, FALSE, FALSE, '.'), 'CURRENCYCODE' => $order->getCurrency(), 'COMPLETETYPE' => 'Complete');
     } else {
         list($desc, $subtotal) = _uc_paypal_product_details($order->products);
         if (intval($order->payment_details['cc_exp_month']) < 10) {
             $expdate = '0' . $order->payment_details['cc_exp_month'] . $order->payment_details['cc_exp_year'];
         } else {
             $expdate = $order->payment_details['cc_exp_month'] . $order->payment_details['cc_exp_year'];
         }
         $cc_type = NULL;
         if (isset($order->payment_details['cc_type'])) {
             switch (strtolower($order->payment_details['cc_type'])) {
                 case 'amex':
                 case 'american express':
                     $cc_type = 'Amex';
                     break;
                 case 'visa':
                     $cc_type = 'Visa';
                     break;
                 case 'mastercard':
                 case 'master card':
                     $cc_type = 'MasterCard';
                     break;
                 case 'discover':
                     $cc_type = 'Discover';
                     break;
             }
         }
         if (is_null($cc_type)) {
             $cc_type = $this->cardType($order->payment_details['cc_number']);
             if ($cc_type === FALSE) {
                 drupal_set_message(t('The credit card type did not pass validation.'), 'error');
                 \Drupal::logger('uc_paypal')->error('Could not figure out cc type: @number / @type', ['@number' => $order->payment_details['cc_number'], '@type' => $order->payment_details['cc_type']]);
                 return array('success' => FALSE);
             }
         }
         // PayPal doesn't accept IPv6 addresses.
         $ip_address = ltrim(\Drupal::request()->getClientIp(), '::ffff:');
         $nvp_request = array('METHOD' => 'DoDirectPayment', 'PAYMENTACTION' => $data['txn_type'] == UC_CREDIT_AUTH_ONLY ? 'Authorization' : 'Sale', 'IPADDRESS' => $ip_address, 'AMT' => uc_currency_format($amount, FALSE, FALSE, '.'), 'CREDITCARDTYPE' => $cc_type, 'ACCT' => $order->payment_details['cc_number'], 'EXPDATE' => $expdate, 'CVV2' => $order->payment_details['cc_cvv'], 'FIRSTNAME' => substr($order->billing_first_name, 0, 25), 'LASTNAME' => substr($order->billing_last_name, 0, 25), 'STREET' => substr($order->billing_street1, 0, 100), 'STREET2' => substr($order->billing_street2, 0, 100), 'CITY' => substr($order->billing_city, 0, 40), 'STATE' => $order->billing_zone, 'ZIP' => $order->billing_postal_code, 'COUNTRYCODE' => $order->billing_country, 'CURRENCYCODE' => $order->getCurrency(), 'DESC' => substr($desc, 0, 127), 'INVNUM' => $order_id . '-' . REQUEST_TIME, 'BUTTONSOURCE' => 'Ubercart_ShoppingCart_DP_US', 'NOTIFYURL' => Url::fromRoute('uc_paypal.ipn', [], ['absolute' => TRUE])->toString(), 'EMAIL' => substr($order->getEmail(), 0, 127), 'PHONENUM' => substr($order->billing_phone, 0, 20));
         if ($order->isShippable() && !empty($order->delivery_first_name)) {
             $shipdata = array('SHIPTONAME' => substr($order->delivery_first_name . ' ' . $order->delivery_last_name, 0, 25), 'SHIPTOSTREET' => substr($order->delivery_street1, 0, 100), 'SHIPTOSTREET2' => substr($order->delivery_street2, 0, 100), 'SHIPTOCITY' => substr($order->delivery_city, 0, 40), 'SHIPTOSTATE' => $order->delivery_zone, 'SHIPTOZIP' => $order->delivery_postal_code, 'SHIPTOCOUNTRYCODE' => $order->delivery_country);
             $nvp_request += $shipdata;
         }
         if ($paypal_config->get('uc_credit_cvv_enabled')) {
             $nvp_request['CVV2'] = $order->payment_details['cc_cvv'];
         }
     }
     $nvp_response = uc_paypal_api_request($nvp_request, $paypal_config->get('wpp_server'));
     $types = uc_credit_transaction_types();
     switch ($nvp_response['ACK']) {
         case 'SuccessWithWarning':
             \Drupal::logger('uc_paypal')->warning('<b>@type succeeded with a warning.</b>@paypal_message', array('@paypal_message' => $this->buildErrorMessages($nvp_response), '@type' => $types[$data['txn_type']], 'link' => Link::createFromRoute(t('view order'), 'entity.uc_order.canonical', ['uc_order' => $order_id])->toString()));
             // Fall through.
         // Fall through.
         case 'Success':
             $message = t('<b>@type</b><br /><b>Success: </b>@amount @currency', ['@type' => $types[$data['txn_type']], '@amount' => uc_currency_format($nvp_response['AMT'], FALSE), '@currency' => $nvp_response['CURRENCYCODE']]);
             if ($data['txn_type'] != UC_CREDIT_PRIOR_AUTH_CAPTURE) {
                 $message .= '<br />' . t('<b>Address:</b> @avscode', ['@avscode' => $this->avscodeMessage($nvp_response['AVSCODE'])]);
                 if ($paypal_config->get('uc_credit_cvv_enabled')) {
                     $message .= '<br />' . t('<b>CVV2:</b> @cvvmatch', ['@cvvmatch' => $this->cvvmatchMessage($nvp_response['CVV2MATCH'])]);
                 }
             }
             $result = array('success' => TRUE, 'comment' => t('PayPal transaction ID: @transactionid', ['@transactionid' => $nvp_response['TRANSACTIONID']]), 'message' => $message, 'data' => SafeMarkup::checkPlain($nvp_response['TRANSACTIONID']), 'uid' => $this->currentUser()->id());
             // If this was an authorization only transaction...
             if ($data['txn_type'] == UC_CREDIT_AUTH_ONLY) {
                 // Log the authorization to the order.
                 uc_credit_log_authorization($order_id, $nvp_response['TRANSACTIONID'], $nvp_response['AMT']);
             } elseif ($data['txn_type'] == UC_CREDIT_PRIOR_AUTH_CAPTURE) {
                 uc_credit_log_prior_auth_capture($order_id, $data['auth_id']);
             }
             // Log the IPN to the database.
             db_insert('uc_payment_paypal_ipn')->fields(array('order_id' => $order->id(), 'txn_id' => $nvp_response['TRANSACTIONID'], 'txn_type' => 'web_accept', 'mc_gross' => $amount, 'status' => 'Completed', 'payer_email' => $order->getEmail(), 'received' => REQUEST_TIME))->execute();
             break;
         case 'FailureWithWarning':
             // Fall through.
         // Fall through.
         case 'Failure':
             $message = t('<b>@type failed.</b>', ['@type' => $types[$data['txn_type']]]) . $this->buildErrorMessages($nvp_response);
             $result = array('success' => FALSE, 'message' => $message, 'uid' => $this->currentUser()->id());
             break;
         default:
             $message = t('Unexpected acknowledgement status: @status', ['@status' => $nvp_response['ACK']]);
             $result = array('success' => NULL, 'message' => $message, 'uid' => $this->currentUser()->id());
             break;
     }
     uc_order_comment_save($order_id, $this->currentUser()->id(), $message, 'admin');
     // Don't log this as a payment money wasn't actually captured.
     if (in_array($data['txn_type'], array(UC_CREDIT_AUTH_ONLY))) {
         $result['log_payment'] = FALSE;
     }
     return $result;
 }
Exemplo n.º 4
0
Arquivo: ipn.php Projeto: yuantw/Shine
<?php

require 'includes/master.inc.php';
$pp = new PayPal();
if ($pp->process()) {
    $app = new Application();
    $app->select($_POST['item_number']);
    if (!$app->ok()) {
        error_log("Application {$_POST['item_name']} {$_POST['item_number']} not found!");
        exit;
    }
    $o = new Order();
    $o->load($_POST);
    $o->app_id = $app->id;
    $o->dt = dater();
    $o->type = 'PayPal';
    $o->insert();
    $o->generateLicense();
    $o->emailLicense();
}
Exemplo n.º 5
0
 /**
  * Saves this shipment.
  */
 public function save()
 {
     $this->changed = time();
     $fields = array();
     if (isset($this->origin)) {
         foreach ($this->origin as $field => $value) {
             $field = 'o_' . $field;
             $fields[$field] = $value;
         }
     }
     if (isset($this->destination)) {
         foreach ($this->destination as $field => $value) {
             $field = 'd_' . $field;
             $fields[$field] = $value;
         }
     }
     // Yuck.
     $fields += array('order_id' => $this->order_id, 'shipping_method' => $this->shipping_method, 'accessorials' => $this->accessorials, 'carrier' => $this->carrier, 'transaction_id' => $this->transaction_id, 'tracking_number' => $this->tracking_number, 'ship_date' => $this->ship_date, 'expected_delivery' => $this->expected_delivery, 'cost' => $this->cost, 'changed' => $this->changed);
     if (!isset($this->sid)) {
         //  drupal_write_record('uc_shipments', $shipment);
         $this->sid = db_insert('uc_shipments')->fields($fields)->execute();
         $this->is_new = TRUE;
     } else {
         //  drupal_write_record('uc_shipments', $shipment, 'sid');
         db_update('uc_shipments')->fields($fields)->condition('sid', $this->sid, '=')->execute();
         $this->is_new = FALSE;
     }
     if (is_array($this->packages)) {
         foreach ($this->packages as $package) {
             $package->sid = $this->sid;
             // Since the products haven't changed, we take them out of the object so
             // that they are not deleted and re-inserted.
             $products = $package->products;
             unset($package->products);
             drupal_set_message("here" . print_r($fields, true));
             $package->save();
             // But they're still necessary for hook_uc_shipment(), so they're added
             // back in.
             $package->products = $products;
         }
     }
     \Drupal::moduleHandler()->invokeAll('uc_shipment', array('save', $this));
     $order = Order::load($this->order_id);
     // rules_invoke_event('uc_shipment_save', $order, $shipment);
 }
Exemplo n.º 6
0
 /**
  * Presents the final total to the user for checkout!
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse|array
  *   A redirect to the cart or a build array.
  */
 public function ecSubmit()
 {
     if (!$session->has('TOKEN') || !($order = Order::load($session->get('cart_order')))) {
         $session->remove('cart_order');
         $session->remove('have_details');
         $session->remove('TOKEN');
         $session->remove('PAYERID');
         drupal_set_message($this->t('An error has occurred in your PayPal payment. Please review your cart and try again.'));
         $this->redirect('uc_cart.cart');
     }
     $build['#attached']['library'][] = 'uc_cart/uc_cart.styles';
     $build['review'] = array('#theme' => 'uc_cart_review_table', '#items' => $order->products, '#show_subtotal' => FALSE);
     $build['line_items'] = uc_order_pane_line_items('customer', $order);
     $build['instructions'] = array('#prefix' => '<p>', '#markup' => $this->t("Your order is not complete until you click the 'Submit order' button below. Your PayPal account will be charged for the amount shown above once your order is placed. You will receive confirmation once your payment is complete."), '#suffix' => '</p>');
     $build['submit_form'] = $this->formBuilder()->getForm('\\Drupal\\uc_paypal\\Form\\EcSubmitForm');
     return $build;
 }
Exemplo n.º 7
0
<html>
<head>
<?php 
require_once "functions.php";
require_once "database.php";
require_once "order.php";
?>
</head>
<body>
<h1>test.order</h1>

<?php 
dbconnect();
echo "<h2>Order::loadbyOrderIx</h2>";
$order = new Order();
$order->loadByOrderIx(1);
echo "<pre>";
print_r($order);
echo "</pre>";
echo "<h2>Order::load</h2>";
$order = new Order();
$order->load(1);
echo "<pre>";
print_r($order);
echo "</pre>";
?>

</body>
</html>