Stripe PHP checkout API : Error: Exception: Received unknown parameter: shipping - php

Im trying to pass shipping details to the checkout session built with:
\Stripe\Checkout\Session::create
But I guet this error:
Breaking news… Error: Exception: Received unknown parameter: shipping (in /myserver/stripe-php/lib/Exception/ApiErrorException.php line 38)
Except from that part the process works fine. Even if I pass "shipping" => null it doesn't give the error.
In the API reference it just shows the "shipping" data array as an optional attributes.
Here is the complete array I'm passing to the session::create
[billing_address_collection] => required
[payment_method_types] => Array
(
[0] => card
)
[line_items] => Array
(
[0] => Array
(
[price_data] => Array
(
[currency] => eur
[product_data] => Array
(
[name] => MEMBER 004: Dark Storm
[description] => sizes:'S-M'
[images] => Array
(
[0] => http://mywebsite.com/image.jpg
)
)
[unit_amount] => 1995
)
[quantity] => 1
)
)
[mode] => payment
[success_url] => http://mywebsite.com/succes/
[cancel_url] => http://mywebsite.com/cancel/
[shipping_address_collection] => Array
(
[0] => ES
)
[shipping] => Array
(
[address] => Array
(
[city] => Barcelona
[country] => ES
[line1] => Street name 81
[line2] => 12
[postal_code] => 09028
[state] => Catalunya
)
[name] => My name
)
[customer_email] => myname#gmail.com
)

You don't pass a shipping address into a Checkout session like this. It is not a parameter of the create endpoint. The shipping attribute of the session object will be populated with the customer shipping address when you use the shipping_address_collection parameter, as I see in your example.
So, you need to remove the invalid shipping parameter and instead inspect that on the result.

Related

How do I get order nested meta data in WooCommerce 3

