Skip to content

Commit

Permalink
add payer information
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel-rubio committed Dec 15, 2024
1 parent 0d3c177 commit 835f46e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/paypal/order/info.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ defmodule Paypal.Order.Info do

alias Paypal.Common.Link
alias Paypal.Order
alias Paypal.Order.Payer
alias Paypal.Order.PurchaseUnit

@primary_key false
Expand All @@ -27,6 +28,7 @@ defmodule Paypal.Order.Info do
embeds_many(:links, Link)
embeds_many(:purchase_units, PurchaseUnit)
field(:status, Ecto.Enum, values: Order.statuses())
embeds_one(:payer, Payer)
end

@doc false
Expand Down
21 changes: 21 additions & 0 deletions lib/paypal/order/payer.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
defmodule Paypal.Order.Payer do
@moduledoc """
Payer get all the information about who's paying the order.
"""
use TypedEctoSchema

@primary_key false

@typedoc """
The information for the payer:
- `payer_id` is the ID in Paypal for the payer.
- `name` is a composition of two values: given_name and surname.
- `email_address` is the email address provided to Paypal for the payment.
"""
typed_embedded_schema do
field(:payer_id, :string, primary_key: true)
field(:name, :map)
field(:email_address, :string)
end
end
17 changes: 16 additions & 1 deletion test/integration_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ defmodule Paypal.IntegrationTest do
method: :post
}
],
payer: %Paypal.Order.Payer{
payer_id: "JWEUL3HMBVGJ6",
name: %{"given_name" => "test", "surname" => "buyer"},
email_address: "[email protected]"
},
purchase_units: [
%Paypal.Order.PurchaseUnit{
reference_id: "default",
Expand Down Expand Up @@ -642,6 +647,11 @@ defmodule Paypal.IntegrationTest do
method: :post
}
],
payer: %Paypal.Order.Payer{
payer_id: "JWEUL3HMBVGJ6",
name: %{"given_name" => "test", "surname" => "buyer"},
email_address: "[email protected]"
},
purchase_units: [
%Paypal.Order.PurchaseUnit{
reference_id: "default",
Expand Down Expand Up @@ -1086,12 +1096,17 @@ defmodule Paypal.IntegrationTest do
method: :get
}
],
payer: %Paypal.Order.Payer{
payer_id: "JWEUL3HMBVGJ6",
name: %{"given_name" => "test", "surname" => "buyer"},
email_address: "[email protected]"
},
purchase_units: [
%Paypal.Order.PurchaseUnit{}
],
status: :completed
}

assert {:ok, info} == Paypal.Order.capture(order.id)
assert {:ok, ^info} = Paypal.Order.capture(order.id)
end
end

0 comments on commit 835f46e

Please sign in to comment.