Braintree Discount - PHP NotFound in Util.php line 64: - php

I am trying to override the discount amount i have created from Braintree control panel by calling the function below.
$result = Braintree_Subscription::create([
'paymentMethodToken' => 'the_payment_method_token',
'planId' => 'the_plan_id',
'addOns' => [
'add' => [
[
'inheritedFromId' => 'abcd',
'amount' => 20.00
]
]
]
]);
But it is returning me this error
NotFound in Util.php line 64:; Util::throwStatusCodeException('404') in Http.php line 47 Appreciate any help. Thanks!

Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support.
The 404 error you're seeing is likely being thrown due to one or more ID's specified in your API call not matching what you have in your control panel. The two ID's from your example code are the following:
A Plan with the ID the_plan_id
An add-on with the ID abcd
You'll want to ensure that you have a plan and add-on with those ID's in your control panel before using them in an API call. Since there isn't a way to generate plans or ID's from the API, you can follow the guide below on how to make them.
Making a Plan
The other potential issue here is that in your question, you mentioned you wanted to use a discount, where in your code, you're specifying an add-on. This might itself be the source of the problem. I would change these lines:
'addOns' => [
'add' => [
[
'inheritedFromId' => 'abcd',
'amount' => 20.00
]
]
to
'discounts' => [
'add' => [
[
'inheritedFromId' => 'abcd',
'amount' => 20.00
]
]

Related

Bigcommerce cart 422: Missing required fields error

I'm using Laravel to consume the Bigcommerce V3 API.
I have ben able to succesfully create a new cart. But when trying to add an item to it, I keep getting a 422: Missing required fields error.
I'm making my request trough Guzzle like this:
return json_decode($this->client->getRestClient()
->post('carts/'.$cartId.'/items?include=line_items.physical_items.options', [
'Accept' => 'application/json',
'json' => [
'line_items' => [
'product_id' => 86,
'quantity' => 1
],
],
])
->getBody())
->data;
The product I'm trying to add has no options or modifiers, so I don't understand what could wrong with my request. According to the docs, this should be all that's needed.
Does anyone have any idea what could be wrong? I tried contacting support, but to no avail.
Thanks in advance!
line_items is an array of objects. Try wrapping your product data in an object.
Like this:
'line_items' => [
{
'quantity' => 1,
'product_id' => 86
}
]
Your line_items field needs to have an array of objects, like this:
[
{
"product_id":86,
"quantity":1
}
]

Is there any method in brain-tree auto renew payment?

HI I am using braintree(braintree/braintree_php": "4.5.0) . I have implemented the 3dsecure in the web.It working fine. I need to auto renew the payment with paymentMethodToken. Below code i have used for auto renewal.
$trans = [
'amount' => "14.63",
'merchantAccountId' => "Vo**ID",
'paymentMethodToken' =>"token",
'transactionSource' => "recurring",
'customFields' => [
'client_id' => "id",
'service_id' => "id",
'invoice_id' => "id",
'action' => "autorenew",
'slots' => "15",
],
'options' => [
'submitForSettlement' => true,
'storeInVaultOnSuccess' => true,
'paypal' => [
'description' =>"Renew server",
]
]
];
$transaction = $gateway->transaction()->sale($trans);
When run this code i get below error
Authorization in Util.php line 59:
The above code is working when the user enter the credit card information to pay.This only gives error when i do payment with paymentMethodToken to auto renew the payments.Any help?
reference : https://developers.braintreepayments.com/guides/paypal/server-side/php
As per I understood your requirement. You need to do auto payment.
For that, Braintree provide the best way to do this called Subscription.
Let me know, If you need any more help.

How can I fetch distinct records from Elasticsearch

I am working on Elasticsearch (ES) for last couple of weeks. There are millions of records currently present in different search indices in ES.
I have noticed that in different search indices, there is duplication of records and it is creating problem.
We can search for duplicate records via code and remove those records. May be this can be applicable, but I have more than 100 million records so it will take lot of time.
My requirement is, while we fetch records from ES, we can apply different filters. Is there any filter or way we can only fetch distinct records? I am currently using REST API using PHP.
Here is the code that I am currently using and filters are working perfectly.
$params = [
'index' => 'MyIndex',
'type' => 'MyType',
'from' => 0,
'size' => 10,
'body' => [
'query' => [
'bool' => [
'must' => [
[ 'match' => [ 'image' => true ] ],
[ 'simple_query_string' => [ 'query' => 'MyQuery' ] ]
]
]
]
]
];
I also tried looking something from "Aggregations", but couldn't find something related to my requirement.
Quick help will be highly appreciated.
Thanks in advance.
I think what you are looking for is "collapsing".
Elasticsearch supports it from 6.x:
https://www.elastic.co/guide/en/elasticsearch/reference/6.x/search-request-collapse.html

Cannot get Vipps in payment window

Using the code sample from here, I wish to add payment with Vipps to the payment options, so I added the following key-values as per the documentation to the request:
$request['paymentwindow'] = [
'paymentmethods' => [
[
'id' => 'paymentcard',
'action' => 'include'
],
[
'id' => 'vipps',
'action' => 'include'
]
]
];
But, this seems to have no effect and no option for payment with Vipps is added to the payment window. What am I doing wrong?
Short answer: Vipps is only available in production account

Creating campaign for dynamic TextMerge segment fails

I'm trying to send a campaign to a dynamic list segment based on a custom numeric merge field (GMT_OFFSET, in this case) but the code below yields the following error from the MailChimp API:
"errors" => [
0 => [
"field" => "recipients.segment_opts.conditions.item:0"
"message" => "Data did not match any of the schemas described in anyOf."
]
]
My code, using drewm/mailchimp-api 2.4:
$campaign = $mc->post('campaigns', [
'recipients' => [
'list_id' => config('services.mailchimp.list_id'),
'segment_opts' => [
'conditions' => [
[
'condition_type' => 'TextMerge',
'field' => 'GMT_OFFSET',
'op' => 'is',
'value' => 2,
],
],
'match' => 'all',
],
],
],
// Cut for brevity
];
If I am to take the field description literally (see below), the TextMerge condition type only works on merge0 or EMAIL fields, which is ridiculous considering the Segment Type title says it is a "Text or Number Merge Field Segment". However, other people have reported the condition does work when applied exclusively to the EMAIL field. (API Reference)
I found this issue posted but unresolved on both DrewM's git repo (here) and SO (here) from January 2017. Hoping somebody has figured this out by now, or found a way around it.
Solved it! I passed an integer value which seemed to make sense given that my GMT_OFFSET merge field was of a Number type. MailChimp support said this probably caused the error and suggested I send a string instead. Works like a charm now.

Categories