1

I am currently working on a WordPress/Woocomerce project I am trying to write a plugin which calls the stripe API using the following method

$stripe = new \Stripe\StripeClient('apikey');

$stripe->charges->create([
  'amount' => 1500,
  'currency' => 'gbp',
  'source' => 'accountid',
]); 
}

This API returns an object containing information regarding the call for example

"id": "callid",
"object": "payment_intent",
"amount":43650,
"amount_capturable":0,

I want to assign this ID in the return object to a local variable. How can I achieve this ? I am a .net developer and my PHP skills are limited I need the simple as possible solution.

Thank you.

2
  • Do you want to store the id from the object as a seperate variable of just simply call it when you need it? It will be redundant copying the value to a new variable if you can just simply call it from the object Commented Jan 14 at 23:15
  • I want to store the id from the object as a separate variable. Right now I just want it in a local variable but will be doing other stuff with it once I solve this problem. Commented Jan 14 at 23:18

1 Answer 1

1

After confirming the response is 200 and contains the “id” in the your response object, you can simply call the property ‘id’ on the object to get the value of id and save it to a new variable as below.

$response = $stripe->charges->create([
    'amount' => 1500,
    'currency' => 'gbp',
    'source' => 'accountid',
]); 

/* 
   Confirm response status is 200 and 
   response has id field before proceeding
*/

$id = $response->id;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.