-
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.
- Loading branch information
1 parent
7b5b614
commit 96d0873
Showing
3 changed files
with
94 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,78 @@ | ||
package com.sesame.oss.stripemock; | ||
|
||
import com.stripe.exception.InvalidRequestException; | ||
import com.stripe.exception.StripeException; | ||
import com.stripe.model.Account; | ||
import com.stripe.model.Payout; | ||
import com.stripe.model.Transfer; | ||
import com.stripe.net.RequestOptions; | ||
import com.stripe.param.PayoutCreateParams; | ||
import com.stripe.param.TransferCreateParams; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
public class PayoutTest extends AbstractStripeMockTest { | ||
@Test | ||
void testPayouts() throws StripeException { | ||
Account account = Account.create(AccountTest.defaultCreationParameters("Stripe-mock test company")); | ||
Transfer t1 = Transfer.create(TransferCreateParams.builder() | ||
.setAmount(11_00L) | ||
.setDestination(account.getId()) | ||
.setCurrency("usd") | ||
.build()); | ||
Transfer t2 = Transfer.create(TransferCreateParams.builder() | ||
.setAmount(22_00L) | ||
.setDestination(account.getId()) | ||
.setCurrency("usd") | ||
.build()); | ||
|
||
Payout payout = Payout.create(PayoutCreateParams.builder() | ||
.setAmount(30_00L) | ||
.setCurrency("usd") | ||
.build(), | ||
RequestOptions.builder() | ||
.setStripeAccount(account.getId()) | ||
.build()); | ||
|
||
assertEquals("paid", payout.getStatus()); | ||
account.delete(); | ||
} | ||
|
||
@Test | ||
void shouldFailPayoutOnInsufficientBalance() throws StripeException { | ||
Account account = Account.create(AccountTest.defaultCreationParameters("Stripe-mock test company")); | ||
|
||
InvalidRequestException exception = assertThrows(InvalidRequestException.class, | ||
() -> Payout.create(PayoutCreateParams.builder() | ||
.setAmount(30_00L) | ||
.setCurrency("usd") | ||
.build(), | ||
RequestOptions.builder() | ||
.setStripeAccount(account.getId()) | ||
.build())); | ||
assertTrue(exception.getMessage() | ||
.contains("You have insufficient funds in your Stripe account for this transfer.")); | ||
assertEquals("balance_insufficient", exception.getCode()); | ||
|
||
|
||
account.delete(); | ||
} | ||
|
||
@Test | ||
void shouldFailPayoutOnInvalidBankAccount() throws StripeException { | ||
Account account = Account.create(AccountTest.defaultCreationParameters("Stripe-mock test company")); | ||
ExternalAccountTest.replaceExternalAccountWith(account, "000111111113"); | ||
|
||
Payout payout = Payout.create(PayoutCreateParams.builder() | ||
.setAmount(30_00L) | ||
.setCurrency("usd") | ||
.build(), | ||
RequestOptions.builder() | ||
.setStripeAccount(account.getId()) | ||
.build()); | ||
|
||
// todo: add tests, including source | ||
assertEquals("failed", payout.getStatus()); | ||
account.delete(); | ||
} | ||
} |