public function newAction() { $this->logger->entering(); $this->logger->info('Loading user'); $users = new User(); $user = $users->find($this->session->user_id)->current(); $this->logger->info('Finding line items of the user'); $lineItemTable = new LineItem(); $where = $this->db->quoteInto('user_id = ?', $user->id); $lineItems = $lineItemTable->fetchAll($where); $items = array(); $swapbucksTotal = 0; $transactionTotal = 0; foreach ($lineItems as $lineItem) { $item = $lineItem->findParentRow('Item'); if (1 == $lineItem->shipping) { $shippingCharge = Item::shippingCharge($item->weight); } else { $shippingCharge = 0; } $items[$item->name] = array('quantity' => 1, 'transFee' => 1, 'item_id' => $item->id, 'title' => $item->name, 'price' => $item->points, 'line_item_id' => $lineItem->id, 'user_id' => $lineItem->user_id, 'shipping_method' => $lineItem->shipping, 'shipping_charge' => $shippingCharge, 'total' => $item->points + $shippingCharge); $swapbucksTotal += $items[$item->name]['total']; $transactionTotal += $items[$item->name]['transFee']; } $this->logger->info('Determine swapbucks to be bought'); $swapbucksToBuy = null; if ($swapbucksTotal > $user->balance) { $swapbucksToBuy = $swapbucksTotal - $user->balance; $items['Swapbucks'] = array('title' => 'Swapbucks', 'quantity' => $swapbucksToBuy, 'price' => 0, 'shipping_charge' => 0, 'total' => 0, 'transFee' => $swapbucksToBuy); $transactionTotal += $swapbucksToBuy; $finalBalance = 0; } else { $finalBalance = $user->balance - $swapbucksTotal; } $paypalParams = array('cmd' => '_xclick', 'business' => '*****@*****.**', 'return' => 'http://swaplady.com/transactions/create', 'cancel_return' => 'http://swaplady.com/', 'currency_code' => 'USD', 'item_name' => 'Swaplady', 'amount' => $transactionTotal, 'no_shipping' => '1'); $paypal = new PayPalEWP(); $paypal->setTempFileDirectory('../tmp'); //path to temp file $paypal->setCertificate('../config/pubcert.pem', '../config/prvkey.pem'); //path to your public certificate, private key $paypal->setCertificateID('KF4WJNF89QEN6'); //certificate id generated by PayPal when you uploaded your public certificate to your PayPal account $paypal->setPayPalCertificate('../config/sandbox_pubcert.pem'); //PayPal public certificate $encryptedButton = $paypal->encryptButton($paypalParams); $this->logger->info('Populating the View'); $this->view->assign(array('title' => 'Shopping Bag', 'user' => $user, 'swapbucksTotal' => $swapbucksTotal, 'transactionTotal' => $transactionTotal, 'swapbucksToBuy' => $swapbucksToBuy, 'finalBalance' => $finalBalance, 'items' => $items, 'paypalParams' => $paypalParams, 'encryptedButton' => $encryptedButton)); $this->render(); $this->logger->exiting(); }
function yab_shop_build_paypal_encrypted_form($cart) { global $tempdir; $subdomain = ''; if (yab_shop_config('paypal_live_or_sandbox') == 'sandbox') { $subdomain = '.sandbox'; } $email = ''; if (ps('email')) { $email = yab_shop_return_input('email'); } $state = ''; if (ps('state|r')) { $state = yab_shop_return_input('state|r'); } $tax = '0.00'; if (yab_shop_config('tax_inclusive') == '0') { $tax = number_format(yab_shop_calculate_sum('tax'), 2); } $action = 'https://www' . $subdomain . '.paypal.com/cgi-bin/webscr'; $message = yab_shop_lang('checkout_paypal_no_forward'); $message2 = yab_shop_lang('checkout_paypal_forward'); $business_email = yab_shop_config('paypal_business_mail'); $country = yab_shop_config('paypal_prefilled_country'); $lc = yab_shop_config('paypal_interface_language'); $section = pagelinkurl(array('s' => yab_shop_config('checkout_section_name'))); $currency = yab_shop_config('currency'); $shipping = yab_shop_shipping_costs(); $myPublicCertificate = yab_shop_config('paypal_certificates_path') . '/' . yab_shop_config('paypal_my_public_certificate_name'); $myPrivateKey = yab_shop_config('paypal_certificates_path') . '/' . yab_shop_config('paypal_my_private_key_name'); $CertificateID = yab_shop_config('paypal_certificate_id'); $PayPalPublicCertificate = yab_shop_config('paypal_certificates_path') . '/' . yab_shop_config('paypal_public_certificate_name'); $paypal = new PayPalEWP(); $paypal->setTempDir($tempdir); $paypal->setCertificate($myPublicCertificate, $myPrivateKey); $paypal->setCertificateID($CertificateID); $paypal->setPayPalCertificate($PayPalPublicCertificate); $parameters = array('cmd' => '_ext-enter', 'redirect_cmd' => '_cart', 'upload' => '1', 'business' => $business_email, 'cert_id' => $CertificateID, 'return' => $section, 'country' => $country, 'lc' => $lc, 'currency_code' => $currency, 'tax_cart' => $tax, 'shipping_1' => $shipping, 'first_name' => yab_shop_return_input('firstname|r'), 'last_name' => yab_shop_return_input('surname|r'), 'email' => $email, 'address1' => yab_shop_return_input('street|r'), 'city' => yab_shop_return_input('city|r'), 'zip' => yab_shop_return_input('postal|r'), 'state' => $state); $i = 0; foreach ($cart->get_contents() as $item) { $i++; $parameters['item_name_' . $i] = $item['name']; $parameters['amount_' . $i] = $item['price']; $parameters['quantity_' . $i] = $item['qty']; if (!empty($item['property_1'])) { $parameters['on0_' . $i] = yab_shop_lang('custom_field_property_1'); $parameters['os0_' . $i] = $item['property_1']; } if (!empty($item['property_2'])) { if (!empty($item['property_3'])) { $parameters['on1_' . $i] = yab_shop_lang('custom_field_property_2') . '/' . yab_shop_lang('custom_field_property_3'); $parameters['os1_' . $i] = $item['property_2'] . '/' . $item['property_3']; } else { $parameters['on1_' . $i] = yab_shop_lang('custom_field_property_2'); $parameters['os1_' . $i] = $item['property_2']; } } else { if (!empty($item['property_3'])) { $parameters['on1_' . $i] = yab_shop_lang('custom_field_property_3'); $parameters['os1_' . $i] = $item['property_3']; } } } if (ps('email')) { $parameters['email'] = yab_shop_return_input('email'); } $encryptedButton = $paypal->encryptButton($parameters); $form = '<script type="text/javascript">function doPaypal(){var New="' . $message2 . '";document.getElementById("yabshoppaypalforward").innerHTML=New;document.getElementById("yab-paypal-form").submit();document.getElementById("yabpaypalsubmit").style.display="none"}window.onload=doPaypal;</script>'; $form .= graf($message, ' class="yab-shop-message" id="yabshoppaypalforward"'); $form .= tag(hInput('cmd', '_s-xclick') . n . hInput('encrypted', $encryptedButton) . n . fInput('submit', 'paypal', yab_shop_lang('checkout_paypal_button'), 'submit', '', '', '', '', 'yabpaypalsubmit') . n, 'form', ' method="post" action="' . $action . '" id="yab-paypal-form"'); switch ($paypal->error) { case 0: $out = $form; break; case 1: $out = 'Paypal certificate id is not set!'; break; case 2: $out = 'Your public and/or private certificate is not readable! Please check permissions, names and paths!'; break; case 3: $out = 'Paypal public certificate is not readable! Please check permissions, names and paths!'; break; case 4: $out = 'Seems to be openssl is not supported!'; break; default: $out = 'Unkown error occured!'; } return $out; }