PayPal shows empty cart - php

I have two payment pages for different things. One of them works great and posts the cart to PayPal like it should, the other one shows an empty cart regardless. I've looked through the url string I'm sending to and these are the only arguments that are different:
Works:
&item_name_1=Add+Seats+-+Keynote+Manager
&item_number_1=Add+to+License
&amount_1=68
&quantity_1=1
&notify_url=http%3A%2F%2Frevolutiondesign.biz%2FIPNBroker.php%3Fkey%3DAZHJ0T1U05V1W1XY8G1C3C3XP3IMF2N2PP%26extendYears%3D0%26newSeats%3D1%26addPortable%3D%26newFeatures%3D
&custom=upgrade
&key=AZHJ0T1U05V1W1XY8G1C3C3XP3IMF2N2PP
&extendYears=0
&newSeats=1
&addPortable=
&addFeatures=
&qtyAddFeatures=0
&costAddFeatures=0
&qtyAddSeats=1
&costAddSeats=68
&qtyPortable=
&costPortable=
&qtyExtend=0
&costExtend=0
&v=63400
Doesn't:
&item_name_1=Add+Cloud+Seats
&item_number_1=Add+Cloud+Seats
&amount_1=94
&quantity_1=1
&notify_url=http%3A%2F%2Frevolutiondesign.biz%2FIPNBroker.php%3FcustomerID%3Dba3d3c75-5e18-42b7-948e-3e34cccc1d9e%26extendPeriod%3Dmonths%26qtyExtend%3D1%26qtyAddSeats%3D1
&custom=cloudUpgrade
&cstID=ba3d3c75-5e18-42b7-948e-3e34cccc1d9e
&costAddSeats=97
&costExtend=7
&v=GREAT+Design+Group
&extend=1
&extendPeriod=months
&add=1
Is there any difference that anyone can see that would cause the second one not to work?

Ok through some process of elimination I finally identified the issue. The issue was in the presence of the variable called 'Add'. I was using that for the number of licenses the user wanted to add, but PayPal also has that as a variable for cart transactions which I did not realize. I pulled that post data into a php variable and then unset the post so it didn't pass to PayPal and it works now. I could also have renamed that post variable coming from my purchase page and I bet it would work as well.

Related

How to set an access point in ups API wrapper?

