How to add tax to Stripe subscription using Laravel Cashier (4.2) - php

I'd like to apply tax to the subscription I have just swapped the user to. Here is my attempt:
protected function swapToYearlyPlan(){
$company = Auth::user()->company;
$customer = $company->subscription()->getStripeCustomer();
$company->subscription('Gold Annual Plan')->swap();
// This doesn't seem to work -- no error message or anything.
$company->subscription()->tax_percent = 5;
return 'Upgraded to Gold Annual Plan w/ tax!!';
}
I looked through the Laravel Cashier files and wasn't able to find any code relating to taxes whatsoever in the StripeGateway.php file. My ultimate fear is that it can't be done in this version of Laravel Cashier.

After more research, it looks like 4.2 doesn't seem to support this feature out of the box. You must separately add tax to an invoice as a separate line item.
I found this post helpful.

Related

"PROMOCODE1" coupon code is not valid

Hi all I will go straight to the point. I found out that when i create a shopping cart price rule in magento and added a promotion/coupon code as indicated above with all rules set correctly to have a discount works from the frontend as expected from customers checkout experience/process.
But when i try to create an order from the backend/admin and trying to apply the promocode1 coupon code to the order for a specific customer it shows it to be invalid. as indicated above.
My Version i am using currently is ver. 1.9.3.6
I hope someone can point me to the right direction or what i may be doing wrong or not doing.
snap shots below
Thanks.
This looks like a bug in magento as after several checks i realized that you have to select 'all store view' option during the creation of the price rule.
Even though you select the specific store view for the price rule, the coupon will not be applied to the order from the backend of magento without you selecting the 'all store view'.
I know this thread is old but I am also getting the same error messages and i resolve my issue by removing the fields reset_shipping: true from sales.js file in js/mage/adminhtml from function applyCoupon. In myside whenever i am applying coupon code then my shipping price is going to reset so coupon code could not apply if shipping price is 0 ( my coupon code is to offer free shipping)

Custom Shipping Rate

I'm trying to customize my onepage checkout in magento. The process is to place orders to the company. Apparently I have set a custom table rate in magento where in I have 2 choices. First choice is Victoria (Australia), where in depending on item size there is a fixed rate for that, while the rest of Australia has the same rate.
Apparently when I use my onepage checkout, I encounter 2 errors:
1st error is that when I am in guest mode, when I fill up the billing information, after I go to the shipping method, it says that my shipping method is unavailable, even if I had already inputted the correct address.
My second error is that when I am using a customer account, everything works fine for the 1st time, then if I try to place another order, it shows the error.
I'm thinking of two ways right now to solve it:
Since I need to fix the problem right away, could I remove the shipping method altogether and just create my own computation at the review tab and save the shipping fee in the end?
Or I try to fix the problem on how the shipping method works?
I found matrix-rate free plugin for magento online. A great alternative instead of manipulating it in the backend. I tried it and it immediately worked, though you need to check if you have the data you need in your database. Use the same steps as you were in modifying table rates, as there will be a new tab for the matrix-rate plugin in the configuration->shipping methods tab.

Get notified on stock unavailability

