Permalink
Browse files

Paypal expects amount to be xx.xx not xxxx

  • Loading branch information...
biilmann committed Nov 7, 2017
1 parent 3338de7 commit 6f60bb384927d5b40a4c00b4fda4ffdd78c9b20c
Showing with 10 additions and 6 deletions.
  1. +4 −4 api/payments_test.go
  2. +6 −2 payments/paypal/paypal.go
View
@@ -456,7 +456,7 @@ func TestPaymentPreauthorize(t *testing.T) {
form := url.Values{}
form.Add("provider", payments.PayPalProvider)
form.Add("amount", "10")
form.Add("amount", "1000")
form.Add("currency", "USD")
form.Add("description", "test")
@@ -477,7 +477,7 @@ func TestPaymentPreauthorize(t *testing.T) {
require.Len(t, createData.Transactions, 1)
assert.Equal(t, "sale", createData.Intent)
assert.Equal(t, "10", createData.Transactions[0].Amount.Total)
assert.Equal(t, "10.00", createData.Transactions[0].Amount.Total)
assert.Equal(t, "USD", createData.Transactions[0].Amount.Currency)
assert.Equal(t, "test", createData.Transactions[0].Description)
})
@@ -492,7 +492,7 @@ func TestPaymentPreauthorize(t *testing.T) {
test.Config.Payment.PayPal.Env = server.URL
params := paypalPreauthorizeParams{
Amount: 10,
Amount: 1000,
Currency: "USD",
Description: "test",
Provider: payments.PayPalProvider,
@@ -518,7 +518,7 @@ func TestPaymentPreauthorize(t *testing.T) {
require.Len(t, createData.Transactions, 1)
assert.Equal(t, "sale", createData.Intent)
assert.Equal(t, "10", createData.Transactions[0].Amount.Total)
assert.Equal(t, "10.00", createData.Transactions[0].Amount.Total)
assert.Equal(t, "USD", createData.Transactions[0].Amount.Currency)
assert.Equal(t, "test", createData.Transactions[0].Description)
})
@@ -123,7 +123,7 @@ func (p *paypalPaymentProvider) NewRefunder(ctx context.Context, r *http.Request
func (p *paypalPaymentProvider) refund(transactionID string, amount uint64, currency string) (string, error) {
amt := &paypalsdk.Amount{
Total: strconv.FormatUint(amount, 10),
Total: formatAmount(amount),
Currency: currency,
}
ref, err := p.client.RefundSale(transactionID, amt)
@@ -156,7 +156,7 @@ func (p *paypalPaymentProvider) preauthorize(config *conf.Configuration, amount
ExperienceProfileID: profile.ID,
Transactions: []paypalsdk.Transaction{paypalsdk.Transaction{
Amount: &paypalsdk.Amount{
Total: strconv.FormatUint(amount, 10),
Total: formatAmount(amount),
Currency: currency,
},
Description: description,
@@ -209,3 +209,7 @@ func (p *paypalPaymentProvider) getExperience() (*paypalsdk.WebProfile, error) {
p.profile = profile
return profile, nil
}
func formatAmount(amount uint64) string {
return strconv.FormatFloat(float64(amount)/100, 'f', 2, 64)
}

0 comments on commit 6f60bb3

Please sign in to comment.