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

Support creating a card token #61

Closed
azzamsa opened this issue Jun 10, 2021 · 3 comments · Fixed by #97
Closed

Support creating a card token #61

azzamsa opened this issue Jun 10, 2021 · 3 comments · Fixed by #97

Comments

@azzamsa
Copy link
Contributor

azzamsa commented Jun 10, 2021

I make a new issue to avoid spamming the subscriber in #32.

Could you please elaborate more ?

Based on my understanding, The path is:

  1. fetching stripe open API spec from https://github.com/stripe/openapi/tree/master/openapi
  2. feed it to async-stripe/openapi/
  3. async-stripe/openapi/ will parse the openapi and write the generated Rust code into out directory.
  4. copy the directory into ``async-stripe/src/resources/generated/`

At first I thought it was something like this:

modified   src/resources/generated/token.rs
@@ -99,6 +99,10 @@ pub struct CreateToken<'a> {
     /// The PII this token will represent.
     #[serde(skip_serializing_if = "Option::is_none")]
     pub pii: Option<CreateTokenPii>,
+
+    /// The Card this token will represent.
+    #[serde(skip_serializing_if = "Option::is_none")]
+    pub card: Option<CreateTokenCard>,
 }
 
 impl<'a> CreateToken<'a> {
@@ -110,6 +114,7 @@ impl<'a> CreateToken<'a> {
             expand: Default::default(),
             person: Default::default(),
             pii: Default::default(),
+            card: Default::default(),
         }
     }
 }
@@ -206,6 +211,14 @@ pub struct CreateTokenPii {
     pub id_number: Option<String>,
 }
 
+#[derive(Clone, Debug, Deserialize, Serialize)]
+pub struct CreateTokenCard {
+    #[serde(skip_serializing_if = "Option::is_none")]
+    pub number: Option<i64>,
+    pub exp_month: Option<i32>,
+    pub exp_year: Option<i32>,
+}
+

But I realized it will be overidden by code generation, so is it someting like this:

modified   openapi/src/mappings.rs
@@ -578,6 +578,11 @@ pub fn field_mappings() -> FieldMap {
             ("create_payment_method", "billing_details"),
             ("BillingDetails", "Option<BillingDetails>"),
         ),
+
+        (("create_token_card", "exp_month"), ("Card", "Option<Card>")),
+        (("create_token_card", "exp_year"), ("Card", "Option<Card>")),
+        (("create_token_card", "number"), ("Card", "Option<Card>")),
+
         (("transfer_schedule_params", "delay_days"), ("DelayDays", "Option<DelayDays>")),
         (("transfer_schedule_params", "weekly_anchor"), ("Weekday", "Option<Weekday>")),
         (("create_webhook_endpoint", "api_version"), ("ApiVersion", "Option<ApiVersion>")),

I tried to search for a PR that adds a new feature for me to follow. I want to know what parts need to be changed. Unfortunately, I can't find it. I also checked the git blame, but no still no clue.

after adding the line above (in mapping.rs) I run openapi-install, but I don't see card token addition in src/resources/generated/token.rs. So I must be missing something.

@arlyon
Copy link
Owner

arlyon commented Jun 15, 2021

Sorry for the delayed response, I am in the process of moving atm. I will make some time tomorrow to see if I can get you some pointers. Thanks for the interest in this project :)

@seanpianka
Copy link
Contributor

From the linked PR in the parent thread, it seems like this API is deprecated in favor of payment intents: #44 (comment)

@arlyon
Copy link
Owner

arlyon commented Oct 8, 2021

Thanks for the input Sean, I agree that the official guidance should be to use the PaymentIntent API. I will put a note of this in the docs as this has appeared a few times.

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

Successfully merging a pull request may close this issue.

3 participants