I'm trying to implement the PayPal API function for SetExpressCheckout. Below I put a part of my code that I am using to call the payment process on the PayPal side. Everything looks fine. At the last step of the checkout, i push the "Pay Now" button and the payment is processed. After that user is returnet to my original site and i got the Transaction ID, success message and token. It looks like evrything was finished fine, but in my PayPal account i dont see any transactions and I don’t get any money at all.
$returnUrl = home_url("/wp-login.php?checkemail=registered&ppayment=done&price=".$package_price."&code=".$paypal_price_unit."&package=".$package_name."&pid=".$incomingpost);
$requestParams = array(
'RETURNURL' => $returnUrl,
'CANCELURL' => home_url('/wp-login.php?checkemail=registered&ppayment=cancel')
);
// Sent item info
$orderParams = array(
'PAYMENTREQUEST_0_AMT' => $package_price,
'PAYMENTREQUEST_0_SHIPPINGAMT' => '0',
'PAYMENTREQUEST_0_CURRENCYCODE' => $paypal_price_unit,
'PAYMENTREQUEST_0_ITEMAMT' => $package_price
);
//send package info
$item = array(
'L_PAYMENTREQUEST_0_NAME0' => $paymentName,
'L_PAYMENTREQUEST_0_DESC0' => $package_name,
'L_PAYMENTREQUEST_0_AMT0' => $package_price,
'L_PAYMENTREQUEST_0_QTY0' => '1'
);
//Call payment process
$infos = array();
$infos['USER'] = $paypal_api_user;
$infos['PWD'] = $paypal_api_pwd;
$infos['SIGNATURE'] = $paypal_api_signature;
if($paypal_sandbox == 1){$sandstatus = true;}else{$sandstatus = false;}
$paypal = new Paypal($infos,$sandstatus);
$response = $paypal -> request('SetExpressCheckout',$requestParams + $orderParams + $item);
if(is_array($response) && $response['ACK'] == 'Success') {
// We will redirecting now.
$token = $response['TOKEN'];
//Save DB before redirect.
$trans_post = array(
'post_status' => 'pending',
'post_type' => 'retransactions',
'post_title' => $token,
);
$new_post_id = wp_insert_post( $trans_post );
add_post_meta($new_post_id, 'webburemap_payment_user', $user_id);
add_post_meta($new_post_id, 'webburemap_payment_amount', $package_price);
add_post_meta($new_post_id, 'webburemap_payment_package_id', $package_IDNO);
add_post_meta($new_post_id, 'webburemap_payment_package_transtype', 'NewPackage');
if($paypal_sandbox == 0){
$commit = '&useraction=commit';
header( 'Location: https://www.paypal.com/webscr?cmd=_express-checkout&token=' . urlencode($token) . $commit ); //PayPal Pay Now
}else{
header( 'Location: https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=' . urlencode($token) );
}
die();
}
Can you provide the Express Checkout Token and the Transaction ID that you are getting back and I will take a look at it on my side to see what may be happening. Also make sure that you are pointing to the correct endpoint. If you are trying to process a live payment, make sure you are pointing towards the live site and not the sandbox.
Related
I have a simple bot (I am using webhook) that responds to a command and goes to the database and sends a sticker and a simple html message for every record found.
If there are many records (20 or more AND took more than 2 minutes to finish the while bucle) bot goes crazy and display the results 4 times (finish one time and then starts again 3 more times), I tried to add a sleep() timer to avoid the loop but have no luck. Not sure what I am missing or doing wrong.
Here's my code:
$update = json_decode(file_get_contents('php://input'));
if (isset($update->message)){
//Fetching update
$message = $update->message;
$message_id = $update->message->message_id;
$text = $message->text;
$chat_id = $message->chat->id;
switch($text){
case "read":
$age = 18;
read_fields($age, $chat_id);
break;
default:
bot('SendMessage',[
'chat_id' => $chat_id,
'text' => "This is a test"
]);
}
}
function read_fields($age, $chat_id){
include("conexion.inc");
$i = 0;
$sticker = "";
$id = "";
$name = "";
$sql = "SELECT id, name, sticker FROM Persons WHERE age = ".$age;
$php = mysql_query($sql, $con);
while($row=mysql_fetch_assoc($php)){
$sticker = $row['id_sticker'];
$id = $row['id'];
$name = $row['name'];
bot('sendSticker',[
'chat_id' => $chat_id,
'sticker' => $id_sticker
]);
$message = $id."-<b>".$name."</b>";
bot('SendMessage',[
'chat_id' => $chat_id,
'parse_mode' => "HTML",
'text' => $mensaje
]);
sleep(3);
$i++;
}
bot('SendMessage',[
'chat_id' => $chat_id,
'text' => "### ".$i." total ### "
]);
}
Telegram Bot API will retry webhook request when server-side consider there are dropped, so you need to reduce response time.
One solution is process them quickly, but it seems not easy.
If you know how to close HTTP connection before timeout, just do that, since it's implement is different from your HTTP server, try to search like NginX fastcgi close upstream connection.
I am looking to get per sms rate by passing "To" mobile number for related country to display in my application, please suggest best solution, Thanks.
Twilio evangelist here.
Unfortunately today we don't have a way via the API to find out the price of an SMS before sending it. You can get the price of an individual message after its sent via the API by making a request to the Messages endpoint:
/2010-04-01/Accounts/{AccountSid}/Messages/{MessageSid}
We also publish a csv that contains all of our SMS pricing. You can find that here:
https://www.twilio.com/help/faq/sms/where-can-i-see-all-of-twilios-sms-pricing-in-one-place
Hope that helps.
i was looking for a similar solution today and i had to code mind myself. Hope this gives you the idea. Though this method will cost you $0.005 per query.
If you can get another provider(s) to query a mobile number and get it's Mobile Network Code (MNC) then this solution becomes free.
<?php
$entry_number="+1239393939"; //The mobile num to query
$account_sid = 'your twilio SID';
$auth_token = 'your auth token';
// STEP 1, GETTING THE MNC(This costs $0.005)
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://lookups.twilio.com/v1/PhoneNumbers/'.$entry_number.'?Type=carrier',
CURLOPT_USERPWD => ''.$account_sid.':'.$auth_token.'',
CURLOPT_USERAGENT => 'Number lookup'
));
$response = curl_exec($curl);
curl_close($curl);
$array = json_decode($response);
$country_code=$array->country_code;
$mnc=$array->carrier->mobile_network_code;
$network_name=$array->carrier->name;
// END OF STEP ONE, (You can var_dump($response); to see entire response
// STEP 2, Checking the price (This step is free)
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://pricing.twilio.com/v1/Messaging/Countries/'.$country_code.'',
CURLOPT_USERPWD => ''.$account_sid.':'.$auth_token.'',
CURLOPT_USERAGENT => 'Number lookup'
));
$response = curl_exec($curl);
curl_close($curl);
$array = json_decode($response);
$pricing= $array->outbound_sms_prices;
foreach ($pricing as $data=>$value)
{
if ($value->mnc == $mnc){
foreach ($value->prices as $data1=>$value1)
{
if ($value1->number_type == 'mobile'){
$current_price=$value1->current_price; // ECHO this line to show price
}
}
}
}
?>
I'm using the Twitter API 1.1 Get statuses method to return the latest tweet from an account on the client's website. This is working fine but I can't find any clear documentation on how to render any links that may be included (Both included usernames and included links) as clickable links?
I can see in the JSON response that any included links are in the XML but it's not clear to me how to go about adding clickable links into the rendered output. The documentation around the new API seems to be lacking practical examples.
Can anyone advise?
The code I'm using the pull out the latest tweet is as follows:
$token = 'TOKEN HERE';
$token_secret = 'TOKEN SECRET HERE';
$consumer_key = 'CONSUMER KEY HERE';
$consumer_secret = 'CONSUMER SECRET HERE';
$host = 'api.twitter.com';
$method = 'GET';
$path = '/1.1/statuses/user_timeline.json'; // api call path
$query = array( // query parameters
'screen_name' => 'SCREEN NAME HERE',
'count' => '1'
);
$oauth = array(
'oauth_consumer_key' => $consumer_key,
'oauth_token' => $token,
'oauth_nonce' => (string)mt_rand(), // a stronger nonce is recommended
'oauth_timestamp' => time(),
'oauth_signature_method' => 'HMAC-SHA1',
'oauth_version' => '1.0'
);
$oauth = array_map("rawurlencode", $oauth); // must be encoded before sorting
$query = array_map("rawurlencode", $query);
$arr = array_merge($oauth, $query); // combine the values THEN sort
asort($arr); // secondary sort (value)
ksort($arr); // primary sort (key)
// http_build_query automatically encodes, but our parameters
// are already encoded, and must be by this point, so we undo
// the encoding step
$querystring = urldecode(http_build_query($arr, '', '&'));
$url = "https://$host$path";
// mash everything together for the text to hash
$base_string = $method."&".rawurlencode($url)."&".rawurlencode($querystring);
// same with the key
$key = rawurlencode($consumer_secret)."&".rawurlencode($token_secret);
// generate the hash
$signature = rawurlencode(base64_encode(hash_hmac('sha1', $base_string, $key, true)));
// this time we're using a normal GET query, and we're only encoding the query params
// (without the oauth params)
$url .= "?".http_build_query($query);
$oauth['oauth_signature'] = $signature; // don't want to abandon all that work!
ksort($oauth); // probably not necessary, but twitter's demo does it
// also not necessary, but twitter's demo does this too
function add_quotes($str) { return '"'.$str.'"'; }
$oauth = array_map("add_quotes", $oauth);
// this is the full value of the Authorization line
$auth = "OAuth " . urldecode(http_build_query($oauth, '', ', '));
// if you're doing post, you need to skip the GET building above
// and instead supply query parameters to CURLOPT_POSTFIELDS
$options = array( CURLOPT_HTTPHEADER => array("Authorization: $auth"),
//CURLOPT_POSTFIELDS => $postfields,
CURLOPT_HEADER => false,
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false);
// do our business
$feed = curl_init();
curl_setopt_array($feed, $options);
$json = curl_exec($feed);
curl_close($feed);
$twitter_data = json_decode($json);
Thanks a lot for your response. I actually found a solution thanks to this blog post from the guys at Asheville - http://www.appliedtns.com/blog/tag/twitter/
It works fine for me.
// Parse any links found in our tweet
$formatted_text = preg_replace('/(\b(www\.|http\:\/\/)\S+\b)/', "<a target='_blank' href='$1'>$1</a>", $post->text);
$formatted_text = preg_replace('/\#(\w+)/', "<a target='_blank' href='http://search.twitter.com/search?q=$1'>#$1</a>", $formatted_text);
$formatted_text = preg_replace('/\#(\w+)/', "<a target='_blank' href='http://twitter.com/$1'>#$1</a>", $formatted_text);
Not sure if this exactly what you need but I am using the tmhOAuth library for my application, see https://github.com/themattharris/tmhOAuth-examples. Using code from Matt Harris' examples I loop through the response and build the output as in the code below. The links in the tweets are created by the library function entify_with_options($tweet).
// Decode response
$timeline = json_decode($this->tmhOAuth->response['response'], true);
if(!$timeline){
throw new Exception('Error: No response was found.');
}
else{
// Start building the output
foreach ($timeline as $tweet) :
... start of response processing
// Format and set tweet text
$tw_entified_tweet = tmhUtilities::entify_with_options($tweet);
// Format and set creation date for permalink
$tw_created_at_formatted = is_twitterlist_format_date($tweet['created_at']);
// Format and set permalink
$tw_permalink = str_replace(
array(
'%screen_name%',
'%id%',
'%created_at%'
),
array(
$tweet['user']['screen_name'],
$tweet['id_str'],
$tw_created_at_formatted,
),
'%created_at%'
);
... end response processing
endforeach;
}
The date format function is:
function is_twitterlist_format_date($created_date)
{
if ( is_null($created_date)) {
return '';
}
else{
// Format: March 4th, 9:19 am
return date('F jS, g:i a', strtotime($created_date));
}
}
Hope this is useful.
I'm trying to integrate a cart-synchronisation-solution for my rest-clients.
The goal should be that I can have the same cart wherever I access my store from.
So I'll have to first of all deliver the existing items out to the client using the authenticated api-user.
But I get stuck at the very beginning:
protected function _retrieveCollection()
{
$cart = Mage::getSingleton('checkout/cart')->getQuote();
$cart->setCustomerId($this->getApiUser()->getUserId());
$cart->setStoreId(4);
$cart->load();
return $cart->getAllItems();
}
returns an empty array even though I have products in my cart.
Anyone any hints? Have that feeling I'm totally on the wrong side...
Found a solution. Getting the quote by Customer which is the other way around worked pretty well:
Mage::app()->setCurrentStore(4);
$cart = Mage::getModel('sales/quote')->loadByCustomer($this->getApiUser()->getUserId());
$items = array();
foreach ($cart->getAllVisibleItems() as $key => $item) {
$items[] = array(
'name' => $item->getName(),
'entity_id' => $item->getProductId(),
'description' => $item->getDescription(),
'final_price_with_tax' => $item->getBasePriceInclTax(),
'qty' => $item->getQty()
);
}
I followed this tutorial to create multilingual site.
http://nuts-and-bolts-of-cakephp.com/2008/11/28/cakephp-url-based-language-switching-for-i18n-and-l10n-internationalization-and-localization/
However although I can get to the login page at example.com/en/users/login when i try to login, the login wouldn't go through. I get thrown at example.com/users/login without the /en/ and I don't know if this matters, but the password does not contain 4 letters/stars/dots like the password i tried, but about 40.
Also, I noticed that the example.com/en/users/logout function does work to log me out, but takes me to example.com/users/login instead of example.com/en/users/logout
I managed to get to the fact that the function that breaks it is the:
class AppHelper extends Helper {
function url($url = null, $full = false) {
if(!isset($url['language']) && isset($this->params['language'])) {
$url['language'] = $this->params['language'];
}
return parent::url($url, $full);
}
}
However, without it, no urls work at all in terms of the /en/ addition in the URL.
Can anyone help? I will provide any code needed.
This was quite a journey to make it work. Some of the things I still don't get, but at least I know they work. If you make an improvement on this let me know, I'd like to be aware of it.
This tutorial in the question only gets you half way.
In addition, here are a few things that need to be moded to get this working:
Routes.php:
/**
* LANGUAGES
*/
Router::connect( '/:language/:plugin/:controller/:action/*', array(), array('language' => '[a-z]{3}')); // PLUGIN FIX
Router::connect('/:language/:controller/:action/*', array('plugin' => null), array('language' => '[a-z]{3}'));
Router::connect('/:language', array('controller'=>'static', 'plugin'=>null), array('language' => '[a-z]{3}'));
App_controller.php:
function beforeFilter(){
$this->_setLanguage();
$this->Auth->logoutRedirect = array( 'controller' => 'static', 'action' => 'index', 'language'=>$this->Session->read('Config.language'));
$this->Auth->loginRedirect = array( 'controller' => 'static', 'action' => 'dashboard', 'language'=>$this->Session->read('Config.language'));
$this->Auth->loginAction = array( 'controller'=>'users', 'action'=>'login', 'language'=>$this->Session->read('Config.language'));
}
function _setLanguage() {
if ($this->Cookie->read('lang') && !$this->Session->check('Config.language')) {
// If ... don't really get this.
$this->Session->write('Config.language', $this->Cookie->read('lang'));
}
else if (isset($this->params['language']) && ($this->params['language']
!= $this->Session->read('Config.language'))) {
// Had a language set, but different from the one in the URL, set to URL
$this->Session->write('Config.language', $this->params['language']);
$this->Cookie->write('lang',$this->params['language'], false, '360 days');
}else{
// First time comer
$this->Session->write('Config.language', Configure::read('Config.language' ));
$this->Cookie->write('lang', Configure::read('Config.language' ), false, '360 days');
}
}
function redirect( $url, $status = NULL, $exit = true ) {
if (!isset($url['language']) && $this->Session->check('Config.language')) {
$url['language'] = $this->Session->read('Config.language');
}
parent::redirect($url,$status,$exit);
}
app_helper.php:
function url($url = null, $full = false) {
if(!isset($url['language']) && isset($this->params['language'])) {
$url['language'] = $this->params['language'];
}else if (!isset($url['language']) && !isset($this->params['language'])){
if($_COOKIE['lang']){
$url['language'] = $_COOKIE['lang'];
}else{
$url['language'] = Configure::read('Config.language');
}
}
return parent::url($url, $full);
}
And this should be it. Hope that helps all of you lost souls with multilingual cakephp stuff
pp
I used the same resource to make cakephp multilingual, but today got stuck with that problem that by default login action loses language. When I found this post, the only thing that I need in addition to the original manual is the following code in controller_app.php beforeFilter:
$this->Auth->logoutRedirect = array( 'language'=>$this->Session->read('Config.language'));
$this->Auth->loginRedirect = array( 'language'=>$this->Session->read('Config.language'));
$this->Auth->loginAction = array( 'controller'=>'users', 'action'=>'login', 'language'=>$this->Session->read('Config.language'));
I saw your other question about multilingual setting. I was going to say that just make the default language to be 'en'. But I'm uncertain how that would affect SEO, so I didn't say anything. But yeah, the way you are doing right now might interfere with many Cake automagic, like the Auth problem you are having.
Here what I'd suggest: In app_controller:
function beforeFilter(){
$this->Auth->loginAction = array(
'controller' => 'users',
'action' => 'login' // insert the language option that you use here
);
$this->Auth->logoutRedirect = array(
'controller' => 'users',
'action' => 'index'
);// you can set where to redirect after logout here
}
I would advise not to redirect to /users/logout, unless you want to do something there. And you would need to change the logout function in users_controller too.
One thing that helped me, (not perfect but it's a start)
is i created exceptions for the 'loginPage' (the login action for the auto component)
so the language of the url doesn't get populated when logging in.
this helped me as i wasn't able to login until i did this
i added this to the app_helper.php
> //exceptions to allow to login
> if (isset($url['action'])) {
> if ($url['action'] == 'loginPage') $url['language'] = false;
> }