PHP Variable of Stripe API [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I need help with PHP and the Stripe API.
$stripe->accountLinks->create([
'account' => 'acct_1HtKYcRm0s9vfiNs',
'refresh_url' => 'https://example.com/reauth',
'return_url' => 'https://example.com/return',
'type' => 'account_onboarding',
]);
That gives me back an answer like this:
{
"object": "account_link",
"created": 1606772720,
"expires_at": 1606773020,
"url": "https://connect.stripe.com/setup/s/QaVzgu7GNGFP"
}
I need help to know how to display the "url" in a variable in PHP.
I've tried to do this but it doesn't work:
$link = $stripe->accountLinks->create([
'account' => 'acct_1HtKYcRm0s9vfiNs',
'refresh_url' => 'https://example.com/reauth',
'return_url' => 'https://example.com/return',
'type' => 'account_onboarding',
]);
$data = json_decode($link);
$links = $data->url;
If someone knows what I can do it would help me a lot. Thanks :)
EDIT:
The var_dump returns this:
object(Stripe\AccountLink)#127 (4) { ["object"]=> string(12) "account_link" ["created"]=> int(1606856512) ["expires_at"]=> int(1606856812) ["url"]=> string(47) "https://connect.stripe.com/setup/c/vD45DxCl0hZQ" }
But I just need url string

You do not need to json_decode the resulting account link object. All you need to do is access the URL property on the object returned by Stripe. For example:
$link = $stripe->accountLinks->create([
'account' => 'acct_1HtKYcRm0s9vfiNs',
'refresh_url' => 'https://example.com/reauth',
'return_url' => 'https://example.com/return',
'type' => 'account_onboarding',
]);
$url = $link->url;
echo $url;
You can use the $url variable in a template or to perform any other server-side logic. The structure of the returned account link object can be referenced here:
https://stripe.com/docs/api/account_links/object

I've made it work by doing this:
$link = $stripe->accountLinks->create(
[
'account' => 'acct_1HtKYcRm0s9vfiNs',
'refresh_url' => 'https://example.com/reauth',
'return_url' => 'https://example.com/return',
'type' => 'account_onboarding',
]
);
$var_url = var_export($link->url, true);
$good_url = str_replace("'", "", $var_url);
Now when I echo "good_url" I get the full url successfully.
Thank you all very much, really, you have helped me a lot.

Related

