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)
Related
Validating Arrays not working in laraval 9.
Request as follows
array:2 [
0 => array:4 [
"nic" => "908110248V"
"employee_id" => "1"
"request_id" => "2"
"schedule_training_id" => "1"
]
1 => array:4 [
"nic" => "962930898v"
"employee_id" => "2"
"request_id" => "1"
"schedule_training_id" => "1"
]
]
validator code snipit as follows
$validator = Validator::make($request->input('data_attributes'), [
'data_attributes.*.nic' => 'required|max:9'
]);
$validator = Validator::make($request->input('data_attributes'), [
'*.nic' => 'required|max:9'
]);
You should check the matrix as a whole and then start working with its elements, this is an example of what you should do:
$validator = Validator::make($request->input('data_attributes'), [
"data_attributes" => "required|array|min:3",
"data_attributes.*" => "required|string|distinct|min:3",
]);
I'm relatively new to MongoDB and trying to figure out how to search for data which has dynamic keys, my dataset is below:
[
'id' => '60bb040f7e589378f644f9a2',
'name' => 'foo',
'settings' => [
'foo' => [
'type' => 'custom',
'enabled' => 'yes'
],
'bar' => [
'type' => 'custom',
'enabled' => 'no'
],
'baz' => [
'type' => 'custom',
'enabled' => 'no'
]
]
]
I want to get the search inside settings, and get all the settings which has enabled as yes.
I've tried this
return Customer::raw(function($collection) {
return $collection->aggregate([
[
'$search' => [
"wildcard" => [
'query' => 'yes',
'path' => 'settings.*.enabled'
]
]
]
]);
});
I am getting the following errror:
Unrecognized pipeline stage name: '$search'
I've also tired using $match, like this
Customer::raw(function($collection)
{
return $collection->aggregate([
[
'$match' => [
"settings.*.enabled" => 'yes'
]
],
]);
})
But it does't return any value.
Any direction on achieving this will be helpful. Thanks!
Ok this is a bit complex but is all I can come up with myself:
Customer::raw(function($collection)
{
return $collection->aggregate([
[
'$addFields' => [
"settingsArray" => [
'$objectToArray' => '$settings'
]
]
],
[
'$unwind' => [
'path' => '$settingsArray'
]
],
[
'$match' => [
'settingsArray.v.enabled' => 'yes'
]
],
[ '$unset' => 'settingsArray' ],
[
'$group' => [
'_id' => '$_id',
doc => [ '$first' => '$$ROOT' ]
]
],
[
'$replaceRoot' => [
'newRoot' => '$doc'
]
]
]);
});
This should return all documents with at least one enabled setting.
A key point about aggregation is that the pipeline works on all documents that the previous stage of the pipeline returned.
Here's the aggregation pipeline explanation:
$addFields will convert the settings object to an array of format [ { k: key, v: value } ] e.g. [ { k: 'foo', 'v': { type: 'custom', enabled: 'yes' } }, ... ]
$unwind will "unwind" the document and "replace" it with X copies of the same document one for each entry in the newly added settingsArray array. The settingsArray at this stage is not an array anymore but a single entry of type { k: key, v: value }. In short you'd get one document per setting
$match will do the actual matching for any document with an enabled setting (remember now each document will only have a single setting as settingsArray
$unset will remove the settingsArray from each document bringing it back to its original format
$group will group all documents by their _id and use the first result of each group as a doc entry. Each document will now be like { _id: <id>, doc: <original document> }
$replaceRoot will set the root of the document to doc and therefore bring the documents back to their original format.
Would love to hear if anyone else has a better solution here.
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);
I watched Elasticsearch Do's, Don'ts and Pro-Tips by Itamar Syn Hershko
https://www.youtube.com/watch?v=c9O5_a50aOQ
I see multiple conditions in several fields in the following image:
https://imgur.com/a/17zAZ4w
I tried to make it in
my Laravel 5.7 app (with the elasticsearch/elasticsearch plugin) as seen in the following code:
$elasticQuery = [
"bool" => [
'must' => [
'multi_match' => [
'query' => $text,
'fields' => ['name^4', 'description']
],
],
"should" => [
'term' => [
"category_id" => 1,
]
]
]
];
but I got the error :
{"error":{"root_cause":[{"type":"parsing_exception","reason":"[bool] malformed query, expected [END_OBJECT] but found [FIELD_NAME]","line":1,"col":130}],"type":"parsing_exception","reason":"[bool] malformed query, expected [END_OBJECT] but found [FIELD_NAME]","line":1,"col":130},"status":400}
But when I use a simple condition:
$elasticQuery = [
'multi_match' => [
'query' => $text,
'fields' => ['name^4', 'description'],
],
];
I got a valid result:
[hits] => Array
(
[total] => 1
[max_score] => 7.4126062
[hits] => Array
(
[0] => Array
(
[_index] => select_vote
[_type] => vote
[_id] => 16
[_score] => 7.4126062
[_source] => Array
(
[id] => 16
[slug] => in-the-film-babe-what-type-of-animal-was-babe
[name] => In the film Babe, what type of animal was Babe?
[description] => Babe is a 1995 A...
[created_at] => 2018-11-10 09:14:15
[category_id] => 2
[category] => Array
(
[name] => Movie&Cartoons
[slug] => movie-cartoons
[created_at] => 2018-11-10 09:14:12
)
)
)
)
)
is this a valid format for multi-request?
MODIFIED BLOCK # 2:
Making some search I found work:
$elasticQuery = [
"bool" => [
'should' => [
[
"multi_match" => [
"query" => $text,
"type" => "cross_fields",
"fields" => [
"name^4",
"description"
]
]
],
[
'match' => [
'category_id' => [
'query' => 1,
]
]
],
[
'match' => [
'category_id' => [
'query' => 3,
]
]
],
]
]
];
when I need to make a search by text fields and the array of category (1 and 3) in the example above it works but looks like it works like an "OR" condition, but I need to make a restriction like "AND" using SQL terminology...
Which way is correct in order to make a restriction as like "AND"?
Thanks!
If you just change should to must it is not going to work because category_id cannot have two values at the same time (unless it's an array, but it's not).
You need to use the following query instead:
$elasticQuery = [
"bool" => [
'must' => [
[
"multi_match" => [
"query" => $text,
"type" => "cross_fields",
"fields" => [
"name^4",
"description"
]
]
],
],
'filter' => [
[
'terms' => [
'category_id' => [ 1, 3 ]
]
]
]
]
];
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,
]
]
]
]
]
]
]
]
]
]
]
];