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.
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.
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
It's relatively easy to create a new instance using PHP by using the runInstances() method.
$instance = $ec2->runInstances(array(
'ImageId' => AMI_ID, // AMI ID
'InstanceType' => AMI_TYPE, // m1.medium etc.
'MinCount' => 1, // Minimum to create
'MaxCount' => 1, // Maximum to create
'SecurityGroups' => SEC_NAME, // Security Group Name
'KeyName' => KEY_NAME // Key Pair to use
))->toArray(); // Get back our data in an array
However, the point of the API is to be able to do everything you can do with the front-end on the amazon website, in a tenth of the time and with your own code.
With that in mind, I need to do the following:
On the front-end, I can change the Volume Size to, say, 40GB.
How can I ask for a 40GB Volume Size when creating a new Instance with PHP? It could even be run after the instance is created, as long as it's automatic - I should be able to do this programatically.
How can I achieve what I require using the AWS SDK for PHP 2?
It looks like you're on the right track. In the documentation for runInstances(), there is a parameter BlockDeviceMappings that contains another parameter Ebs that contains the paramenter you're looking for VolumeSize. This is untested code.
$instance = $ec2->runInstances(array(
'ImageId' => AMI_ID, // AMI ID
'InstanceType' => AMI_TYPE, // m1.medium etc.
'MinCount' => 1, // Minimum to create
'MaxCount' => 1, // Maximum to create
'SecurityGroups' => SEC_NAME, // Security Group Name
'KeyName' => KEY_NAME, // Key Pair to use
'BlockDeviceMappings' => array( // How block devices are mapped to instance
array(
'Ebs' => array( // EBS Volume Info
array(
'VolumeSize' => 40 // Volume Size
)
)
)
)
))->toArray(); // Get back our data in an array
This is no different than how is done using the command line tools. First you need to figure out the snapshot ID of the AMI you will be launching. You do this by querying the properties of the AMI. One of the values returned is the snapshot ID. Then you use that ID to run the instance by specifying the snapshot ID you will use and also the size.
The documentation here : http://docs.aws.amazon.com/AWSSDKforPHP/latest/index.html#m=AmazonEC2/run_instances
explains this needs to be passed with the BlockDeviceMapping array. Then within that array you need to use 'Ebs' and specify the SnapshotId and VolumeSize.
If you pass all those parameters in the runinstance call it will launch with your desired size.
i'm searching for a solution to solve the following problem in zf2:
i have a list of destinations, and i want a search-formular on my page with auto-completion.
also the list is used to translate parts of my web-page, so i will use zend_translate to do this.
it it possible to "reverse-search" the list of translations with zend_translate?
Example:
$translate->getKeysByExpression('*ger*');
result:
array (
array ( 'key' => '__germany__', 'name' => 'germany'),
array ( 'key' => '__trn_landwithger__', 'name' => 'landwithger'
)
it is not the biggest problem if i have to load the complete list of translations, it is not that much.
or is it better to use mongodb as backend for zend_translate, and use direct queries to find the completion-candidates?