My application allows subscription services and i am using paypal's recurring payment for this. There according to there manual, the order i used is
SetExperssCheckOut-->GetExppressCheckOut-->DoExpressCheckOut->CreateRecurringPayment Profile.
On DoExpressCheckOut event iteself my first payment is made and after that on creating the recurring payment profile the next payment is made, ie if I have a daily subscription , on the end of 3rd day, no of payments made =4 (3 from the recurring payment and 1 from the get express checkout). I want only 3 payments at the end of 3rdday. The code I used is:
GetExpressCheckout getExpressCheckout = new GetExpressCheckout();
GetExpressCheckoutDetailsResponseType getExpressCheckoutResponse = getExpressCheckout.ECGetExpressCheckoutCode(token);
if (getExpressCheckoutResponse.Ack == AckCodeType.Success)
{
ExpressCheckout expressCheckout = new ExpressCheckout();
DoExpressCheckoutPaymentResponseType doExpressCheckoutResponse = expressCheckout.DoExpressCheckoutPayment
(
token,
getExpressCheckoutResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerID,
PayPalSettings.OrderAmount,
PaymentActionCodeType.Sale,
CurrencyCodeType.USD
);
if (doExpressCheckoutResponse.Ack == AckCodeType.Success)
{
//create Recurring Payment Profile
CreateRecurringPaymentsProfile createRecurringPaymentsProfile = new CreateRecurringPaymentsProfile();
CreateRecurringPaymentsProfileResponseType recurringPaymentProfileResponse = createRecurringPaymentsProfile.CreateRecurringPaymentsProfileCode(
doExpressCheckoutResponse.DoExpressCheckoutPaymentResponseDetails.Token,
doExpressCheckoutResponse.Timestamp,
PayPalSettings.OrderAmount,
1,
BillingPeriodType.Day,//BillingPeriodType.Month
CurrencyCodeType.USD
);
if (recurringPaymentProfileResponse.Ack == AckCodeType.Success)
{
//Do something
}
How can I make all payments under the recurring payment section ?
When using Recurring Payments the DoExpressCheckoutPayment API call isn't required. When the customer is redirected to PayPal for authentication they submit their agreement to the scheduled payments.
Try skipping the DoExpressCheckoutPayment API call and this should take care of the extra payment.
Let me know if you run into any issues.
Related
The bottom line is to listen to a specific user and transfer his tweets with minimal delay to the telegram bot.
To implement this task, I use the Twiipi library in which, as I understand it, there are 2 most important types of authentication for me:
On behalf of the user - 900 requests in 15 minutes (i.e. 1 request in 1 second)
On behalf of the application - 300 requests in 15 minutes (i.e. 1 request in 3 seconds)
I authenticate my script on behalf of the user using the OAuth1UserHandler function (listed below).
But despite this, the delay in speed appears after 7.5 minutes of work, given that the script for interacting with twitter resources runs once every 1.5 seconds. That is one way or another Authentication of my script takes place on behalf of the application. But despite this, I just made a second bot that starts after 7 minutes of the previous one, thereby updating the time for the previous one to work. My main problem is that the performance of parsing tweet data drops (acceptable speed is a maximum of 1.5 seconds, delays sometimes last 13 seconds).
Please tell me what I'm doing wrong or how can I solve my problem better?
code of one of 2 bots
import tweepy
import datetime
import time
from notifiers import get_notifier
from re import sub
TOKEN = 'telegram token here'
USER_ID = telegram user id here
ADMIN_ID = teelgram my id here for check work bots
auth = tweepy.OAuth1UserHandler(
consumer_key="consumer key",
consumer_secret="consumer secret",
access_token="access token",
access_token_secret="access token secret",
)
api = tweepy.API(auth)
# auth.set_access_token(access_token, access_token_secret)
print("############### Tokens connected ###############")
user = 'whose username we will listen to'
username_object = api.get_user(screen_name=user)
def listening_to_the_user():
print(' We start listening to the user...')
print(' When a user posts a tweet, you will hear an audio notification...')
seconds_left = 60*10
while seconds_left >= 0:
for i in api.user_timeline(user_id=username_object.id, screen_name=user, count=1):
tweet_post = i.created_at
tweet_text = sub(r"https?://t.co[^,\s]+,?", "", i.text)
tweet_time_information = [tweet_post.day, tweet_post.month, tweet_post.year, tweet_post.hour, tweet_post.minute]
now = datetime.datetime.now()
current_time = [now.day, now.month, now.year, now.hour, now.minute]
if tweet_time_information == current_time:
telegram = get_notifier('telegram')
notification_about_tweet = f'️{user}⬇️'
notification_about_tweet_time = f'{tweet_post.day}.{tweet_post.month}.{tweet_post.year}, {tweet_post.hour}:{tweet_post.minute}.{tweet_post.second}'
notification_about_current_time = f'{now.day}.{now.month}.{now.year}, {now.hour}:{now.minute}.{now.second}'
telegram.notify(token=TOKEN, chat_id=USER_ID, message=notification_about_tweet)
telegram.notify(token=TOKEN, chat_id=USER_ID, message=tweet_text)
try:
entities = i.extended_entities
itr = entities['media']
for img_dict in range(len(itr)):
telegram.notify(token=TOKEN, chat_id=ADMIN_ID, message=(entities['media'][img_dict]['media_url_https']))
except:
entities = 0
telegram.notify(token=TOKEN, chat_id=ADMIN_ID, message=notification_about_tweet)
telegram.notify(token=TOKEN, chat_id=ADMIN_ID, message=tweet_text)
telegram.notify(token=TOKEN, chat_id=ADMIN_ID, message=notification_about_tweet_time)
telegram.notify(token=TOKEN, chat_id=ADMIN_ID, message=notification_about_current_time)
try:
entities = i.extended_entities
itr = entities['media']
for img_dict in range(len(itr)):
telegram.notify(token=TOKEN, chat_id=USER_ID,
message=(entities['media'][img_dict]['media_url_https']))
except:
entities = 0
seconds_left -= 60
time.sleep(60)
seconds_left -= 1.5
time.sleep(1.5)
listening_to_the_user()
Initially, I tried to use bearer_token for authentication, but this literally did not affect the operation of my program in any way and I simply reduced it to those tokens that are now in it.
I rummaged through the documentation in search of an answer to my question, but in search I only thought of the script calling the second bot after 7 minutes of the previous one, and so they worked in turn
I'm developing a little shopping website for entertainment purpose but I'm intending to apply the same code to a possible real shop website in the future.
So I have these "slots" that are meant to be bought, like a reservation slot for saving seats with numbers.
So people will buy the slots and save the seats, but I'm facing a race condition problem, even though I'm using lockForUpdate method, I can buy more slots than I have balance for.
My piece of code for when the user clicks "buy":
foreach ($tSlots as $mSlot) {
DB::beginTransaction();
$slot = Slots::where('id', $mSlot)->lockForUpdate()->first();
$wallet = $user::getWallet();
$wallet->lockForUpdate();
if (($slot->user_id === null) && ($wallet->balance >= $slot->price)) {
$wallet->balance -= $slot->price;
$slot->user_id = $user->id;
if ($wallet->update() && $slot->update()) {
$counter++;
DB::commit();
} else {
DB::rollBack();
}
} else {
DB::rollBack();
}
}
I'm keeping track of the slots count as I will display how many slots the users has successfully bought on the view after redirection.
If i intercept the request and edit it to make, let's say, 4 requests, each buying 5 different slots, I can manage to buy more than I have balance for, and my balance turns negative. Where am I messing it up?
I am trying to send order placed email to seller only if the payment is success. I tried with below events.
sales_order_place_after, sales_order_save_after, checkout_onepage_controller_success_action
and i am using below code to send email based on the order status like
if($order->getState() == Mage_Sales_Model_Order::STATE_PROCESSING){
$emailTemp = Mage::helper('marketplace')->getOrderPlaceNotifymailTemplate();
$emailTempVariables = array();
$emailTempVariables['myvar1'] = $order->getRealOrderId();
$emailTempVariables['myvar2'] = $order['created_at'];
$emailTempVariables['myvar4'] = $billinginfo;
$emailTempVariables['myvar5'] = $payment;
$emailTempVariables['myvar6'] = $shipping_info;
$emailTempVariables['myvar9'] = $shipping_des;
$emailTempVariables['myvar8'] = $orderinfo;
$emailTempVariables['myvar3'] = $Username;
$processedTemplate = $emailTemp->getProcessedTemplate($emailTempVariables);
$emailTemp->setSenderName($adminUsername);
$emailTemp->setSenderEmail($adminEmail);
$emailTemp->send($useremail,$Username,$emailTempVariables);
}
but i am not able to send emails,even i tried to send using
if($order->getBaseTotalDue() == 0){
.......email code.........
}
if i removed if{} condition i can send email even if i cancel payment on payment gateway.I need to rectify this and i need to send emails only if payment is success.
A client wants to set up A/B testing on the Product Detail Page related to the stock_level of a product's variants. Once the user selects their options, if the quantity is less than 5, I'd show something like "Hurry, only 3 more in stock"...
I believe I have the correct Inventory settings enabled, because I can retrieve the stock_level of a product without options.
Has anyone had success pulling variant SKU stock_levels in stencil?
Thanks
This can be done using javascript in the assets/js/theme/common/product-details.js file. On initial page load and each time a product option is changed, there is a function updateView(data) that is called. The data parameter contains all the info you need for the selected variation.
Starting on line 285, replace this:
updateView(data) {
const viewModel = this.getViewModel(this.$scope);
this.showMessageBox(data.stock_message || data.purchasing_message);
with this:
updateView(data) {
const viewModel = this.getViewModel(this.$scope);
if(data.stock < "5") {
data.stock_message = "Hurry, only " + data.stock + " left!";
}
this.showMessageBox(data.stock_message || data.purchasing_message);
I am making an application for a car dealership. I have a page for stocks and a page for sales. Whenever I make a new entry in sales, I want the corresponding entry to be deleted from the stocks page.
My db for sales is
db.define_table('sales',
Field('customer_name','string'),
Field('village','string'),
Field('mobile_number','integer'),
Field('model','string',required=True,requires=IS_IN_SET(['1035DI','241DI','241DI(P.S.)','245DI','245DI(P.S.)','9000DI','9000DI(P.S)','5245DI','9500DI'])),
Field('engine_number','string'),
Field('chassis_number','string'),
Field('date_of_sale','date'),
Field('sale_price','integer'),
Field('bill_number','integer'),
Field('mode_of_payment','string',requires=IS_IN_SET(['Cash','Cheque']))
)
My db for stock is
db.define_table('stock',
Field('model','string',required=True,requires=IS_IN_SET(['1035DI','241DI','241DI(P.S.)','245DI','245DI(P.S.)','9000DI','9000DI(P.S)','5245DI','9500DI'])),
Field('engine_number','string',required=True),
Field('chassis_number','string',required=True),
Field('invoice_number','integer',required=True),
)
Engine number and chassis number is unique for each entry.
You didn't post any controller code, so I'm just making a simple untested example. I'm assuming you're using SQLFORM, and your sales controller function is just named "sales"
#controller, i.e. default.py
def sales():
form = SQLFORM(db.sales)
if form.process().accepted:
engine_number = form.vars.engine_number
chassis_number = form.vars.chassis_number
db((db.stock.engine_number == engine_number) & (db.stock.chassis_number == chassis_number)).delete()
return dict(form=form)