We have installed another plugin for WooCommerce called Booster Plus for WooCommerce and this plugin can modify the checkout page by paying for an order by invoice number.
I am customizing our thank you page by displaying the invoice number too. Currently, I am not able to do that because I don't know how can I properly get the value of the nested $order->get_data() result.
<?php
$order_data = $order->get_data();
print_r($order_data);
?>
The result of order_data above looks like below:
(
[id] => 7403
[discount_total] => 0
[discount_tax] => 0
[shipping_total] => 0.00
[shipping_tax] => 0
[cart_tax] => 2.47
[total] => 21.47
[total_tax] => 2.47
[customer_id] => 20
[order_key] => wc_order_8pt3q7T79
[billing] => Array
(
[first_name] => John
[last_name] => Done
[company] => g2x
[address_1] => 3134 James Street
[address_2] =>
[city] => Moose Factory
[state] => ON
[postcode] => P0L 1W0
[country] => CA
[email] => testjohndoe123#gmail.com
[phone] => 705-658-2112
)
[cart_hash] => 087347d19dff4677dc8kaeb2b2c653c6
[number] => 7403
[meta_data] => Array
(
[0] => WC_Meta_Data Object
(
[current_data:protected] => Array
(
[id] => 102652
[key] => mailchimp_woocommerce_campaign_id
[value] =>
)
[data:protected] => Array
(
[id] => 102652
[key] => mailchimp_woocommerce_campaign_id
[value] =>
)
)
[1] => WC_Meta_Data Object
[2] => WC_Meta_Data Object
[3] => WC_Meta_Data Object
[4] => WC_Meta_Data Object
[5] => WC_Meta_Data Object
(
[current_data:protected] => Array
(
[id] => 102694
[key] => _wcj_custom_payment_gateway_input_fields
[value] => Array
(
[pay_by_po] => 123456789
)
)
[data:protected] => Array
(
[id] => 102694
[key] => _wcj_custom_payment_gateway_input_fields
[value] => Array
(
[pay_by_po] => 123456789
)
)
)
[coupon_lines] => Array
()
)
Do you know how can I get the value of [pay_by_po] which is 123456789? Any help is greatly appreciated. Thank you.
You can get and unprotect this nested meta data using WC_data method get_meta_data(), which gives an array of WC_Meta_Data Objects:
$meta_data = $order->get_meta_data();
print_r($order_data);
Then on each WC_Meta_Data Object, you can use WC_Meta_Data available methods like get_data() that gives an unprotected data array:
foreach( $order->get_meta_data() as $meta_data_obj ) {
$meta_data_array = meta_data_obj->get_data();
print_r($meta_data_array);
$meta_key = $meta_data_array['key']; // The meta key
$meta_value = $meta_data_array['value']; // The meta value
}
You can also get directly any nested meta data from the order using WC_Data method get_meta() from aspecific meta key as follow:
$meta_value = $order->get_meta('_wcj_custom_payment_gateway_input_fields');
print_r($meta_value);
Note This nested meta data exist since WooCommerce version 3.
About Abstract WC_Data Class
Its Implemented by classes using the same CRUD(s) pattern.
Direct known subclasses:
WC_Abstract_Legacy_Order, WC_Abstract_Legacy_Product, WC_Customer_Download, WC_Customer_Download_Log, WC_Legacy_Coupon, WC_Legacy_Customer, WC_Legacy_Payment_Token, WC_Legacy_Shipping_Zone, WC_Legacy_Webhook, WC_Order_Item
Indirect known subclasses:
WC_Abstract_Order, WC_Coupon, WC_Payment_Token, WC_Payment_Token_CC, WC_Payment_Token_ECheck, WC_Product, WC_Product_External, WC_Product_Grouped, WC_Product_Simple, WC_Product_Variable, WC_Product_Variation, WC_Shipping_Zone, WC_Customer, WC_Webhook, WC_Order, WC_Order_Item_Coupon, WC_Order_Item_Fee, WC_Order_Item_Product, WC_Order_Item_Shipping, WC_Order_Item_Tax, WC_Order_Refund
See: Developing using WooCommerce CRUD objects

Eror "price must be consistent across all products" etsy

I send "https://openapi.etsy.com/v2/listings/listing_id/inventory" but i received error "price must be consistent across all products"
that's what i give in offerings:
[offerings] => Array
(
[0] => Array
(
[price] => Array
(
[amount] => 14500
[divisor] => 100
[currency_code] => USD
[currency_formatted_short] => $145.00
[currency_formatted_long] => $145.00 USD
[currency_formatted_raw] => 145.00
)
[quantity] => 7
[is_enabled] => 1
[is_deleted] => 0
)
)
I had the same problem, and you also have to add the parameter [price_on_property], even if Etsy Api say it's optional.
When you are trying to update inventory, you don't include the entire Money object as json. The price is supplied as a double value only. (ex. "price=29.99")
It would look more like this
[offerings] => Array
(
[0] => Array
(
[price] => 145.00
[quantity] => 7
[is_enabled] => 1
[is_deleted] => 0
)
)

Is FedEx shipping api works in India Domestic

I tried to implement fedex api to calculate the cost of shipping betwnn to zip codes of a country. It is working fine for USA. It is also working from USA to other country(tried for IN and AU). But when I tried it for two zip codes from India or Australia as shipper and recipient address. It is giving below error :-
The transaction returned an Error.
Severity: ERROR
Source: crs
Code: 691
Message: The PurposeOfShipmentType is null, empty or invalid.
LocalizedMessage: The PurposeOfShipmentType is null, empty or invalid.
Don't know what is the issue. I checked the value for PurposeOfShipmentType in wsdl file it is showing below xml code :-
First occurrence
<xs:element name="Purpose" type="ns:PurposeOfShipmentType" minOccurs="0">
<xs:annotation>
<xs:documentation>The reason for the shipment. Note: SOLD is not a valid purpose for a Proforma Invoice.</xs:documentation>
</xs:annotation>
</xs:element>
second occurrence
<xs:simpleType name="PurposeOfShipmentType">
<xs:restriction base="xs:string">
<xs:enumeration value="GIFT"/>
<xs:enumeration value="NOT_SOLD"/>
<xs:enumeration value="PERSONAL_EFFECTS"/>
<xs:enumeration value="REPAIR_AND_RETURN"/>
<xs:enumeration value="SAMPLE"/>
<xs:enumeration value="SOLD"/>
</xs:restriction>
</xs:simpleType>
Don't understanding what should be the value. Below is array which I am sending into $client ->getRates($request) function
$request = Array
(
[WebAuthenticationDetail] => Array
(
[UserCredential] => Array
(
[Key] => *******
[Password] => *******
)
)
[ClientDetail] => Array
(
[AccountNumber] => *****
[MeterNumber] => *****
)
[TransactionDetail] => Array
(
[CustomerTransactionId] => *** Rate Available Services Request using PHP ***
)
[Version] => Array
(
[ServiceId] => crs
[Major] => 16
[Intermediate] => 0
[Minor] => 0
)
[ReturnTransitAndCommit] => 1
[RequestedShipment] => Array
(
[DropoffType] => REGULAR_PICKUP
[ShipTimestamp] => 2014-10-03T11:37:53+02:00
[Shipper] => Array
(
[Address] => Array
(
[StreetLines] => Array
(
[0] => 10 Fed Ex Pkwy
)
[City] => Memphis
[StateOrProvinceCode] =>
[PostalCode] => 110016
[CountryCode] => IN
)
)
[Recipient] => Array
(
[Address] => Array
(
[StreetLines] => Array
(
[0] => 13450 Farmcrest Ct
)
[City] => Herndon
[StateOrProvinceCode] =>
[PostalCode] => 302015
[CountryCode] => IN
)
)
[ShippingChargesPayment] => Array
(
[PaymentType] => SENDER
[Payor] => Array
(
[ResponsibleParty] => Array
(
[AccountNumber] => 510087500
[Contact] =>
[Address] => Array
(
[CountryCode] => IN
)
)
)
)
[PackageCount] => 2
[RequestedPackageLineItems] => Array
(
[0] => Array
(
[SequenceNumber] => 1
[GroupPackageCount] => 1
[Weight] => Array
(
[Value] => 2
[Units] => LB
)
[Dimensions] => Array
(
[Length] => 10
[Width] => 10
[Height] => 3
[Units] => IN
)
)
[1] => Array
(
[SequenceNumber] => 2
[GroupPackageCount] => 1
[Weight] => Array
(
[Value] => 5
[Units] => LB
)
[Dimensions] => Array
(
[Length] => 20
[Width] => 20
[Height] => 10
[Units] => IN
)
)
)
)
)
In order for the India to India domestic shipping to work you need to add in a PurposeOfShipment type to the request. This line is not standard in Magento's code for Fedex shipping. That line will be added into CustomsClearanceDetail header as a child under CommercialInvoice then a line under that is Purposewhich can have any value that PurposeOfShipment has.
Here is an example of the request I used that returned proper shipping estimates for India to India shipping.
'CustomsClearanceDetail' => array(
'CommercialInvoice' => array(
'Purpose' => "SOLD"
)
),
If I am not wrong, Fedex's Test Account doesn't return India specific info. Unless until its certified by the Fedex team and they provide you with the Production Key, you might not get the Rates aggreed for your account. Please do correct me if my understanding is wrong

How Do I access Data in Facebook Array with PHP?

I have made a simple facebook register widget.
On register the App sends the data to send.php
On send.php I have
print_r($response);
And I get something like this:
Array
(
[algorithm] => HMAC-SHA256
[expires] => 1367953200
[issued_at] => 1367946138
[oauth_token] => BAAE0refKufgBAORkK7hUaVpF8MnFygoqHAHrO3nRJMyNjvJx6RjiMjoqbz2YlfqeogcIPGJJaIgD0xtxhBj1WRgQ5F5SidjwM7ZCKOyZBlEuatIqIccbjGj2uMV5hqtKtZA1g7hOEqMeZAEwmnO6SgRgsb9ittKZCDnPfoxYxCxZAZBAhIKX457IG5ZB4yknv9FZB8QUG7Pt0mfBRQUYG12KoTmO7QRH20LP65FyPqTi7mAZDZD
[registration] => Array
(
[name] => derp derp
[email] => ddddd#gmail.com
[location] => Array
(
[name] => Vienna, Austria
[id] => 1.1116511224109E+14
)
[gender] => male
[phone] => sss
)
[registration_metadata] => Array
(
[fields] => [ {'name':'name'}, {'name':'email'}, {'name':'location'}, {'name':'gender'}, {'name':'phone', 'description':'Phone Number', 'type':'text'},]
)
[user] => Array
(
[country] => at
[locale] => en_US
)
[user_id] => 100000506481284
)
So the data gets passed without a problem but how can I access a specific value?
For example text book array stuff doesnt appear to be working like:
print $response[0];
Gives me an error:
Notice: Undefined offset: 0 in C:\xampp\htdocs\ddd\send.php on line 38
How else can I access the data?
For example how could I store country, email, name or whatever in their own variables so I can echo them later? Its there but I cant seem to figure out how to "digest" it properly with php.
There is no index 0 in the array you pasted..
Use it like
$email = $response['registration']['email'];
If it was an object instead of an array you would do
$email = $response->registration->email
This is very basic PHP array handling.
http://php.net/manual/en/language.types.array.php

SOAP not fetches result in PHP for Mouzenidis travel

I try to get results from http://api.mouzenidis-travel.com/search/ServiceMainSearch.svc?Wsdl
There is some methods to fetch data:
GetCountries // fetch available country data
GetCityDeparture(int countryID) //fetch available departure city data
GetFilter(int countryId, List departureCityId) // fetch others filters
// My PHP code:
$client = new SoapClient("http://api.mouzenidis-travel.com/search/ServiceMainSearch.svc?Wsdl");
$countryList = $client->GetCountries(); // results below
[0] => stdClass Object
(
[Code] => GR
[ID] => 29
[Name] => ГрециÑ
[NameLat] => Greece
)
[1] => stdClass Object
(
[Code] => CZ
[ID] => 6240
[Name] => ЧехиÑ
[NameLat] => Czech Republic
)
$cityDepObj = $client->GetCityDeparture(array('countryID'=>29));
[0] => stdClass Object
(
[Code] => MOW
[GroupName] => РоÑÑиÑ
[GroupNameLat] => РоÑÑиÑ
[GroupOrder] => 4
[ID] => 1
[Name] => МоÑква
[NameLat] => Moscow
[CountryID] => 460
[IsDeparture] => 1
[RegionID] => 0
)
[1] => stdClass Object
(
[Code] =>
[GroupName] => РоÑÑиÑ
[GroupNameLat] => РоÑÑиÑ
[GroupOrder] => 4
[ID] => 299
[Name] => ÐрхангельÑк
[NameLat] => Arkhangelsk
[CountryID] => 460
[IsDeparture] => 1
[RegionID] => 0
)
.
.
.
$client->GetFilter(array(29,array(1)));
Fatal error: Uncaught SoapFault exception: [s:Client] No connections available ...
I wrote to the Mouzendinis Tech Support, no results.
What make I wrong?
In C# this method requires field 'Country' as int, not an array of int. Also, other fields must be initialized as empty array or null.
The last field is a dictionary that caused filter update. For example: if you changed the city of departure, you should set the field to DictionaryEnum.CityDeparture
Can you check their API documentation and check what parameters required to pass to GetFilter method.
as you made $client->GetCityDeparture(array('countryID'=>29));, did you try with $client->GetFilter(array('countryId'=>29,'departureCityId'=>array(1))); ?
otherwise, try a wsdl to php geneator that'll ease you the requests construction and handling the response

Categories