I am using the gabrielbull ups api wrapper and it is working fine, except when I want to add an UPS access point; the documentation says I have to declare a "AlternateDeliveryAddress". The access point data should then be printed on the ups label, but they are not appearing.
Since there isn't an example for this case on the wrapper GitHub page, I searched for methods on my own and found one but I have the feeling I forgot something since I don't receive any errors. I tried this code for the specific part. The surrounding code is like in the shipping class example
$address = new \Ups\Entity\Address();
$address->setAddressLine1($ap_addressline1);
$address->setPostalCode($ap_postal);
$address->setCity($ap_city);
$address->setCountryCode($ap_country);
$alternateTo = new \Ups\Entity\AlternateDeliveryAddress;
$alternateTo->setAddress($address);
$alternateTo->setUpsAccessPointId($ap_id);
$alternateTo->setName($ap_name);
$alternateTo->setAttentionName($ap_name);
$shipment->setAlternateDeliveryAddress($alternateTo);
Edit: I got this info of setting up the accesspoint from UPS support. The guy told me to set an alternate address with the AccessPoint data that will be printed at the bottom line of the label (where it's currently missing). If I misunderstood something (though we did a video conference and he showed me the result) and you know another way, feel free to tell me.
Ok after re-reading the official docs I found out what was missing.
If you want to use an accesspoint as address you also have to set the Indication Type via setShipmentIndicationType. There are 2 codes: 01 and 02 depending on the way you want to send it. Ofcourse I didn't add them before...
I haven't finished it yet because I get some errors but that's more about what information ups needs from me and so on. At least I can work with that.
As I mentioned in my initial post I used the example of the api wrapper as base and insert the required part before the request was send:
...
// Set Reference Number
...
// this is the part where you set shipment indication type for the accesspoint
$accesspoint = new \Ups\Entity\ShipmentIndicationType;
$accesspoint->setCode(Ups\Entity\ShipmentIndicationType::CODE_HOLD_FOR_PICKUP_ACCESS_POINT); // for "01"
#$accesspoint->setCode(Ups\Entity\ShipmentIndicationType::CODE_ACCESS_POINT_DELIVERY); // for "02"
$shipment->setShipmentIndicationType($accesspoint);
// Set payment information
...
// Ask for negotiated rates (optional)
...
// Get shipment info
...

Send data from div to controller in laravel

Is that possible instead of using <input name="...."/> I get my value from div or span etc. ?
currently I get my data directly from database, base on product id, but as my product might have discount that will show different price with what is saved in my database and I cannot show it as input so i need to pass it through div or span etc.
code:
here is my code now:
public function addingItem(Request $request, $id)
{
$product = Product::findOrFail($id);
Cart::add(array(
'id' => $product->id,
'name' => $product->title,
'price' => $product->price, // this comes directly from products table
));
}
with my code i always will get 45.325 but I need to get 35.325 during discount time.
That's why i need to pass it through div and cannot use input here.
any idea?
As far as your PHP code is concerned, data doesn't come from any particular part of a page, it comes from the HTTP request sent by the browser. An HTML form is just the simplest way to get the browser to add some data to that request. This may seem like nitpicking, but it has important consequences.
First, it means that what you are asking for is absolutely possible. You just need to write some JavaScript to run in the browser and tell the browser to add that value to the request. A simple way would be to have a hidden input field on the form and set the value in the JavaScript, but you can also create a completely custom request and send it to the server (AJAX).
Second, though, it means that any user can submit any data to your application by telling their browser to submit their choice of value not yours. Consequently, you have to be very careful of what data you trust, and trusting the browser to send you a price sounds like a really bad idea. What's to stop someone giving themselves a 100% discount by editing the value on the page?
Somewhere, you know what discounts you're offering. That discount is a core part of your application, so however the view knows what discount to show, the rest of the application should be able to know the same way. This probably means moving some code out of your view into a new function, which can be used by various parts of the application; that makes each use more readable, and means you don't have to change it in lots of places if the requirements get more complex.
SOLVED
well I decided to bring my codes to controller instead of using ajax or other ways, here is how I've done it:
$discounts = Discount::all();
$mytime = Carbon::now();
//get discounted price or normal price of product
$price = $product->discounts;
if($price->count() > 0 ) {
foreach($discounts as $disc){
if($disc->value_to >= $mytime) {
$price = $product->price - $disc->amount;
}
}
}else{
$price = $product->price;
}
Hope it help others.

Using WooCommerce API filter by product SKU

I'm trying to retrieve product info from WooCommerce using their API.
I'm sending an request using the following URL: {url}/wp-json/wc/v2/products?filter[sku]=10008&consumer_key={key}&consumer_secret={key}. However, the response I receive, contain various products, which have no relation whatsoever to SKU=10008.
I'm wondering why this filter, dosen't isolate the response, only containing products filtered by my specified SKU? Am I using the API wrong?
For instance, this is my response (only printing the SKU):
pCb0760
pCb0855
pHn4000
pCh0900
pCb0752
pVg0210
pTa0111
pTa0110
pTa0101
pTa0100
pGd0130
pGd0120
pGd0110
pTa0120
pEg0030
pSu1015
pNd0400
pF27z
pF27w
pF27bb
pF27b
pF14z
pF14w
pF14bb
pF14b
pSp0360
pPa0300
pHp0100
pEk0400
pAb1665
pAs0100z
pLt0210
pLt0200
pLt0100
pCs0822
pIg0912
pIg0911
pIg0910
pIg0902
pIg0901
pIg0900
pIg0802
pIg0801
pIg0800
pIg0190
pIg0187
pIg0186
pIg0185
pIg0171
pIg0170
pIg0132
pIg0101
pHi1081
pHi1080
pHi1013
pHi1012
pHi1011
pHi1010
I really can't see any correlation between my request and this response...
Try with this call:
/wp-json/wc/v3/products?sku=<your_sku>"
Replacing <your_sku> with your SKU.
I believe filter has been deprecated. Here's what I use to get a list of products with the SKU. yoursite.com/wc-api/v3/products/?sku=SKUHERE
I had to use /wc-api/v3/products?filter[sku]="" instead.

Wordpress/PHP - Custom action on comment post

Whenever a user posts a comment, I'd like to basically have a copy of the post sent to another database for a separate site. The database part is simple, but I can't seem to find the right action hook for this. (I did my testing with a simple echo statement, a failure being it not displaying at all) 'comment_save_pre' would only work when updating a comment, 'wp_set_comment_status' only works when the comment is approved, and 'comment_post' didn't seem to work at all. Does the hook exist?
add_action('...?...', 'on_comment_post');
function on_comment_post($comment){
echo "Test";
}
You can use comment_post :
Runs just after a comment is saved in the database. Action function
arguments: comment ID, approval status ("spam", or 0/1 for
disapproved/approved).

Creating configurable product programmatically

I'm trying to create configurable products programmatically in Magento 1.5.1.
I understand I need first to create simple related products, what I did. Now I manage to associate these simple products to make a configurable one.
Here is the critical part...
I keep the ids and some of the attributes values in an array, so I can later make my configurable product, but some of them are missing, I don't know which method to call.
I found this entry in Magento Wiki, that helped me and seems to fit my needs.
However, at the end the author is setting two things :
$product->setConfigurableProductsData($data);
$product->setConfigurableAttributesData($data);
and the values in the arrays have been taken in the admin page source using Firebug....and then translated into PHP arrays (array example for the first call) :
"I’ve harcoded the values for my associated products and attribute
data. You can get attribute data by viewing the source through the
admin interface and using Firebug for Firefox."
$data = array('5791'=>array('0'=>array('attribute_id'=>'491', // I already got this
'label'=>'vhs', // this too
'value_index'=>'5', // but what is value_index ?
'is_percent'=>0,
'pricing_value'=>'')),
'5792'=>array('0'=>array('attribute_id'=>'491',
'label'=>'dvd',
'value_index'=>'6',
'is_percent'=>0,
'pricing_value'=>'')));
My question is : is there a way to retrieve these values without using Firebug (which in my script won't help me a lot !), but programmatically. I already found a way to retrieve attribute values, labels, etc... using its code, but one field I don't know is value_index.
I guess this may be the option position in an option list, but not sure.
Also if someone knows a good/better way to create a configurable product in Magento, please tell me.
Any help is welcome thank you.
It seems you're asking where to retrieve the value_index value where you already have the label. Here's what I had: I didn't test this on 1.5x.
function get_attribute_id($option, $type) {
$attributeId = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('catalog_product', $type);
$attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);
$attributeOptions = $attribute->getSource()->getAllOptions();
foreach ($attributeOptions as $opts_arr) {
if (strtoupper($opts_arr['label']) == strtoupper($option)) {
return $opts_arr['value'];
}
}
return FALSE;
}
$value_index = get_attribute_id('vhs', 'media_format');
No one else seemed to mention the easiest way to figure out what the value_index of vhs is: In the backend, under
Catalog > Manage > media_format > Manage Label/Options
Inspect the source of the individual form inputs. Where you have 'vhs' you should have an input named option[value][6]
As far as I understand your question, there are two options: a) create simple products by script, put the generated id's in an array and create the configurables using the ids or b) read the id's from the admin and put them in your script. Since programming is about automation I'd definately go for option a.

Categories