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");
Related
I'm using the Merchant Fulfillment portion of the Amazon Selling Partner API found at https://github.com/jlevers/selling-partner-api/
I have other portions working... namely orders coming down and reports going up. But I am using the same techniques and the Merchant Fulfillment API is not working. The response I get back indicates that it's not received the data I am sending it.
What am I doing wrong?
// North America Live
$NA = [
'url' => 'https://sellingpartnerapi-na.amazon.com',
'region' => 'us-east-1',
];
// North America Sandbox
// $NA = [
// 'url' => 'https://sandbox.sellingpartnerapi-na.amazon.com',
// 'region' => 'us-east-1',
// ];
$config = new SellingPartnerApi\Configuration([
"lwaClientId" => $lwaClientId,
"lwaClientSecret" => $lwaClientSecret,
"lwaRefreshToken" => $lwaRefreshToken,
"awsAccessKeyId" => $awsAccessKeyId,
"awsSecretAccessKey" => $awsSecretAccessKey,
"endpoint" => $NA // or another endpoint from lib/Endpoint.php
]);
$apiInstance = new SellingPartnerApi\Api\MerchantFulfillmentApi($config);
$body = new \SellingPartnerApi\Model\MerchantFulfillment\GetEligibleShipmentServicesRequest(
[
"shipment_request_details" =>
[
"amazon_order_id" => "XXX-XXXXXXXX-XXXXXXXX",
"item_list" =>
[
"order_item_id" => "XXXXXXXXXXXXXXX",
"quantity" => 1,
],
"ship_from_address" =>
[
"name" => "XXXXXXX",
"address_line1" => "XXXXXXXXXX",
"email" => "XXXXX#XXXXX.COM",
"city" => "XXXXXXXXX",
"postal_code" => "XXXXXX",
"country_code" => "US",
"phone" => "XXXXXXXXXXXX",
],
"weight" =>
[
"value" => 7,
"unit" => "oz",
],
"shipping_service_options" =>
[
"delivery_experience" => "DeliveryConfirmationWithSignature",
"carrier_will_pick_up" => true,
]
]
]
);
try {
$result = $apiInstance->getEligibleShipmentServices($body);
d($result);
} catch (Exception $e) {
echo "<PRE>";
echo 'Exception when calling MerchantFulfillmentV0Api->getEligibleShipmentServices: <BR>', wordwrap($e->getMessage(),80,"<br>\n",TRUE), PHP_EOL;
echo "</PRE>";
}
The $response I get back is:
Exception when calling MerchantFulfillmentV0Api->getEligibleShipmentServices:
[400] {
"errors": [
{
"code": "InvalidInput",
"message": "5
validation errors detected: Value \u0027\u0027 at
\u0027shipmentRequestDetails.shipFromAddress.email\u0027 failed to satisfy
constraint: Member must satisfy regular expression pattern: .+#.+; Value
\u0027\u0027 at \u0027shipmentRequestDetails.amazonOrderId\u0027 failed to
satisfy constraint: Member must satisfy regular expression pattern:
[0-9A-Z]{3}-[0-9]{7}-[0-9]{7}; Value \u0027\u0027 at
\u0027shipmentRequestDetails.weight.unit\u0027 failed to satisfy constraint:
Member must satisfy enum value set: [g, ounces, oz, grams]; Value null at
\u0027shipmentRequestDetails.weight.value\u0027 failed to satisfy constraint:
Member must not be null; Value \u0027[]\u0027 at
\u0027shipmentRequestDetails.itemList\u0027 failed to satisfy constraint: Member
must have length greater than or equal to 1",
"details": ""
}
]
}
In the Shipping Service options.... this needs to be set false.
"carrier_will_pick_up" => true,
If its set to true then it will not work. I think it has something to do with sending a request for pickup to the carrier.... and it seems counter-intuitive to set it to false... but thats what made it work!
I'm having a hard time using a method setData() of the HttpBody class. I'm passing the parameter to the method as an object, but I recieve an error message.
How do I pass the parameter:
public function create(string $resource, $body)
{
$client = $this->googleClient();
$service = new CloudHealthcare($client);
$parent = "projects/my_project_id/locations/my_location/datasets/my_dataset/fhirStores/repository";
$httpBody = new HttpBody();
$httpBody->setContentType('application/fhir+json;charset=utf-8');
$httpBody->setData([
"resourceType" => "Patient",
"id" => "23434",
"meta" => [
"versionId" => "12",
"lastUpdated" => "2014-08-18T15:43:30Z"
],
"text" => [
"status" => "generated",
"div" => "<!-- Snipped for Brevity -->"
],
"extension" => [
[
"url" => "http://example.org/consent#trials",
"valueCode" => "renal"
]
],
"identifier" => [
[
"use" => "usual",
"label" => "MRN",
"system" => "http://www.goodhealth.org/identifiers/mrn",
"value" => "123456"
]
],
"name" => [
[
"family" => [
"Levin"
],
"given" => [
"Henry"
],
"suffix" => [
"The 7th"
]
]
],
"gender" => [
"text" => "Male"
],
"birthDate" => "1932-09-24",
"active" => true
]);
$data = $service->projects_locations_datasets_fhirStores_fhir->create($parent, $resource, $httpBody);
return $data;
}
Following the error message I get.
The error says I didn't pass the resourceType field, but it was passed:
Google\Service\Exception: {
"issue": [
{
"code": "structure",
"details": {
"text": "unparseable_resource"
},
"diagnostics": "missing required field \"resourceType\"",
"expression": [
""
],
"severity": "error"
}
],
"resourceType": "OperationOutcome"
} in file /usr/share/nginx/vendor/google/apiclient/src/Http/REST.php on line 128
How should I pass the parameter to receive the success message?
Tkanks!
I haven't tried the PHP client libraries specifically, but for most languages you don't want to use the HttpBody class - it's an indication that the method accepts something in the body of the request that is just text from the perspective of the method signature. I would try passing the JSON string directly.
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);
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 am trying to post child objects to a database with php and can't figure this out, any help is appreciated. The top clientId to invAmount posts fine, but the invoiceDetails child objects is where I am getting confused, I tried a while loop but no luck, I am a ui guy not php so I'm out of ideas.
The post:
{
"clientId": "5",
"invNumber": "2",
"invProject": "Test Project",
"invDescription": "Test",
"invDate": "09/20/2013",
"invAmount": "5000",
"invoiceDetails": [
{
"invRowDescription": "Description 1",
"invRowHours": "50",
"invRowRate": "50",
"invRowTotal": 2500
},
{
"invRowDescription": "Description 2",
"invRowHours": "50",
"invRowRate": "50",
"invRowTotal": 2500
}
]
}
The php controller
<?php
$_POST = json_decode(file_get_contents('php://input'), true);
// Independent configuration
require 'medoo.php';
$database = new medoo(array(
// required
'database_type' => 'mysql',
'database_name' => 'dbname',
'server' => 'server',
'username' => 'user',
'password' => 'pw'
));
$database->insert("invoiceSummary", array(
"clientId" => $_POST['clientId'],
"number" => $_POST['invNumber'],
"project" => $_POST['invProject'],
"description" => $_POST['invDescription'],
"date" => $_POST['invDate'],
"amount" => $_POST['invAmount']
));
while($rowInv = mysqli_fetch_array($_POST['invoiceDetails'])) {
$database->insert("invoiceDetails", array(
"clientId" => $_POST['clientId'],
"number" => $_POST['invNumber'],
"description" => $_POST['invRowDescription'],
"hours" => $_POST['invRowHours'],
"rate" => $_POST['invRowRate'],
"total" => $_POST['invRowTotal'],
));
}
echo json_encode('success');
?>