-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into payment-intent
- Loading branch information
Showing
28 changed files
with
277 additions
and
317 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,28 @@ | ||
defmodule StripeMock.API.Operations.Token do | ||
import Ecto.Query | ||
|
||
alias Ecto.Multi | ||
alias StripeMock.Repo | ||
alias StripeMock.API.Token | ||
alias StripeMock.API.{Token, Source} | ||
|
||
def get_token(id) do | ||
Repo.fetch(Token, id) | ||
Token | ||
|> preload(:card) | ||
|> Repo.fetch(id) | ||
end | ||
|
||
def create_token(attrs) do | ||
%Token{} | ||
|> Token.changeset(attrs) | ||
|> Repo.insert() | ||
Multi.new() | ||
|> Multi.insert(:token, Token.changeset(%Token{}, attrs)) | ||
|> Multi.run(:source, fn _repo, %{token: token} -> | ||
%Source{} | ||
|> Source.changeset(%{token_id: token.id}) | ||
|> Repo.insert() | ||
end) | ||
|> Repo.transaction() | ||
|> case do | ||
{:ok, %{token: token}} -> {:ok, token} | ||
{:error, _, value, _} -> {:error, value} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
defmodule StripeMock.API.Source do | ||
use StripeMock.Schema | ||
|
||
schema "sources" do | ||
belongs_to :card, API.Card | ||
belongs_to :token, API.Card | ||
end | ||
|
||
@doc false | ||
def changeset(token, attrs) do | ||
token | ||
|> cast(attrs, [:card_id, :token_id]) | ||
end | ||
end |
Oops, something went wrong.