adding taxes to a checkout api transaction - square-connect

I'm having trouble adding taxes to a square checkout api transaction. Everything else is working, but I can't make the taxes part work. It would be appreciated if someone could post a few lines of the relevant php code that adds taxes at the item or order level. Thank you in advance.

Here's an example of a PHP Checkout request that create a $5.00 charge, with a 10% tax (50 cent) at the order level:
$checkout_api = new \SquareConnect\Api\CheckoutApi();
$request_body = new \SquareConnect\Model\CreateCheckoutRequest(
[
"idempotency_key" => uniqid(),
"order" => [
"line_items" => [
[
"name" => "Test Payment",
"quantity" => "1",
"base_price_money" => [
"amount" => 500,
"currency" => "USD"
]
]],
"taxes" => [
[
"name" => "This is so taxing",
"type" => "ADDITIVE",
"percentage" => "10"
]
]
]
]
);
$response = $checkout_api->createCheckout($location_id, $request_body);
If you want to add it at the item level, you would just move the taxes array to inside the line_items object. Example of 2 items, one with tax and one without:
$checkout_api = new \SquareConnect\Api\CheckoutApi();
$request_body = new \SquareConnect\Model\CreateCheckoutRequest(
[
"idempotency_key" => uniqid(),
"order" => [
"line_items" => [
[
"name" => "Test Payment",
"quantity" => "1",
"base_price_money" => [
"amount" => 500,
"currency" => "USD"
],
"taxes" => [
[
"name" => "This is so taxing",
"type" => "ADDITIVE",
"percentage" => "10"
]
]
],
[
"name" => "Test Payment Without Tax",
"quantity" => "1",
"base_price_money" => [
"amount" => 500,
"currency" => "USD"
]
]],
]
]
);
$response = $checkout_api->createCheckout($location_id, $request_body);

Related

How to Set Up Multiparty Payments (Onboard Sellers)

I am Trying To Implement Paypal Multiparty payment so i can connect seller and Buyers and then i take x% of fee from them for using the platform
eg. Fiverr,Upwork,Freelancer,
so first the seller connect his account and then they can sell services and accept payment through paypal but i dont know how to connect There Paypal account to My app
I am using laravel 9 with srmklive/laravel-paypal package
This is my Code
Route::get('https://api-m.sandbox.paypal.com/v2/customer/partner-referrals', function () {
$provider = new PayPalClient;
$provider->setApiCredentials(config('paypal'));
$paypalToken = $provider->getAccessToken();
$partner = $provider->createPartnerReferral([
"operations" => [
[
"operation" => "API_INTEGRATION",
"api_integration_preference" => [
"rest_api_integration" => [
"integration_method" => "PAYPAL",
"integration_type" => "FIRST_PARTY",
"first_party_details" => [
"features" => [
"PAYMENT",
"REFUND"
],
"seller_nonce" => uniqid()
]
]
]
]
],
"products" => [
"EXPRESS_CHECKOUT"
],
"legal_consents" => [
[
"type" => "SHARE_DATA_CONSENT",
"granted" => true
]
]
]);
dd($partner);
})
this is the out put
^ array:2 [▼
"type" => "error"
"message" => "{"operations":[{"operation":"API_INTEGRATION","api_integration_preference":{"rest_api_integration":{"integration_method":"PAYPAL","integration_type":"FIRST_PARTY","first_party_details":{"features":["PAYMENT","REFUND"],"seller_nonce":"623a1fcec9be3"}}}}],"products":["EXPRESS_CHECKOUT"],"legal_consents":[{"type":"SHARE_DATA_CONSENT","granted":true}]} {"name":"INVALID_REQUEST","message":"Request is not well-formed, syntactically incorrect, or violates schema.","debug_id":"f64fe0ec63213","information_link":"","details":[{"issue":"INVALID_STRING_LENGTH","description":"The length of a field value should not be shorter than 44 characters.","field":"/operations/0/api_integration_preference/rest_api_integration/first_party_details/seller_nonce","location":"body"}],"links":[]} ◀"
]
Thank in Advance
Route::get('https://api-m.sandbox.paypal.com/v2/customer/partner-referrals', function () {
$provider = new PayPalClient;
$provider->setApiCredentials(config('paypal'));
$paypalToken = $provider->getAccessToken();
$partner = $provider->createPartnerReferral([
"operations" => [
[
"operation" => "API_INTEGRATION",
"api_integration_preference" => [
"rest_api_integration" => [
"integration_method" => "PAYPAL",
"integration_type" => "FIRST_PARTY",
"first_party_details" => [
"features" => [
"PAYMENT",
"REFUND"
],
"seller_nonce" => uniqid()
]
]
]
]
],
"products" => [
"EXPRESS_CHECKOUT"
],
"legal_consents" => [
[
"type" => "SHARE_DATA_CONSENT",
"granted" => true
]
]
]);
dd($partner);
})
this is the out put
^ array:2 [▼
"type" => "error"
"message" => "{"operations":[{"operation":"API_INTEGRATION","api_integration_preference":{"rest_api_integration":{"integration_method":"PAYPAL","integration_type":"FIRST_PARTY","first_party_details":{"features":["PAYMENT","REFUND"],"seller_nonce":"623a1fcec9be3"}}}}],"products":["EXPRESS_CHECKOUT"],"legal_consents":[{"type":"SHARE_DATA_CONSENT","granted":true}]} {"name":"INVALID_REQUEST","message":"Request is not well-formed, syntactically incorrect, or violates schema.","debug_id":"f64fe0ec63213","information_link":"","details":[{"issue":"INVALID_STRING_LENGTH","description":"The length of a field value should not be shorter than 44 characters.","field":"/operations/0/api_integration_preference/rest_api_integration/first_party_details/seller_nonce","location":"body"}],"links":[]} ◀"
]
"details":[{"issue":"INVALID_STRING_LENGTH","description":"The length of a field value should not be shorter than 44 characters.","field":"/operations/0/api_integration_preference/rest_api_integration/first_party_details/seller_nonce
Error message details are useful, yes? The field is documented in the API reference. You can also try omitting it.
After some search, I found out the problem was that my seller_nonce field was lowered than 44 characters, so make sure your seller_nounce is more than 44 characters. Also, make sure you have checked the box On Board After Payment
seller_nonce => uniqid(Str::random(40), true)

Magento 2 rest api doesn't update salable quantity

I use rest api to create a simple product on my magento. All works correctly except quantity column that is correctly update on "Quantity" column but not on the salable quantity.
Rest call: "www.mysite.com/V1/products"
Array data
$data = [
"product" => [
"sku" => $sku,
"name" => $product_title,
"attribute_set_id" => 4,
"price" => $price,
"status" => 1,
"visibility" => 4,
"type_id" => "simple",
"weight" => "1",
"extension_attributes" => [
"category_links" => [
[
"position" => 0,
"category_id" => "53"
]
],
"stock_item" => [
"qty" => $qty,
"is_in_stock" => true
]
],
"custom_attributes" => [
[
"attribute_code" => "special_price",
"value" => $salable_price
],
[
"attribute_code" => "special_from_date",
"value" => "2021-02-07 00:00:00"
],
[
"attribute_code" => "special_to_date",
"value" => "2091-02-07 00:00:00"
],
[
"attribute_code" => "cost",
"value" => $salable_price
],
[
"attribute_code" => "description",
"value" => $description
],
[
"attribute_code" => "short_description",
"value" => $short_description
]
]
]
];
As you see, qty has been correctly update on qty column but not on the salable quantity. What is my mistake?
Please try this:
"stockItem": {
"is_in_stock": 1,
"qty": 10,
"manage_stock": true,
"use_config_manage_stock": 1
}

How to print value in blade from $lookup in laravel

I have two collections in MongoDB I want to aggregation between them, it worked fine but I don't know how to print the value in the blade(view) of levels that's come from other collection?
$allRanges = Range::raw(( function($collection) {
return $collection->aggregate([
[
'$lookup' => [
'from' => 'Levels',
'localField' => 'LevelId',
'foreignField'=> '_id',
'as' => 'levels'
]
], [
'$match' =>[
'PlanTypeId'=> '5daad2c12939b70f0b7ff052'
]
],
]);
})))->toarray();
output:
=> [
[
"_id" => "5daad809095e6f0c7e37fbf2",
"PlanTypeId" => "5daad2c12939b70f0b7ff052",
"LevelId" => "5dab14832d31e850ea1644b2",
"Range" => "range1",
"step" => 1,
"part" => 10,
"levels" => MongoDB\Model\BSONArray {#3149
flag::STD_PROP_LIST: false,
flag::ARRAY_AS_PROPS: false,
iteratorClass: "ArrayIterator",
storage: [
MongoDB\Model\BSONDocument {#3146
flag::STD_PROP_LIST: false,
flag::ARRAY_AS_PROPS: true,
iteratorClass: "ArrayIterator",
storage: [
"_id" => MongoDB\BSON\ObjectId {#3147
+"oid": "5dab14832d31e850ea1644b2",
},
"PlanTypeId" => "5daad2c12939b70f0b7ff052",
"Level" => "1",
],
},
],
},
],
I get the Range but how get for example levels->Level?
<tr>
#foreach($allRanges as $d)
<td>{{$d['Range']}}</td>
</tr>
#endforeach

Elasticsearch query for simple category search, sorting by price and getting records by range

I want to write query with following condition :
search by category (like category = 'cat1')
and with price range (and price between 100 to 500)
and sort by price (low to high)
I tried:
$params = [
'index' => 'my_index',
'type' => 'product',
'body' => [
//"from" => 0, "size" => 2,
"sort" => [
["default_product_low_price.sale_price" => ["order" => "asc"]]
],
'query'=> $query,
"aggs" => [
"default_product_low_price" => [
"nested" => [
"path" => "default_product_low_price"
],
"aggs" => [
"range" => ["default_product_low_price.sale_price" => [ "gte" => '790',
"lte" => '1000' ]],
//"max_price" => ["max" => [ "field" => "default_product_low_price.sale_price" ]]
],
]
]
]
];
But I am getting an error
Bad Request 400 Exception in GuzzleConnection.php line 277: error.
Please guide me where I am wrong? What is the right query?
I think this should be your query :
$params = [
'index' => 'my_index',
'type' => 'product',
'body' => [
"sort" =>[
["default_product_low_price.sale_price" => ["order" => "asc"]]
],
"query"=> [
"filtered"=> [
"query"=> [
"match_all"=> []
],
"query"=>[
"term"=> [
"category.name"=> "jeans"
]
],
"filter"=> [
"nested"=> [
"path"=> "default_product_low_price",
"filter"=> [
"bool"=> [
"must"=> [
[
"range"=> [
"default_product_low_price.sale_price"=> [
"gte"=> 100,
"lte"=> 200,
]
]
]
]
]
]
]
]
]
]
]
];

Order by in aggregation ES laravel

I'm trying to order elements by field descending in Elasticquent, but don't know how. This is my code:
$laws_y = Law::searchByQuery([
],
[
"group_by_law_year" => ["terms" => ['field' => "law_year", "size" => 100]]
]);
Can anyone help?
You can do it using the order setting and order by _term: desc:
$laws_y = Law::searchByQuery([
],
[
"group_by_law_year" => [
"terms" => [
'field' => "law_year",
"order" => ["_term" => "desc" ], <--- add this line
"size" => 100
]
]
]);

Resources