-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix account holder payment context source. Partial Authorization (#120)
* Add partial authorization in payment request * Fix account holder payment context source
- Loading branch information
1 parent
0bfe87e
commit 83554ee
Showing
6 changed files
with
223 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,13 +7,15 @@ import ( | |
"github.com/google/uuid" | ||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/checkout/checkout-sdk-go/common" | ||
"github.com/checkout/checkout-sdk-go/payments" | ||
"github.com/checkout/checkout-sdk-go/payments/nas" | ||
"github.com/checkout/checkout-sdk-go/payments/nas/sources" | ||
) | ||
|
||
func TestIncrementAuthorization(t *testing.T) { | ||
t.Skip("Skipping because increment authorization needs an authorized payment") | ||
paymentResponse := makeCardPayment(t, false, 10) | ||
paymentResponse := makeCardPaymentPartialAuthorization(t, false, 10) | ||
assert.NotNil(t, paymentResponse, "Expected paymentResponse not to be nil") | ||
|
||
metadata := make(map[string]interface{}) | ||
metadata["TestIncrementAuthorization"] = "metadata" | ||
|
@@ -38,20 +40,26 @@ func TestIncrementAuthorization(t *testing.T) { | |
checkerOne: func(response *nas.IncrementAuthorizationResponse, err error) { | ||
assert.Nil(t, err) | ||
assert.NotNil(t, response) | ||
assert.NotEmpty(t, response.Reference) | ||
assert.Equal(t, int64(5), response.Amount) | ||
assert.NotEmpty(t, response.ActionId) | ||
assert.NotEmpty(t, response.Currency) | ||
assert.False(t, response.Approved) | ||
assert.NotEmpty(t, response.ResponseCode) | ||
assert.NotEmpty(t, response.ResponseSummary) | ||
assert.NotEmpty(t, response.ExpiresOn) | ||
assert.NotEmpty(t, response.ProcessedOn) | ||
assert.NotEmpty(t, response.Balances) | ||
assert.NotEmpty(t, response.Links) | ||
assert.NotEmpty(t, response.Links["payment"]) | ||
}, | ||
checkerTwo: func(response *nas.GetPaymentResponse, err error) { | ||
assert.NotEmpty(t, response.Balances) | ||
assert.Equal(t, int64(10), response.Balances.TotalAuthorized) | ||
assert.Equal(t, int64(5), response.Balances.TotalCaptured) | ||
assert.Equal(t, int64(0), response.Balances.TotalCaptured) | ||
assert.Equal(t, int64(0), response.Balances.TotalRefunded) | ||
assert.Equal(t, int64(0), response.Balances.TotalVoided) | ||
assert.Equal(t, int64(0), response.Balances.AvailableToCapture) | ||
assert.Equal(t, int64(5), response.Balances.AvailableToRefund) | ||
assert.Equal(t, int64(0), response.Balances.AvailableToVoid) | ||
assert.Equal(t, int64(10), response.Balances.AvailableToCapture) | ||
assert.Equal(t, int64(0), response.Balances.AvailableToRefund) | ||
assert.Equal(t, int64(10), response.Balances.AvailableToVoid) | ||
}, | ||
}, | ||
} | ||
|
@@ -69,8 +77,8 @@ func TestIncrementAuthorization(t *testing.T) { | |
} | ||
|
||
func TestIncrementAuthorizationIdempotently(t *testing.T) { | ||
t.Skip("Skipping because increment authorization needs an authorized payment") | ||
paymentResponse := makeCardPayment(t, false, 10) | ||
paymentResponse := makeCardPaymentPartialAuthorization(t, false, 10) | ||
assert.NotNil(t, paymentResponse, "Expected paymentResponse not to be nil") | ||
|
||
metadata := make(map[string]interface{}) | ||
metadata["TestIncrementAuthorization"] = "metadata" | ||
|
@@ -115,7 +123,9 @@ func TestIncrementAuthorizationIdempotently(t *testing.T) { | |
checker: func(response1 interface{}, err1 error, response2 interface{}, err2 error) { | ||
assert.Nil(t, err1) | ||
assert.NotNil(t, response1) | ||
assert.NotNil(t, err2) | ||
assert.Nil(t, err2) | ||
assert.NotNil(t, response2) | ||
assert.NotEqual(t, response1.(*nas.IncrementAuthorizationResponse).ActionId, response2.(*nas.IncrementAuthorizationResponse).ActionId) | ||
}, | ||
}, | ||
} | ||
|
@@ -128,15 +138,15 @@ func TestIncrementAuthorizationIdempotently(t *testing.T) { | |
return client.IncrementAuthorization(tc.paymentId, tc.request, &tc.idempotencyKeyRandom1) | ||
} | ||
predicateOne := func(data interface{}) bool { | ||
response := data.(*payments.CaptureResponse) | ||
response := data.(*nas.IncrementAuthorizationResponse) | ||
return response.Links != nil && len(response.Links) >= 0 | ||
} | ||
|
||
processTwo := func() (interface{}, error) { | ||
return client.IncrementAuthorization(tc.paymentId, tc.request, &tc.idempotencyKeyRandom2) | ||
} | ||
predicateTwo := func(data interface{}) bool { | ||
response := data.(*payments.CaptureResponse) | ||
response := data.(*nas.IncrementAuthorizationResponse) | ||
return response.Links != nil && len(response.Links) >= 0 | ||
} | ||
|
||
|
@@ -146,3 +156,71 @@ func TestIncrementAuthorizationIdempotently(t *testing.T) { | |
}) | ||
} | ||
} | ||
|
||
func makeCardPaymentPartialAuthorization(t *testing.T, shouldCapture bool, amount int64) *nas.PaymentResponse { | ||
currentYear := time.Now().Year() + 1 | ||
|
||
cardSource := sources.NewRequestCardSource() | ||
cardSource.Name = "Mr. Test" | ||
cardSource.Number = "4556447238607884" | ||
cardSource.ExpiryYear = currentYear | ||
cardSource.ExpiryMonth = 12 | ||
cardSource.Cvv = "123" | ||
cardSource.BillingAddress = &common.Address{ | ||
AddressLine1: "CheckoutSdk.com", | ||
AddressLine2: "90 Tottenham Court Road", | ||
City: "London", | ||
State: "London", | ||
Zip: "W1T 4TJ", | ||
Country: common.GB, | ||
} | ||
cardSource.Phone = &common.Phone{ | ||
CountryCode: "44", | ||
Number: "1234567890", | ||
} | ||
|
||
customerRequest := &common.CustomerRequest{ | ||
Email: "[email protected]", | ||
Name: "Test Customer", | ||
Phone: &common.Phone{ | ||
CountryCode: "44", | ||
Number: "1234567890", | ||
}, | ||
} | ||
|
||
paymentIndividualSender := nas.NewRequestIndividualSender() | ||
paymentIndividualSender.FirstName = "Mr" | ||
paymentIndividualSender.LastName = "Test" | ||
paymentIndividualSender.Address = &common.Address{ | ||
AddressLine1: "CheckoutSdk.com", | ||
AddressLine2: "90 Tottenham Court Road", | ||
City: "London", | ||
State: "London", | ||
Zip: "W1T 4TJ", | ||
Country: common.GB, | ||
} | ||
|
||
paymentRequest := nas.PaymentRequest{ | ||
Source: cardSource, | ||
Amount: amount, | ||
Currency: common.USD, | ||
Reference: uuid.New().String(), | ||
Description: "Test Payment", | ||
Capture: shouldCapture, | ||
Customer: customerRequest, | ||
Sender: paymentIndividualSender, | ||
AuthorizationType: nas.EstimatedAuthorizationType, | ||
PartialAuthorization: &nas.PartialAuthorization{ | ||
Enabled: true, | ||
}, | ||
BillingDescriptor: &payments.BillingDescriptor{ | ||
Name: "CheckoutSdk.com", | ||
City: "London", | ||
}, | ||
} | ||
|
||
response, err := DefaultApi().Payments.RequestPayment(paymentRequest, nil) | ||
assert.Nil(t, err, "Expected no error in RequestPayment") | ||
assert.NotNil(t, response, "Expected response not to be nil") | ||
return response | ||
} |
50 changes: 50 additions & 0 deletions
50
test/resources/payment_context_paypal_details_response.json
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,50 @@ | ||
{ | ||
"partner_metadata": { | ||
"customer_id": "EWR4HCRWOEIW4", | ||
"order_id": "NF89G5J9E5G905E90" | ||
}, | ||
"payment_request": { | ||
"amount": 2500, | ||
"authorization_type": "Final", | ||
"capture": true, | ||
"currency": "GBP", | ||
"failure_url": "https://url/payment-failed", | ||
"items": [ | ||
{ | ||
"discount_amount": 0, | ||
"name": "£25.00 Voucher", | ||
"quantity": 1, | ||
"tax_amount": 0, | ||
"total_amount": 2500, | ||
"unit_price": 2500 | ||
} | ||
], | ||
"payment_type": "Regular", | ||
"processing": { | ||
"shipping_amount": 0, | ||
"user_action": "PAY_NOW" | ||
}, | ||
"processing_channel_id": "pc_strugfrty47ellyymdfg6fzhc4i", | ||
"reference": "543454", | ||
"shipping": { | ||
"address": { | ||
"address_line1": "Main Address", | ||
"address_line2": "Flor 1", | ||
"city": "London", | ||
"country": "GB", | ||
"state": "State", | ||
"zip": "ZIP" | ||
}, | ||
"first_name": "Andrey Young" | ||
}, | ||
"source": { | ||
"account_holder": { | ||
"email": "[email protected]", | ||
"full_name": "Andrey Young" | ||
}, | ||
"type": "paypal" | ||
}, | ||
"success_url": "https://url/payment-successful" | ||
}, | ||
"status": "Created" | ||
} |