I am trying to insert products on Google Merchant Center. I am currently using Google API PHP client, and I am unable to find toSimpleObject function in any of the class and class extending it.
$this->service = new Google_Service_ShoppingContent($client);
$product = array("batchId" => $batchID,
"merchantId" => $this->googleapi->merchantID,
"method" => "insert",
"product" => array(
"kind" => "content#product",
"offerId" => $skuDetails['SKU'],
"title" => $skuDetails['TITLE'],
"description" => $skuDetails['DESCRIPTION'],
"imageLink" => $skuDetails['IMAGE'],
"contentLanguage" => "en",
"targetCountry" => "US",
"channel" => "online",
"availability" => ($skuDetails['QUANTITY'] > 0)?'in stock':'out of stock',
"brand" => $skuDetails['BRAND'],
"condition" => $skuDetails['CONDITION'],
"minHandlingTime" => $skuDetails['HANDLING_TIME'],
"ageGroup" => 'adult',
"maxHandlingTime" => ($skuDetails['HANDLING_TIME'] + 2),
"googleProductCategory" => (empty($skuDetails['CATEGORYID']))?$skuDetails['CATEGORYPATH']:$skuDetails['CATEGORYID'],
"price" => [
"value" => $price['lp'],
"currency" => "USD"
]
)
);
$productObject = new Google_Service_ShoppingContent_ProductsCustomBatchRequest();
$productObject->setEntries($product);
$result = $this->service->products->custombatch($productObject);
Error:
An uncaught Exception was encountered
Type: Error
Message: Call to undefined method Google_Service_ShoppingContent_ProductsCustomBatchRequest::toSimpleObject()
Line Number: 108
Backtrace:
File: vendor/google/apiclient-services/src/Google/Service/ShoppingContent/Resource/Products.php
Line: 40
Function: call
You should be using Google_Service_ShoppingContent_Product to insert data to your product instance then you can use custombatch to upload it
$product = new Google_Service_ShoppingContent_Product();
$product->setId($id);
$product->setTitle($title);
Related
I would like to store credit card information for a customer in our QuickBooks account
using the PHP Payments SDK - the following is what I am trying to achieve this but I get an invalid arguments error:
$client = new PaymentClient([
'access_token' => $accessTokenValue,
'environment' => "sandbox" ]);
$array = [
"number" => "4408041234567893",
"expMonth" => "12",
"expYear" => "2026",
"name" => "Test User",
"address" => [
"streetAddress" => "1245 Hana Rd",
"city" => "Richmond",
"region" => "VA",
"country" => "US",
"postalCode" => "44112"
],
"customerid" => "94"
];
$create = CardOperations::createCard($array);
$response = $client->charge($create);
I have not had any luck reaching out to support, any way this can be done, I appreciate the help.
Error received:
Uncaught TypeError: Argument 1 passed to
QuickBooksOnline\Payments\Operations\CardOperations::createCard() must
be an instance of QuickBooksOnline\Payments\Modules\Card, array given
UPDATE using recommended code:
Uncaught ArgumentCountError: Too few arguments to function
QuickBooksOnline\Payments\Operations\CardOperations::createCard(), 1
passed
As per your error it seems the required Card data should be an instance of the class
QuickBooksOnline\Payments\Modules\Card
But you're passing array to it. As per the documentation could you please check this below code , hopefully it will work.
$client = new PaymentClient([
'access_token' => $accessTokenValue,
'environment' => "sandbox"
]);
$cardData = [
"number" => "4408041234567893",
"expMonth" => "12",
"expYear" => "2026",
"name" => "Test User",
"address" => [
"streetAddress" => "1245 Hana Rd",
"city" => "Richmond",
"region" => "VA",
"country" => "US",
"postalCode" => "44112"
],
"customerid" => "94"
];
$chargeData = [
"amount" => "10.55",
"currency" => "USD",
"card" => $cardData,
"context" => [
"mobile" => "false",
"isEcommerce" => "true"
]
];
$customerId = "94";
$charge = ChargeOperations::buildFrom($chargeData);
$chargeResponse = $client->charge($charge);
$clientId = rand();
$card = CardOperations::buildFrom($cardData);
$createCardresponse = $client->createCard($card, $clientId, rand() . "abd");
//or alternatively $createCardresponse = $client->createCard($card, $customerId, rand() . "abd");
I am new to codeigniter I am trying to save my record into the database and when ever I try to do so it gives me this error.
Fatal error: Uncaught ActiveRecord\UndefinedPropertyException: Undefined property: Product->Array in C:\xampp\htdocs\cafe\sparks\php-activerecord\0.0.2\vendor\php-activerecord\lib\Model.php on line 514 in C:\xampp\htdocs\cafe\sparks\php-activerecord\0.0.2\vendor\php-activerecord\lib\Model.php:514 Stack trace: #0 C:\xampp\htdocs\cafe\sparks\php-activerecord\0.0.2\vendor\php-activerecord\lib\Model.php(333): ActiveRecord\Model->read_attribute('Array') #1 C:\xampp\htdocs\cafe\sparks\php-activerecord\0.0.2\vendor\php-activerecord\lib\Validations.php(573): ActiveRecord\Model->__get('Array') #2 C:\xampp\htdocs\cafe\sparks\php-activerecord\0.0.2\vendor\php-activerecord\lib\Validations.php(141): ActiveRecord\Validations->validates_uniqueness_of(Array) #3 C:\xampp\htdocs\cafe\sparks\php-activerecord\0.0.2\vendor\php-activerecord\lib\Model.php(1048): ActiveRecord\Validations->validate() #4 C:\xampp\htdocs\cafe\sparks\php-activerecord\0.0.2\vendor\php-activerecord\lib\Model.php(784): ActiveRecord\Model->_validate() #5 C:\xampp\htdocs in C:\xampp\htdocs\cafe\sparks\php-activerecord\0.0.2\vendor\php-activerecord\lib\Model.php on line 514
The code I have wrote works fine for other models. Here is the code I am using.
$data = array(
"type" => $this->input->post('type'),
"code" => $this->input->post('code'),
"name" => $this->input->post('name'),
"category" => $this->input->post('category'),
"cost" => $this->input->post('cost'),
"description" => $this->input->post('description'),
"tax" => $this->input->post('tax'),
"alertqt" => $this->input->post('alertqt'),
"price" => $this->input->post('price'),
"color" => $this->input->post('color'),
"supplier" => $this->input->post('supplier'),
"unit" => $this->input->post('unit'),
"taxmethod" => $this->input->post('taxmethod'),
"options" => $this->input->post('options'),
"photo" => $image,
"photothumb" => $image_thumb,
"created_at" => $date,
"modified_at" => $date
);
$product = Product::create($data);
I have solved it the issue was not in the controller but it was in the model. I was validating uniqueness of array but actually it was not needed. Removing that block of code works fine.
When using the new gocardless api examples I can list customers so I'm assuming that I have composer installed correctly but when I try the example for creating a subscription (as listed below) I get http error 500 does anybody know what I may be doing wrong?
<?php
require 'vendor/autoload.php';
$client = new \GoCardlessPro\Client(array(
'access_token' => 'my_sandbox_access_token_goes_here',
'environment' => \GoCardlessPro\Environment::SANDBOX
));
$client->subscriptions()->create([
"params" => ["amount" => 25,
"currency" => "GBP",
"name" => "Monthly test",
"interval_unit" => "monthly",
"day_of_month" => 1,
"metadata" => ["order_no" => "test1"],
"links" => ["mandate" => "MA125"]]
]);
?>
Thanks
I'm working with a fly web service.I should to be able to create following json format and send to the server :
{
"FareSourceCode": "313139353639393726323426363636323231",
"SessionId": "53a2210f-b151-4aa1-bef0-3db2dbe71565",
"TravelerInfo": {
"PhoneNumber": "02012345678",
"Email": "Sales#partocrs.com",
"AirTravelers": [
{
"DateOfBirth": "1990-11-01T00:00:00",
"Gender": 0,
"PassengerType": 1,
"PassengerName": {
"PassengerFirstName": "John",
"PassengerLastName": "Smith",
"PassengerTitle": 0
},
"Passport": {
"Country": "US",
"ExpiryDate": "2020-05-06T00:00:00",
"PassportNumber": "AB1234567"
},
"NationalId": "0012230877",
"Nationality": "US",
"ExtraServiceId": [
"sample string 1"
],
"FrequentFlyerNumber": "123456789",
"SeatPreference": 0,
"MealPreference": 0
}
]
}
}
I use SoapClient in php7 with this code :
<?php
$PassengerData = //Get passengers informations from mysql
$AirTravelers = array();
foreach ($PassengerData as $p) {
$PassengerType = 'Adt'; //Adult
$PassengerTitle = ($p->sex) ? 'Mrs' : 'Mr';
$AirTravelers = [
'DateOfBirth' => $p->age,
'Gender' => $p->sex ? 'Female' : 'Male',
'PassengerType' => $PassengerType,
'PassengerName' => [
'PassengerFirstName' => $p->efname,
'PassengerLastName' => $p->elname,
'PassengerTitle' => $PassengerTitle,
],
'Passport' => [
'Country' => 'IR',
'ExpiryDate' => $p->passport_expire,
'PassportNumber' => $p->passport_number,
],
'NationalId' => $p->ncode,
'Nationality' => 'IR',
'SeatPreference' => 'Any',
'MealPreference' => 'Any',
];
}
$client = new \SoapClient($ServerHttp);
$session = $client->CreateSession(array("rq" => [ "OfficeId" => $PartoOfficeId, "UserName" => $PartoUserName, "Password" => $PartoPassword]));
$AirBook = $client->AirBook(
array("rq" => [
'FareSourceCode' => $FareSourceCode,
'SessionId' => $session->CreateSessionResult->SessionId,
'TravelerInfo' => ['PhoneNumber' => $current_user_data->mobile,
'Email' => $current_user_data->user_name,
'AirTravelers' =>$AirTravelers
]
]
)
);
But this code can't make correct json format.Because php output json like this :
"AirTravelers": **[**{...}**]**
When i see json log(with json_encode):
json_encode([
'FareSourceCode' => $FareSourceCode,
'SessionId' => $session->CreateSessionResult->SessionId,
'TravelerInfo' => ['PhoneNumber' => $current_user_data->mobile,
'Email' => $current_user_data->user_name,
'AirTravelers' => $AirTravelers
]
])
It is like this (php output json):
"AirTravelers": **{**
And When i use this code :
json_encode([
'FareSourceCode' => $FareSourceCode,
'SessionId' => $session->CreateSessionResult->SessionId,
'TravelerInfo' => ['PhoneNumber' => $current_user_data->mobile,
'Email' => $current_user_data->user_name,
'AirTravelers' => **[**$AirTravelers**]**
]
])
Json output format were as follows:
$AirTravelers = **[**{....}]**strong text**
My question is :How can i send correct json format to this web service?
I use json_encode in my php request but it doesn't work and when i use :
$AirBook = $client->AirBook(
array("rq" => [
'FareSourceCode' => $FareSourceCode,
'SessionId' => $session->CreateSessionResult->SessionId,
'TravelerInfo' => ['PhoneNumber' => $current_user_data->mobile,
'Email' => $current_user_data->user_name,
'AirTravelers' =>[$AirTravelers]
]
]
)
);
I receive this error in php :
Fatal error: Uncaught SoapFault exception: [a:DeserializationFailed ] The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:rq. The InnerException message was 'There was an error deserializing the object of type ServiceModel.Request.AirBook. The value '1988-11-16 00:00:00' cannot be parsed as the type 'DateTime'.'. Please see InnerException for more details. in C:\wamp64 \www\paradise\wp-content\plugins\amir_traveler\fly\fly_functions.php on line 341
SoapFault: The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:rq. The InnerException message was 'There was an error deserializing the object of type ServiceModel.Request.AirBook. The value '1988-11-16 00:00:00' cannot be parsed as the type 'DateTime'.'. Please see InnerException for more details. in C:\wamp64\www\paradise\wp-content\plugins\amir_traveler\fly\fly_functions.php on line 341
I'm trying to create this XML in a SOAP call
<ns1:NameID type="INTERNAL">831392</ns1:NameID>
<ns1:NameMembership primary="true" displaySequence="1">
<ns2:membershipType>PFS</ns2:membershipType>
<ns2:membershipNumber>222222E</ns2:membershipNumber>
<ns2:membershipLevel>SILVER</ns2:membershipLevel>
<ns2:memberName>Luis Fernandez </ns2:memberName>
</ns1:NameMembership>
I don't know how to add the primarykey and displaySequence` attributes. I trying to create something like this:
$parameters = array("NameID" => array("_" => "831392", "type" => "INTERNAL"),
"NameMembership" => array("_" => array(
"membershipLevel" => "SILVER",
"memberName" => "Luis Fernandez",
"membershipType" => "PFS",
"membershipNumber" => "222222E"), "primary" => true, "displaySequence" => 1
));
But it doesn't work. It returns this code:
<ns1:InsertGuestCardRequest>
<ns1:NameID type="INTERNAL">831392</ns1:NameID>
<ns1:NameMembership primary="true" displaySequence="1"/>
</ns1:InsertGuestCardRequest>
Can anyone help me to find what am I doing wrong?
I got it! Thanks!
$parameters = array("NameID" => array("_" => "831392", "type" => "INTERNAL"),
"NameMembership" => array(
"membershipLevel" => "SILVER",
"memberName" => "Luis Fernandez",
"membershipType" => "PFS",
"membershipNumber" => "222222E",
"primary" => true,
"displaySequence" => 1
));