Stripe checkout wont accept metadata - php

I have integrated Stripe checkout (the latest version) and need to send additional data so I can reconcile a later webhook.
Stripe rejects the metadata with the following error
Fatal error: Uncaught exception 'Stripe\Error\InvalidRequest' with message 'Received unknown parameter: metadata'
My partially redacted code looks like this
$object = \Stripe\Checkout\Session::create([
'success_url' => 'www/payment_processor.php?action=success',
'cancel_url' => 'www/payment_processor.php?action=cancel',
'payment_method_types' => ['card'],
'customer_email' => $email,
'metadata' => ['user_id' => $user_id],
'line_items' => [[
'amount' => $amount,
'currency' => $currency,
'name' => 'Purchase',
'description' => $description,
'quantity' => 1,
]]
]);
I expect the metadata to be accepted and returned with the webhook, as described in the Stripe documentation.

For anyone still coming across this issue, simply placing a client_reference_id or metadata parameter did not work for me even with the 2020-08-27 API.
Adding payment_intent_data with metadata is what got it to work for me. You can try adding the following code:
'payment_intent_data'=>['metadata' => ["order_id" => $orderID, "type" => "myProduct"],

You can do this
stripe.checkout.sessions.create({
payment_intent_data: {
application_fee_amount: this.booking_fee,
metadata: {
key1 : value1,
key2 : value2,
.
.
key N : value N
}
}
})

First sentence of the linked documentation states:
Updateable Stripe objects—including Account, Charge, Customer, PaymentIntent, Refund, Subscription, and Transfer —have a metadata parameter.
You are creating neither of those, you are creating a Session
Update
As Oliver Dixon pointed out, Stripe Sessions now do have a meta data property (although they are still not stated in the meta data article)

You cannot attach metadata to a Session, but you can attach metadata to either the payment_intent or setup_intent that will be created in the session.
See the documentation, you pass it as payment_intent_data.metadata.
Note that Stripe warns you not to put sensitive data in metadata, so if you want to store a client name etc, you're better off putting it in a database under a unique key and then pass the key as client_reference_id.

As of October 2020 the session object has metadata.

The other answers are correct that metadata doesn't exist on the Session object. client_reference_id is an alternative but it has to be unique and it must be a string.
If you just want metadata to show up on the purchase in the Stripe Dashboard, use the payment_intent_data attribute when creating your session. That's how you attach metadata to a purchase made during a session. Relevant documentation here.

The Stripe Session object does not accept metadata as a parameter. See here for the details.
The reference you give in your question is for a Stripe Charge object which does accept metadata.

If you are like me and came across the need to bundle some information for example customer id, order id etc, across over to stripe. There's a parameter called payment_intent_data which is an associative array. Within payment_intent_data you have a property called description which you can use to embed some extra information. The description you put here will show up on the description field when you do a csv payment export on stripe.
https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-payment_intent_data-description
$stripe_session = \Stripe\Checkout\Session::create([
'submit_type' => 'pay',
'billing_address_collection' => 'required',
'customer' => $customer,
'client_reference_id' => $customer ,
'payment_intent_data'=>['description' =>'This is my description'],
'payment_method_types' => ['card'],
'line_items' => [[
'name' => $event->title,
'description' => $description/*This description does not go on csv export, it's more or less cosmetic */,
'amount' => ($fee),
'currency' => 'gbp',
'quantity' => 1,
]],
'success_url' => 'example.com',
'cancel_url' => 'example.com',
]);

Metadata must be nested in the Session creation object:
Stripe's docs incorrectly list metadata as a parent (https://stripe.com/docs/api/checkout/sessions/create) when in fact it's a child:
https://support.stripe.com/questions/using-metadata-with-checkout-sessions
payment_intent_data.metadata
subscription_data.metadata
client_reference_id is associated with the Session only, and does not get stored in Stripe as metadata.

Related

PHP Paypal Checkout SDK V2 -- what are the possible values for "purchase_units"?

We are building a Paypal PHP V2 checkout and the documentation on the github doesn't show what the possible expected data is for the purchase_units. Paypal in their wisdom have also turned off issue tracking.
Github: https://github.com/paypal/Checkout-PHP-SDK
Code exampled by Paypal:
Creating an Order
// Construct a request object and set desired parameters
// Here, OrdersCreateRequest() creates a POST request to /v2/checkout/orders
use PayPalCheckoutSdk\Orders\OrdersCreateRequest;
$request = new OrdersCreateRequest();
$request->prefer('return=representation');
$request->body = [
"intent" => "CAPTURE",
"purchase_units" => [[
"reference_id" => "test_ref_id1",
"amount" => [
"value" => "100.00",
"currency_code" => "USD"
]
]],
"application_context" => [
"cancel_url" => "https://example.com/cancel",
"return_url" => "https://example.com/return"
]
];
This is fine, but we can't find any documentation as to what values can or should be given in "purchase_units" (or any other fields in this data set) array.
Paypal's own documentation itself for "purchase_units" links to here:
https://developer.paypal.com/docs/api/orders/v2/#definition-model-update_purchase_unit_request
which states:
model-update_purchase_unit_request
reference_id string required
The API caller-provided external ID for the purchase unit.
Minimum length: 1.
Maximum length: 256.
payments object required
The comprehensive summary of payments for the purchase unit.
Which is either incomplete or referencing something else (there is no payments object on the exampled code).
We are looking to establish what other fields can be given in purchase_units and if the reference_id is a Paypal reference or something on our servers we generate (such as a database order row, etc.) . I would assume the reference_id is something we generate ourselves but as there's so little documentation from Paypal this doesn't appear to be actually clarified anywhere.
Questions:
What fields can we use in the "purchase_units" request body
How can we add shipping on to this order creation?
And as a bonus, where is there any reliable and unarchived Paypal documentation on this?
Thank you.
I would assume the reference_id is something we generate ourselves
Yes, that appears to be the case.
If you look under https://developer.paypal.com/docs/api/orders/v2/#definition-purchase_unit, there it says,
reference_id - string - The API caller-provided external ID for the purchase unit.
So you, as the caller of the API, have to provide this ID.

SimpleSAMLPHP bind via POST

Our current SAML setup has been working just fine with the more or less default setup provided by the library SimpleSAMLPHP. However, one new IDP specifically needs to bind to the SP via a POST binding.
It seems like SimpleSAMLPHP will always redirect to the IDP using a GET request, as can be clearly seen here for example:
There also seems to be no distinct configuration setting which controls this.
We have tried to play with the NameID Policy settings with no success. The SP lists the following NameID Policy in their metadata:
urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST
Our own NameID Policy is as follows:
urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified
Any tip here will really be highly appreciated
You want the IdP's metadata to have a urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST binding for SingleSignOnService and have that binding be listed first in the list of SingleSignOnService options supported. This is often in the file metadata/saml20-idp-remote.php. This is different from NameId and from the AssertionConsumerService SP bindings with the same binding name. Your SP will pick the first SingleSignOnService option listed for the IdP in the IdP's metadata.
$metadata['https://some.idp.co'] = array (
'entityid' => 'https://some.idp.co',
'metadata-set' => 'saml20-idp-remote',
'SingleSignOnService' =>
array (
0 =>
array (
'Binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST',
'Location' => 'https://some.idp.co/idp/profile/SAML2/POST/SSO',
),
1 =>
array (
'other options, etc'
),
),

Adding Product Bundle and variation child to Order/Cart using add_bundle_to_order()

I'm trying to add a Product Bundle to an Order (or a Cart, add_bundle_to_cart uses the same args). The Bundle has several child products, all of which have variations. The args I need to be providing according to the documentation are:
$args = array(
81 => array(
'product_id' => 1543,
'quantity' => 3,
),
84 => array(
'product_id' => 1386,
'quantity' => 1,
'variation_id' => 3535,
'attributes' => array(
'attribute_pa_attribute-1' => 'value-1b',
'attribute_pa_attribute-2' => 'value-2b',
),
)
);
Where the second bundled product (84) is a variable product. My issue: I cannot verify whether the values I am providing for the 'attributes' array are correct.
My attribute is named 'Servings' and there are two options - '2 People' and '4 People'. I am not sure how to format the attribute name to replace 'attribute_pa_attribute-1'. I have tried 'servings', 'attribute_pa_servings', etc. If I return the variation information for the product it gives me: 'attribute_servings' as the name and '2 People' as the value. But that doesn't seem to work either.
I am not getting any errors returned in debug.log, and I cannot find any examples of someone using this in the land of Google.
If anyone has any experience with this, I would greatly appreciate a tip as to what I am doing wrong.
Many thanks.
I came to realise there are two different types of 'attributes' in Woo: global attributes (across all products), and local attributes (specific to one product). The quoted instructions from the documentation are referring to how to reference global attributes - I am using local ones. So that is why the terms weren't working.
General overview here.
Information on the syntax between the two here.

Mailchimp grouping doesn't seem to work

I am trying to implement an opt-in on a website to add a newly registered user to a mailing list on Mailchimp. This user can either be an individual or a business client and has to be in different groups.
Now what I've done is, I created 1 list with 1 group and in that group I created 2 subgroups(?)
Like there's a group title and there's groupings underneath. Now I try to use the API Wrapper provided over here: https://github.com/drewm/mailchimp-api/ and used this method for the API request:
$r = $mailchimp->call('lists/subscribe', array(
'id' => 'REMOVED_ID',
'email' => array(
'email' => 'REMOVED_EMAIL'
),
'merge_vars' => array(
'groupings' => array(
'id' => REMOVED_ID,
'groups' => array('REMOVED_NAME')
)
)
));
For obvious reasons I've replaced the actual values with placeholders.
What happens is: The user with the opt-in gets a email asking for their confirmation, and then the email adres gets added to the list but they're not in any groups.
Am I doing something wrong or am I being impatient?
I've found out what the problem is for this particulair problem. The JSON produced by the MailChimp class looks like this:
{"id":"ID_REMOVED","email":{"email":"EMAIL_REMOVED"},"merge_vars":{"FNAME":"Captain","LNAME":"Jack","groupings":{"id":ID_REMOVED,"groups":["GROUP_NAME_REMOVED"]}},"apikey":"API_KEY_REMOVED"}
But it should have [] around the groupings like so:
"groupings":[{"id":ID_REMOVED,"groups":["GROUP_NAME_REMOVED"]}]
Now I don't know how to achieve this, but for future reference, this is what caused my problem

Destroy a specific session in codeigniter

I have a codeigniter application that I am using the Cart class to make an e-commerce store.
I am also using Codeigniter-Auth (a library) to make accounts on this system. I have noticed when I log out while testing the application, the session data for the shopping cart is also destroyed.
I noticed in the library this is how it logs the users in:
$data = array(
'id' => $row->id,
'name' => $row->name,
'email' => $row->email,
'loggedin' => TRUE
);
$this->CI->session->set_userdata($data);
And this is how it logs the user out:
return $this->CI->session->sess_destroy();
How do I tell codeigniter to only destroy the user session and not every session in the system?
Using:
$data = array(
'id' => $row->id,
'name' => $row->name,
'email' => $row->email,
'loggedin' => TRUE
);
$this->session->set_userdata($data); // instead of $this->CI->session->set_userdata($data);
You are actually setting 4 session variables! To unset a specific one, use:
$this->session->unset_userdata('loggedin');
I believe you can just use $this to refer to CodeIgniter's instance. You must also assign a "name" to your session data (variable) to be able to specifically unset it.
$this->session->set_userdata('sample_userlog',$data);
$this->session->unset_userdata('sample_userlog');
Hope this helps.
The documentation states to clear the current session use
$this->session->sess_destroy();
Note: This function should be the last one called, and even flash variables will no longer be available. If you only want some items destroyed and not all, use unset_userdata().
For example $this->CI->session->unset_userdata($data).

Categories