I am trying to create a "Notify me" feature if the stock is unavailable.
On search on admin panel, I could find only that a user should sign up / log in to get notified about the stock availability.
But I just want to let the user (a guest) enter only his/her email address to get notified.
How should I do this?
Please give suggestions..
EDIT:
I have got this link, which gives me a way to start.
Till now what I did is added the following code in my template file which is creating a url for redirect (thinking to do it in ajax way, to stop page refreshing).
<?php
$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$base64 = strtr(base64_encode($actual_link), '+/=', '-_,');
$postUrl = "http://$_SERVER[HTTP_HOST]/efk/productalert/add/stock/product_id/" . $simpleProduct->getId() . "/uenc/". $base64;
?>
In the above code, efk is my project folder name.
After this, I have gone to productalert/add/stock controller method i.e stockAction() which is calling sign up / login form (I think so) using $model->save();.
How should I disable this save calling and add my own small overlay which holds a textbox to enter a email address?
Magento has "Notify me when product is back in stock" feature out of the box. It can be configured in admin panel: system / configuration / catalog / product alerts and product alerts run settings.
You're right, it works only for registred customers. To make it working for guest users some coding is required. I'd say you need to do the following steps:
Add email column to product_alert_stock table
Create new controller and action (believe me, it's better than you override existing one via config.xml) which extends Mage_ProductAlert_AddController::stockAction(). Your method will have to set guest's email to productalert/stock model.
Create subscription form and make sure it submits data to your new controller/action.
Update (override) Mage_ProductAlert_Model_Observer::_processStock() method to make it respect situations when "customer" has no ID but has email.
When you'll be testing, I suggest you to install SMTP Pro Email extension and mailcatcher to ease the testing process.
We have done this (http://www.alfresia.co.uk/sorrento-side-table.html/). Here we ended up creating a custom module as when we did this magento did not support any product alert system for the guest users (i do not know if this is supported now).
We first created a text box which would appear on product page where the product is out of stock. We were saving this info in one of our custom tables where we the schema was {id, email, product_sku, status} (status had three values Awaiting Stock, In Stock, and Already Notified).
We then wrote an observer which was hooked to cataloginventory_stock_item_save_after event, this helped us get the product sku which has been back in stock, and update all entries in our custom table with status In Stock and send a mail to the user.
This is how we did it, surely there will be a much cleaner way doing this.
You could have work with plugins. MagentoCommerce has loads of plugins/extensions which does the same
Free Version - http://www.magentocommerce.com/magento-connect/product-out-of-stock-subscription-1350.html
I too had similar requirement, and have installed 'http://www.magentocommerce.com/magento-connect/product-out-of-stock-subscription-1350.html' this plugin.
Well this plugin does the job, But they have override complete product view page template instead of simply adding a new block. By this your custom development on product view page development might get reflected on frontend.
Or else this plugin definitely does the job.
This http://www.magentocommerce.com/magento-connect/product-out-of-stock-subscription-1350.html plugin is really good but it breaks for configurable product types and it completely overrides the product controller which makes your system vulnerable to future upgrades. I think observers should be hooked to events where the product is back in stock and should update the users.

Magento - Single Coupon marked as used when payment pending

I have got a problem with Magento single coupon code that is marked as having been used at the time the customer clicks on the Place Order button. If the Paypal payment fails or the client leaves the page before the order is complete, he won't able to go back and re-order with this coupon which is set to be only used once, and has been marked already been used.
I have found a piece of code that decreases the number of times the coupons has been used by the user and allows him to reuse the coupon. Unfortunately, he gets an error when trying to connect the Paypal page when clicking the place order button. In order to be able to use the coupon another time and access the Paypal page, I have to delete the lines in SQL database in tables salesrule_coupon_usage and salesrule_customer with this customer's ID.
Here is the code I need to change to automatically delete coupon usage information for a customer ID:
public function cancel($observer)
{
$order = $observer->getEvent()->getPayment()->getOrder();
if ($order->canCancel()) {
if ($code = $order->getCouponCode()) {
$coupon = Mage::getModel('salesrule/coupon')->load($code, 'code');
if ($coupon->getTimesUsed() > 0) {
$coupon->setTimesUsed($coupon->getTimesUsed() - 1);
$coupon->save();
}
$rule = Mage::getModel('salesrule/rule')->load($coupon->getRuleId());
error_log("\nrule times used=" . $rule->getTimesUsed(), 3, "var/log/debug.log");
if ($rule->getTimesUsed() > 0) {
$rule->setTimesUsed($rule->getTimesUsed()-1);
$rule->save();
}
if ($customerId = $order->getCustomerId()) {
if ($customerCoupon = Mage::getModel('salesrule/rule_customer')->loadByCustomerRule($customerId, $rule->getId())) {
$couponUsage = new Varien_Object();
Mage::getResourceModel('salesrule/coupon_usage')->loadByCustomerCoupon($couponUsage, $customerId, $coupon->getId());
if ($couponUsage->getTimesUsed() > 0) {
/* I can't find any ##$!#$ interface to do anything but increment a coupon_usage record */
$resource = Mage::getSingleton('core/resource');
$writeConnection = $resource->getConnection('core_write');
$tableName = $resource->getTableName('salesrule_coupon_usage');
$query = "UPDATE {$tableName} SET times_used = times_used-1 "
. "WHERE coupon_id = {$coupon->getId()} AND customer_id = {$customerId} AND times_used > 0";
$writeConnection->query($query);
}
if ($customerCoupon->getTimesUsed() > 0) {
$customerCoupon->setTimesUsed($customerCoupon->getTimesUsed()-1);
$customerCoupon->save();
}
}
}
}
}
}
I believe this was an old bug from around 1.4 to maybe 1.6. But whether you've got an old version or not, this can fairly easily be fixed in place if you know your way around Magento.
The problem is, you have code that is updating the salesrule_coupon_usage table right when they click the pay button. This isn't really what you want at all. You want this to be wrapped into the payment transaction. I don't know if this bug is happening because you have custom code or are using a older version of Magento, but I'll tell you how I would fix the problem. Then I'll give you a fix similar to what you proposed:
Magento already has an abstraction called a "transaction". A transaction is used to put and group of objects together that need to either all succeed or all fail, no half-measures. Magento will go through the transaction and attempt to save each of the objects you have placed in it. If any of them fail (for example, payment doesn't go through), all the events that have been already saved are "rolled back".
Luckily, Magento already creates a transaction object to handle payment for the various things that need to update together on successful payment. You can tap into that transaction and use it to update the coupon usage correctly.
Here is the 10,000 foot view of what you need to do.
Find whatever is updating the salesrule_coupon_usage table too early and kill it. We are going to add in our own transaction-safe version, so we don't want it being saved anywhere else. Easiest way to do this is to figure out what model connects to that table and search for the creation of that model. For 1.7 and 1.8, that is the rule/customer model.
Create an observer to catch the start of a payment transaction. In most modern versions of magento this event is called sales_order_payment_place_start and can be witnessed in app/code/core/Mage/Sales/Model/Order/Payment.php
Pull the order out of the event and pull the coupon code out of the event.
Pull the actual model you want to update. It looks like someone couldn't find it in your code, but there should be some model that uses the salesrule_coupon_usage table hiding somewhere. Search though the .xml files for "salesrule_coupon_usage" and see which model using that table. Again, for me, on 1.7, that is the rule/customer model.
Load that model up, with the customer change the value where your coupon code is concerned to indicate that the customer has used the coupon, but don't save yet.
Get the transaction out of the event and register your updated coupon object with the addObject method.
And your done. The transaction will automatically try to save all of the objects that have been added to it. If any part fails (including a failed payment), it'll rollback the whole process and your coupon won't be used. Yay!
Now, in my opinion, the above is the best way to handle the issue, but if you are having issues for some reason, here is an alternative based on catching an unsuccessful payment and then using your code.
Again, here is the 10,000 foot view:
Create an observer to catch the failed payment event. In most versions the event you want is sales_order_payment_cancel.
Run the code you've got... it should do it. But to clarify for others:
Pull the order out of the event, pull the coupon code and customer id out of that.
Update the customer, rule and salesrule_coupon_usage table. (Although there really should be a model for that, I'm sure you can find it)
Now when a sale fails, you go back through and unwind everything manually. This isn't as clean as my first solution, but might be easier for you depending on your familiarity with Magento.
I'm fairly sure that new, clean versions of Magento don't have this issue, so let me offer a fairly obvious suggestion as a third solution.
Update Magento
If Magento is up to date, test disabling any custom modules, because something broke it. I've noticed that Amasty coupon plugins are particularly buggy.
If you've made custom changes to Magento core... good luck with that.
Good luck!

Payment Options not appearing in Magento

a bit of a funny one for you this afternoon.
This is in Magento 1.5.1.0...
Essentially, my website sells products that are free (£0.00) however the customer has to pay for delivery. The problem that I’m having, is that at checkout, the Payment Methods simply doesn’t load whenever the basket sub total is 0. Even when the Grand Total with Shipping is an amount.
I’m running One Step Checkout, however it doesn’t work on the default One Page Checkout either.
I’ve tried everything, and I’m certain that it’s not got anything to do with the Payment Gateways that I’m using.
I tried the same thing on another site of mine, that’s running 1.4 and it works fine on there?
You can see a screenshot of the page with the problem here...
Any help would be really appreciated.
Check that you have: "Zero Subtotal Checkout" enabled under: System -> Configuration -> Payment Methods.
Subtotal is pre shipping, tax and discounts, this payment option exists specifically for your circumstance.

Categories