There is a coupon_code variable listed on this page of the CartThrob docs:
http://cartthrob.com/docs/tags_detail/coupon_info/index.html#coupon_code
Where exactly is the data for this variable coming from? There isn't a "coupon_code" field on the default Coupon channel that get's set up.
Any ideas?
In the CT settings under discount, you can define the channel and the custom fields within that channel to be used. ie. coupon code = title & coupon settings = CT discount FT
The coupon code comes from the title.
Looks like it comes from the url_title field when you publish a coupon code.
Related
I am listening to Stripe's invoice.payment_failed webhook with my web app and I would like to get the default_payment_method from each invoice but for some reason it always returns nothing but an empty array!
When I query for a Stripe invoice on the command line and expand on the default_payment_method like this...
Stripe::Invoice.retrieve('in_3K6dIY2KgYRkshw2LAzya63P', :expand => "default_payment_method")
...I also get empty arrays. This surprises me because all my Stripe customers do have a default payment method associated with them.
What am I missing here?
Thanks for any help.
There are three independent places a default payment method can be set. From more specific to less specific they go :
invoice.default_payment_method (which you are looking at)
subscription.default_payment_method
customer.invoice_settings.default_payment_method
Stripe charges the most specific one if it's set. When reading from the API, those values don't inherit from the level above, they can all be set individually, if they are not set explicitly then they are null. So that's why you see it as null on the Invoice level.
Instead you likely want to look at the Subscription object or the Customer object(and can leverage the expand feature for that), depending on how you built your integration and which one it sets.
Overall though, you probably actually want the PaymentMethod used in the invoice payment though? That would be from the last_payment_error.
inv = Stripe::Invoice.retrieve({
id: 'in_1K8iiKJoUivz182DMzSkuBgp',
expand: ["customer.invoice_settings.default_payment_method",
"subscription.default_payment_method",
"payment_intent"]
}
)
print("invoice : #{inv.default_payment_method} \n")
print("subscription : #{inv.subscription.default_payment_method} \n")
print("customer : #{inv.customer.invoice_settings.default_payment_method} \n")
print("failed charge : #{inv.payment_intent.last_payment_error.payment_method} \n")
I created a POC with a customer/credit card in Stripe and I logged into my dashboard within Stripe and was able to see this customer has a default source (the test credit card I added) associated correctly. It shows this card is the default source.
When I run this .Net code:
var customerService = new CustomerService();
var stripeCustomer = await customerService.GetAsync(customerId);
To get that customer, it returns everything correctly except his source. All of the fields I had hoped I can find it from are empty! I want to know his default payment source so I can show it on the front end with a little icon to indicate it's default.
DefaultSource, DefaultSourceId, and Sources properties are all blank/null.
Is there a way to have Stripe return it, or do I need to do something else? I tried the 'expand' property for the GetAsync method but that threw an error saying the above properties are not expandable (i.e. I can't ask Stripe to expand/return Source).
Any ideas what I can do?
FYI I also tried this:
var paymentMethodService = new PaymentMethodService();
var cards = await paymentMethodService.ListAsync(new PaymentMethodListOptions { Customer = customerId, Type = "card"});
and there doesn't seem to be a property anywhere that says the card is default (although it does correctly return all cards). I believe Stripe documentation states the Customer is the holder of the default source, not the card object. What gives?
Thanks in advance!
It looks like you're using Payment Methods, since your payment method list call has the results you expect, which means the customer likely doesn't have any sources. You can try that again with the properly pluralized expand[]=sources if you do know your Customer has Sources attached.
For Payment Methods, there is no general default for the Customer. For one-time Payment Intents, you must always specify the payment_method from among those attached to the Customer for future payments.
For paying invoices (related to recurring subscriptions, eg), you can set the invoice_settings.default_payment_method for Customer. This only applies to invoices.
I have a workflow script that transforms a sales order into an item fulfillment when the order is approved.
I can create a subrecord for inventory detail no problem, but in some cases Netsuite will automatically set the inventory detail. In these cases, when I go to add a subrecord, I receive an error on fulfillment submit record.
I have tried for 2 hours and cannot seem to find a way only to verify if the inventory detail is existing. I tried using the examples from the documentation
var invDetailSubrecord = fulfillment.editCurrentLineItemSubrecord('item', 'inventorydetail');
var invDetailSubrecord = fulfillment.viewCurrentLineItemSubrecord('item', 'inventorydetail');
fulfillment.removeCurrentLineItemSubrecord('item', 'inventorydetail');
None of the above commands do anything and are ignored. I don't see any way possible to verify that inventory detail is set before creating it. Viewing the actual data isn't necessary.
You can use nlapiGetLineItemCount on inventory-details subrecord(I am using the same in SuiteScript2.0 and it works) before setting/updating records manually and if you get line count greater than 0, you can safely assume inventory details already exists for the line.
You can check this out for further reading.
Scenario :
I've been trying to implement something like Amazon has on their product pages in, where the non promoted price is crossed, and the promoted price is highlighted.
I have the PROMOTIONS product option selected in the controller, and
it is returning the potencialPromotion, but it doesn't have the value
of the discount in that structure only the message (as on the
Accelerator it appears the message).
I'm in Hybris 6.6 and I looked up the DefaultPromotionEngineService.evaluate method because it is used in the Cart, and for the cart it returns the promotion actions, but the equivalent method for the product isn't returning anything.
Has anybody done this? Seems like a pretty convencional request although I know it goes against the flexibility of promotion engine.
I can use a Regex against the message to get the discount, but it's a road I don't want to take because it will end badly....
Please suggest.
Thank you
Since you haven't mentioned it before, I have answered based on Legacy Promotion, not the Promotion Engine. I'll update answer if there is a way to do the same in Promotion Engine.
It's true, OOTB there is no service which gives you the discount price on PDP.
I think what you can do,
Override PromotionsPopulator to get the discount value and set it to promotionData.
if (fixedPricePromotion instanceof ProductFixedPricePromotionModel)
{
PromotionPriceRowModel promotionPriceRowModel = ((ProductFixedPricePromotionModel)source).getProductFixedUnitPrice();
//TODO: covert promotionPriceRowModel to promotionPriceData
//TODO: set to promotionData
}
ProductPromotionsPopulator internally calls the above populator to convert ProductPromotionModel to data.
I think we can achieve this using the price row. We can create one more price row and display the logic correctly based on the discount price.
I'm trying to generate voucher coupons for my flask application.
I need coupon that are not easily made, that can be read with the proper key and unique through time.
I already tried hashids with something like:
from hashids import Hashids
hash_id = Hashids(salt='Super salt', min_length=8)
hash_id.encrypt(30)
# 'voRDznrz'
The problem being that the key generated will always be the same.
I also tried itsdangerous for a smarter solution:
import itsdangerous
signer = itsdangerous.URLSafeTimedSerializer("Super salt")
coupon = signer.dumps("30 days free!")
signer.load(coupon, max_age=3600*24*30)
# IjMwIGRheXMgZnJlZSEi.Dl1JAQ.u_ilEm7nQ_8XIQt3nbwe31hyyRc
The solution is far better but I need to store already used coupon to forbid any re-use. Also the coupon is quite ugly and hard to type for our users.
Solution:
Okay so I was using Stripe to make my payment, and the answer is in their doc.
Using Stripe in python you can create coupon this way:
stripe.api_key = "Your secret api key"
coupon = stripe.Coupon.create(
duration='repeating',
duration_in_month=2,
percent_off=100,)
This mean that the coupon will give 2 free month to any subscription, I didn't find how to select a specific product to which the coupon can be applied though.
With the coupon object created you just take his id, this is your coupon code. To bind it to a subscription (and apply it) you do:
subscription = stripe.Subscription.retrieve("Subscription ID")
subscription.coupon = coupon.id
subscription.save()
Normaly coupons are not hash keys, are just some text like 30FREE and are stored in a table with a column that indicates if the coupon has been used (and a coupon exists if is in the table).
If you are not using an ORM right now, i recommend SQLAlchemy with Flask-SLQAlchemy, are very easy to setup and start.
Note: you can assign a coupon to a segment of users making a relationship between the coupons table and the users table, and then implement the logic of only a user inside that group can redeem the coupon or something like that.