How To Use External Class In YII2 Step By Step [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 4 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Improve this question
So i have a class i have used couple of times for other non YII projects but now i want to use the same class in a YII2 project. I have done some searches but i kind of got stuck along the way. Below is what i have done so far:
I created a folder called "utility" in the vendor directory, the utility folder contains my class named "AT_Response.class.php". So my question is how do i include or call and use this class in my model or controller.
I have checked some links like :
https://www.yiiframework.com/doc/guide/2.0/en/tutorial-yii-integration
https://forum.yiiframework.com/t/not-understanding-how-to-use-external-php-library/79679
Class Code:
<?php
class AT_Response {
static private $response = array
(
'9999' => array('description' => "Unexpected Response", 'definite' => true, 'status' => "Indeterminate"),
'00' => array('description' => "Success", 'definite' => true, 'status' => "Success"),
'NNC_AUTH_01' => array('description' => /*"Status unknown, please wait for settlement report"*/"System Error", 'definite' => true, 'status' => "Failure"),
'NNC_VTU_01' => array('description' => "Ttimed out", 'definite' => false, 'status' => "Indeterminate"),
'NNC_VTU_02' => array('description' => "Exceeded max number of requests for Phone number per time period", 'definite' => true, 'status' => "Failure"),
'NNC_VTU_03' => array('description' => "Invalid target MSISDN supplied", 'definite' => true, 'status' => "Failure"),
'-1' => array('description' => "Not successful", 'definite' => false, 'status' => "Failure"),
);
static function getResponseByCode($respCode) {
if (isset(self::$response[$respCode]))
return self::$response[$respCode];
//else
return self::$response['9999'];
}
}
Thanks
With a few changes you can use any custom class as a helper component. You need to use namespace and use statement for the existing class you have, see the below
<?php
namespace app\components;
class Response
{
/**
* #var array
*/
private static $response = array
(
'9999' => array('description' => "Unexpected Response", 'definite' => true, 'status' => "Indeterminate"),
'00' => array('description' => "Success", 'definite' => true, 'status' => "Success"),
'NNC_AUTH_01' => array('description' => /*"Status unknown, please wait for settlement report"*/"System Error", 'definite' => true, 'status' => "Failure"),
'NNC_VTU_01' => array('description' => "Ttimed out", 'definite' => false, 'status' => "Indeterminate"),
'NNC_VTU_02' => array('description' => "Exceeded max number of requests for Phone number per time period", 'definite' => true, 'status' => "Failure"),
'NNC_VTU_03' => array('description' => "Invalid target MSISDN supplied", 'definite' => true, 'status' => "Failure"),
'-1' => array('description' => "Not successful", 'definite' => false, 'status' => "Failure")
);
/**
* #param $respCode
*/
public static function getResponseByCode($respCode)
{
if (isset(self::$response[$respCode])) {
return self::$response[$respCode];
}
return self::$response['9999'];
}
}
Save the Above class in a file called Response.php in app\components folder if using basic-app or common\components if you are using advanced-app but dont forget to change the namespace in the code.
You can then call the function getResponseByCode() like app\components\Response::getResponseByCode($responseCode) or common\components\Response::getResponseByCode($responseCode)

remove elemets from array where value of daughter array is equal [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I have an array what consist of arrays. Have a looks into this file gist.
How you can see each array repeats two times. I need to delete the second, I need to compare them by 'key' value of array.
Thanks!
The easiest way to get the result you expect is in my opinion this way:
$data = array(
array(
'domain' => 'messages',
'key' => 'test.testik',
'message' => array()
),
array(
'domain' => 'messages',
'key' => 'test2313.tes31231tik',
'message' => array()
),
array(
'domain' => 'validators',
'key' => 'valid.validik',
'message' => array()
),
array(
'domain' => 'validators',
'key' => 'joga.jimbo',
'message' => array()
),
array(
'domain' => 'validators',
'key' => 'valid.validik',
'message' => array()
)
);
$newdata = array();
foreach ($data as $subdata) {
$newdata[$subdata['key']] = $subdata;
}
$newdata = array_values($newdata); // reset array indizes
print_r($newdata);
The undefined offset 6 error is telling you that there isnt an array element at position 6. Without seeing your error message and your code I cant tell you where the error is But you would need to see if the element exists using something like this:
if (isset($array[index]))
{
//do something
}
This will handle the error, meaning you wont get the message, but you should see why the element doesnt exist, like Was there a problem when the arrays were made.
Your error message will tell you which line the problem was on and therefore which array variables are causing these errors.
UPDATE:
your code will always return true as you are comparing a value to itself therefore it will be an empty array.
$transll['key'] == $transll['key']

Getting values depend on url [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have this array again:
$predmeti = [
'slo' => [
'ime' => 'Slovenščina',
'ucitelj' => 'Ana Berčon',
'nadimek' => '',
'ucilnica' => '11'
],
'mat' => [
'ime' => 'Matematika',
'ucitelj' => 'Nevenka Kunšič',
'nadimek' => '',
'ucilnica' => '12'
],
'ang' => [
'ime' => 'Angleščina',
'ucitelj' => 'Alenka Rozman',
'nadimek' => 'Rozi',
'ucilnica' => '3'
],
'mob' => [
'ime' => 'Medijsko oblikovanje',
'ucitelj' => 'Iztok Mulej',
'nadimek' => 'HTML ninja',
'ucilnica' => 'MM2'
]
];
I want to get values of every key depend on url I am accesing. For example I have url /predmet?ime=slo, then I want to get data only for key 'slo'.
How do I achieve that?
if(isset($_GET['ime']) && isset($predmeti[$_GET['ime']])){
$data = $predmeti[$_GET['ime']];
}
Use the parameter in the URL
<?php
$param = $_GET['ime'];
print_r($predmeti[$param]);
?>

PHP retrieve variable from file in OOP [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a config files which store variable like this:
<?php
return array(
'debug' => true,
'url' => 'http://localhost',
'timezone' => 'UTC',
'locale' => 'en',
);
How can I retrieve it in object oriented way from main file? Thank you.
I'm not quite sure what sort of answer you're expecting when you say "in an object oriented way", but the way I'd do it would be something like the following:
$config = include("configfile.php");
And then you can just access the values like so:
echo $config["timezone"]; //prints "UTC"
i am guessing you wanted to convert this array to an object if so then use this.
<?php
return (object) array(
'debug' => true,
'url' => 'http://localhost',
'timezone' => 'UTC',
'locale' => 'en',
);
in the other page do this:
$config = include("configfile.php");
echo $config->locale;
This is not really a OOP concept, rather a PHP concept
Simply include the file:
$config = include 'config.php';

PHP array in class generated in function [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I got a problem for a script I'm working on: I need the array that normaly gets generated in the query_person() function to be saved in protected static $users to be used across the script. This is just a quick test I made, normally the array gets generated by a query.
The script works if I do it like this:
protected static $users = array('paul' => array('p_gebruikersnaam' => "paul", 'p_wachtwoord' => "de3c41cc7918c25822f1fb840a86a84b", 'p_id' => "10000000", 'p_md5' => "d1ca3aaf52b41acd68ebb3bf69079bd1")
);
but since the array gets generated by a db query I had to put the query in a function but it doesn't work like this then:
protected static $users = array();
public function query_personen(){
$users = array('paul' => array('p_gebruikersnaam' => "paul", 'p_wachtwoord' => "de3c41cc7918c25822f140a86a84b", 'p_id' => "100000", 'p_md5' => "d1ca3aaf52b41acd68e9079bd1")
);
}
How do I make it work so that the second script generates the same output as the first?
public function query_personen(){
$this->users = array('paul' => array('p_gebruikersnaam' => "paul", 'p_wachtwoord' => "de3c41cc7918c25822f140a86a84b", 'p_id' => "100000", 'p_md5' => "d1ca3aaf52b41acd68e9079bd1")
);
You need to use $this to refer to the object.
If you want it to be static, you should use:
public static function query_personen(){
self::$users = array('paul' => array('p_gebruikersnaam' => "paul", 'p_wachtwoord' => "de3c41cc7918c25822f140a86a84b", 'p_id' => "100000", 'p_md5' => "d1ca3aaf52b41acd68e9079bd1")
);
Note that the second function is a static function (Yours in the example isn't so you should use the first version).

Categories