Skip to content

Add verification_document_id handling to StripeAccountController#581

Merged
joshsmith merged 1 commit intodevelopfrom
file_upload_controller
Dec 22, 2016
Merged

Add verification_document_id handling to StripeAccountController#581
joshsmith merged 1 commit intodevelopfrom
file_upload_controller

Conversation

@joshsmith
Copy link
Contributor

@joshsmith joshsmith commented Dec 17, 2016

What's in this PR?

WIP PR for @snewcomer.

Fixes #570 when done.


defp handle_create_result({:error, %Ecto.Changeset{} = changeset}, _conn), do: changeset
defp handle_create_result({:ok, %StripeFileUpload{}} = result, conn) do
result |> CodeCorps.Analytics.Segment.track(:created, conn)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tracking this is a good idea, I think!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you were asking about the error. I don't think we'll track that.

Converts a map received from the Stripe API into a map that can be used
to create a `CodeCorps.StripeFileUpload` record
"""
@stripe_attributes [:file, :purpose, :id]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to pull in all of Stripe's attributes for the file upload here:

{
  "id": "file_19RAITKUlS7mA39fpztNbjpd",
  "object": "file_upload",
  "created": 1481850845,
  "purpose": "identity_document",
  "size": 238253,
  "type": "jpg"
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this would mean id, created, purpose, size, and type (not object).

@joshsmith
Copy link
Contributor Author

To fix the error on Circle, you'll need to create an app/lib/code_corps/stripe_testing/file_upload.ex file similar to the other files there. That's just a mock, and you can use the example JSON I provided above.

{:ok, result}
end

@non_stripe_attributes ["project_id"]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be stripe_connect_account_id.

@joshsmith
Copy link
Contributor Author

joshsmith commented Dec 17, 2016

Unfortunately, Stripe's documentation was really unclear on the fact that you can upload files via the browser.

This PR is going to change to the following:

StripeAccountController:

  • PUT with a verification_document_id
  • Pattern match against the verification_document_id in handle_update
  • handle_update will call StripeAccountService.add_verification_document()

StripeAccountService.add_verification_document()

with

  • Pattern match against the verification_document_id and the Stripe Account information
  • Use verification_document_id to fetch the file with Stripe.FileUpload.retrieve (to ensure proper secure data coming from the client)
  • Call Stripe.Account.update with verification[document] set to the id from %Stripe.FileUpload{}

do

Inside a transaction:

  • Use the returned %Stripe.FileUpload{} to insert a %CodeCorps.FileUpload{}
  • Use the returned %Stripe.Account{} to update our %CodeCorps.StripeAccount{}

Additional changes

We're going to need to:

  • Remove the StripeFileUploadController and its test, along with the line from the router

Sorry about these changes @snewcomer. Wish I had caught this earlier since it would have saved lots of hours for many people involved.

@joshsmith joshsmith changed the title [FILE UPLOAD CONTROLLER] WIP Add verification_document_id handling to StripeAccountController Dec 18, 2016
@@ -0,0 +1,30 @@
defmodule CodeCorps.StripeFileUploadControllerTest do
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file needs deleted.

@@ -0,0 +1,21 @@
defmodule CodeCorps.StripeFileUploadController do
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file needs deleted.

web/router.ex Outdated
resources "/stripe-connect-accounts", StripeConnectAccountController, only: [:show, :create]
resources "/stripe-connect-plans", StripeConnectPlanController, only: [:show, :create]
resources "/stripe-connect-subscriptions", StripeConnectSubscriptionController, only: [:show, :create]
resources "/stripe-file-uploads", StripeFileUploadController, only: [:create]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line needs deleted.


@api Application.get_env(:code_corps, :stripe)

def create(%{"file" => file, "purpose" => purpose, "stripe_connect_account_id" => stripe_connect_account_id} = attributes) do
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll remove create and replace with retrieve.

@joshsmith
Copy link
Contributor Author

This is partly blocked by #572 now. Can be resolved by creating a mock for the update in StripeTesting.


def add_vertification_document(%{"verification_document_id" => verification_document_id, "stripe_connect_account" => connect_account} = attributes) do
with {:ok, %Stripe.FileUpload{} = file} <- Stripe.FileUpload.retrieve(verification_document_id),
{:ok, %Stripe.Account{} = account} <- Stripe.Account.update(%{verification_document_id: file.id})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stripe.FileUpload => @api.FileUpload

Stripe.Account => @api.Account

|> CodeCorps.StripeAccount.update

file_upload
|> CodeCorps.FileUpload.create_identity_document_changeset
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume you're looping back but both these should be wrapped in a transaction.

@joshsmith joshsmith removed the blocked label Dec 20, 2016
@joshsmith
Copy link
Contributor Author

No longer blocked.

@begedin
Copy link
Contributor

begedin commented Dec 20, 2016

@joshsmith This PR seems to mostly be dealing with the file upload controller. I'll implement adding a verification_document_id to a StripeConnectAccount in a separate PR. I think it will be simpler that way.

@begedin
Copy link
Contributor

begedin commented Dec 20, 2016

Was a bit too quick with the previous comment. Quick glance had me thinking the file upload controller is still what's the focus of the PR.

I see that this part has been cleaned up somewhat. I'll just take over from this pr @snewcomer. Hope you don't mind. Good work so far.

@begedin begedin self-assigned this Dec 20, 2016
@begedin begedin force-pushed the file_upload_controller branch 2 times, most recently from 16f7be5 to c1395c5 Compare December 20, 2016 17:30
@begedin
Copy link
Contributor

begedin commented Dec 21, 2016

@joshsmith I renamed the document id field to legal_entity_verification_document to accomodate changes made in #588.

#588 should be merged first, then conflicts created by that resolved here. Until then, we should consider it blocked.

@begedin begedin modified the milestone: Launch Donations Dec 21, 2016
@joshsmith joshsmith force-pushed the file_upload_controller branch from 5d37d90 to 0868928 Compare December 22, 2016 00:09
@joshsmith joshsmith force-pushed the file_upload_controller branch from 0868928 to 4c57465 Compare December 22, 2016 00:11
@joshsmith joshsmith merged commit 65488b4 into develop Dec 22, 2016
@joshsmith joshsmith deleted the file_upload_controller branch December 22, 2016 00:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants