mailchimp add member returning status 400 member exists - mailchimp-api-v3.0

According to my understanding of mailchimp documentation, if one tries to add a member which already exists, it should return http status of 200, along with a member status of possible values: "subscribed", "unsubscribed", "cleaned", "pending", or "transactional".
However, I'm getting http status 400 with a "title" of "Member Exists".
With this behavior, I don't see a way to have dependable error handling code, since I don't think there is any guarantee that "title" strings are unmutable.
My PHP code creates params from form parameters as:
$params = array (
'email_address' => $email,
'status' => 'subscribed',
'merge_fields' => array (
'FNAME' => $first_name,
'LNAME' => $last_name,
...),
'tags' => $tags);
which are then JSON encoded and sent to mailchimp.
I'm testing with an email address that is already in the target list, in the "unsubscribed" state. The response from mailchimp is
(
[http_status] => 400
[response] => Array (
[title] => Member Exists
[status] => 400
[detail] => test1#kotatko.com is already a list member. Use PUT to insert or update list members.
[instance] => a9556e41-5e92-34bf-1ac6-1f7d35bca7f7
)
)
Why is it sending me http_status of 400 instead of 200 ?

I was having the same issue. For me the solution was converting the email string to lowercase before hashing it. Hope it helps!
Source: https://github.com/amro/gibbon/issues/239

Related

Laravel unique validation Ignore Rule for update

I have a name field on my Client model which must be unique. For the store method I have the following rules:
array (
'token' => 'string|max:250',
'directory' => 'max:250',
'name' => 'required|string|max:250|unique:clients',
)
For the update method, I have amended this ruleset to ignore the current ID to avoid a duplicate being identified:
$rules['name'] = $rules['name'] . ',id,' . $id;
This produces the following ruleset (for record ID 105):
array (
'token' => 'string|max:250',
'directory' => 'max:250',
'name' => 'required|string|max:250|unique:clients,id,105',
)
When the update method is executed, the The name has already been taken. response is returned during the validation.
I realise this is a well-discussed topic, but believe I am conforming to the correct approach. Can someone point out the error in my logic, please?
Note: This is running on Laravel 5.8.
array(
'token' => 'string|max:250',
'directory' => 'max:250',
'name' => [
'required', 'string', 'max:250',
\Illuminate\Validation\Rule::unique(Client::class, 'email')->ignore($this->id)
]
)

Indipay parameter missing exception

I am sending all the parameters required by indipay but still i am getting a parameter missing exception. If i send the static values then it is working fine.
$parameters = [
'purpose' => 'Application Fee for '.$regnId,
'buyer_name' => $request->s_fname.' '.$request->s_lname,
'amount' => env('APPLICATION_FEE'),
];
$order = Indipay::prepare($parameters);
return Indipay::process($order);
IndipayParametersMissingException in InstaMojoGateway.php line 119 at
InstaMojoGateway->checkParameters(array('redirect_url' =>
'http://127.0.0.1:8000/parent/response/indipay', 'purpose' =>
'Application Fee for GKB_19LKG_000019', 'buyer_name' => 'asdasd
asdasd', 'amount' => '200')) in InstaMojoGateway.php line 41
I finally found the answer.
The indipay package didn't gave the correct error. There was no parameter missing in the request. There was a max size issue in the validator function for the instamojo payment gateway.

Handling CodeIgniter form validation (rule keys and data types)

Okay, so I've been searching for a while this question, but couldn't find an answer (or at least some direct one) that explains this to me.
I've been using CodeIgniter 3.x Form Validation library, so I have some data like this:
// Just example data
$input_data = [
'id' => 1,
'logged_in' => TRUE,
'username' => 'alejandroivan'
];
Then, when I want to validate it, I use:
$this->form_validation->set_data($input_data);
$this->form_validation->set_rules([
[
'field' => 'id',
'label' => 'The ID to work on',
'rules' => 'required|min_length[1]|is_natural_no_zero'
],
[
'field' => 'username',
'label' => 'The username',
'rules' => 'required|min_length[1]|alpha_numeric|strtolower'
],
[
'field' => 'logged_in',
'label' => 'The login status of the user',
'rules' => 'required|in_list[0,1]'
]
]);
if ( $this->form_validation->run() === FALSE ) { /* failed */ }
So I have some questions here:
Is the label key really necessary? I'm not using the Form Validation auto-generated error messages in any way, I just want to know if the data passed validation or not. Will something else fail if I just omit it? As this will be a JSON API, I don't really want to print the description of the field, just a static error that I have already defined.
In the username field of my example, will the required rule check length? In other words, is min_length optional in this case? The same question for alpha_numeric... is the empty string considered alpha numeric?
In the logged_in field (which is boolean), how do I check for TRUE or FALSE? Would in_list[0,1] be sufficient? Should I include required too? Is there something like is_boolean?
Thank you in advance.
The "label" key is necessary, but it can be empty.
The "required" rule does not check length, nor does the "alpha_numeric". It checks that a value is present, it does not check the length of said value. For that, there is min_length[] and max_length[].
If you're only passing a 0 or 1, then this is probably the easiest and shortest route.

receive more response data in ci-merchant library codeigniter

How can I receive more response data in the ci-merchant codeigniter library ?
I am using the Paypal Express checkout payment method.
And I am passing the following parameters:
$params = array(
'amount' => 100.00,
'currency' => 'USD',
'return_url' => my return url,
'cancel_url' => my cancel url );
Right now am getting just the following response
Merchant_paypal_api_response Object
(
[_status:protected] => complete
[_message:protected] =>
[_reference:protected] => 1K088384XU0947545
[_data:protected] =>
[_redirect_url:protected] =>
[_redirect_method:protected] => GET
[_redirect_message:protected] =>
[_redirect_data:protected] =>
)
How can I get the data like paypal id, shipping address, item name and other stuff that paypal returns in the DoExpressCheckoutPayment response ?
Actually, that info wouldn't come back in the DECP response. It would come back in GetExpressCheckoutDetails.
Your library should provide some way to see the RAW API requests and responses. If it's not parsing out all of the details for you you'll need to do that on your own.
This isn't exactly an answer to your question, but you should try using Omnipay instead. Omnipay is basically CI-Merchant V2 (I'm the author of both libraries).
Omnipay lets you have direct access to the raw response. E.g. you would do something like this:
$params = array( 'amount' => 1000, 'currency' => 'USD', 'returnUrl' => 'my return url', 'cancelUrl' => 'my cancel url' );
$response = $gateway->completePurchase($params)->send();
$reference = $response->getTransactionReference(); // paypal transaction id
$data = $response->getData(); // this is the raw response object

CakePHP - Validation rule 'last' not working

I have two custom validation rules (I have tested they work correctly):
class PasswordResetKey extends AppModel {
public $validate = array(
'timestamp' => array(
'rule' => '_notExpired',
'message' => 'Your password reset link has expired. Please request another one.',
'last' => true
),
'key' => array(
'rule' => '_validFormat',
'message' => 'You do not appear to have used a valid password reset link. Please request another one.'
)
);
But no matter what I do, the errors returned are always:
Array
(
[key] => You do not appear to have used a valid password reset link. Please request another one.
[timestamp] => Your password reset link has expired. Please request another one.
)
Even when I check that the timestamp rule fails, it still goes on and checks the other rule for 'key' as well. I only want the timestamp error if it is there.
last is for multi rules per field. due to the fact that you only have one rule per field its always last and thus pointless.
My intuition says _notExpired should not fire if the reset link is wrong. I would have that rule raise a flag only if the link is correct but expired.

Resources