Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Account Person, how to create ? #154

Open
aldebaranzbradaradjan opened this issue Dec 10, 2020 · 0 comments
Open

Account Person, how to create ? #154

aldebaranzbradaradjan opened this issue Dec 10, 2020 · 0 comments

Comments

@aldebaranzbradaradjan
Copy link

aldebaranzbradaradjan commented Dec 10, 2020

Hi guys !

I follow this guide to create connected account : https://stripe.com/docs/connect/account-tokens (i'm french, must use account_id method) and it show the use of create person.
I've been trying for a while now to create a person (https://stripe.com/docs/api/persons/create).
I just don't understand how to do this, I'm just starting stripe;

I use this code to create account :

// Create a connected account
let mut params = stripe::CreateAccount::new();
params.type_ = Some(stripe::AccountType::Custom);
params.requested_capabilities = Some (
    vec![
        stripe::RequestedCapability::CardPayments,
        stripe::RequestedCapability::Transfers,
    ]
);
params.country = Some("FR");
params.account_token = Some("ct_1Hwl4gHMKCJ5sXRrmJvYNJTQ");
    
let account = stripe::Account::create(&client, params).unwrap();
println!( "Create Account :\n\n{:#?}\n\n", account );

But I'm blocked with the person part.
The account have a individual part, should use that ?
In the stripe doc, the Go implementation use PersonParams to achieve that, we have PersonParams in this lib, should use that ?
Go example :

// Set your secret key. Remember to switch to your live secret key in production!
// See your keys here: https://dashboard.stripe.com/account/apikeys
stripe.Key = "sk_test_nkieGSlT2YjYFPw"

token := r.FormValue("token-person")

params := &stripe.PersonParams{
  Account: stripe.String("{{CONNECTED_ACCOUNT_ID}}"), // id of the account created earlier,
  PersonToken: stripe.String(token),
}
per, _ := person.New(params)

So I have try.
I have understand how to impersonate an account, with the header. But the PersonParams seems differents from go version, I don't know what to provide for metadata :

// ----------------------------------------------------------------------------------
// impersonate the client
let mut headers = stripe::Headers::default();
headers.stripe_account = Some( account.id.to_string() );
let client = client.with_headers(headers);

// Then, all requests can be made normally
let mut params = stripe::PersonParams {
    metadata : stripe::Metadata
}

Pretty certain I'm simply going down the wrong path, so in short, any example would be highly appreciated. Or maybe the feature is missing ? I was initially searching for a CreatePerson struct.

Thanks.


After some pain, I have figure how to send custom request to stripe, see my implementation :

#[derive(Serialize)]
struct CreatePerson {
    pub person_token: String,
}

#[derive(Deserialize, Debug)]
struct CreatePersonResponse {
        id: String,
        account: String,
}

fn attach_person( client : &stripe::Client, account_id : String, person_id: String ) -> stripe::Response<CreatePersonResponse> {
    client.post_form(
        &format!("accounts/{}/persons", account_id ),
        CreatePerson { person_token : person_id } 
    )
}

...
let person = attach_person(&client, account.id.to_string(), "cpt_1HwxXsHMKCJ5sXRrcJBuH0UF".into());
...

It's little dirty, but it's work. Accordingly to the code base, I imagine we should add a person_ext.rs file in resource to implement this properly. I will see if I can write something like that, It seems complicated at first glance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant