use of com.hyperwallet.clientsdk.model.HyperwalletPayment in project mirakl-hyperwallet-connector by paypal.
the class OperatorInvoiceModelToHyperwalletPaymentConverterTest method convert_shouldReturnNullWhenCommissionIsZero.
@Test
void convert_shouldReturnNullWhenCommissionIsZero() {
// @formatter:off
final InvoiceModel invoice = InvoiceModel.builder().destinationToken(DESTINATION_TOKEN).shopId(SHOP_ID).invoiceNumber(INVOICE_NUMBER).transferAmountToOperator(0.0D).currencyIsoCode(CURRENCY_ISO_CODE).build();
// @formatter:on
final HyperwalletPayment result = testObj.convert(invoice);
assertThat(result).isNull();
}
use of com.hyperwallet.clientsdk.model.HyperwalletPayment in project mirakl-hyperwallet-connector by paypal.
the class OperatorInvoiceModelToHyperwalletPaymentConverterTest method convert_shouldConvertAnInvoiceIntoHyperwalletPayment.
@Test
void convert_shouldConvertAnInvoiceIntoHyperwalletPayment() {
final Double transferAmountToOperator = 100.10D;
when(hyperwalletSDKServiceMock.getProgramTokenByHyperwalletProgram(HYPERWALLET_PROGRAM)).thenReturn(PROGRAM_TOKEN);
when(invoicesOperatorCommissionsConfigMock.getBankAccountToken(HYPERWALLET_PROGRAM)).thenReturn(OPERATOR_BANK_ACCOUNT_TOKEN);
// @formatter:off
final InvoiceModel invoice = InvoiceModel.builder().hyperwalletProgram(HYPERWALLET_PROGRAM).destinationToken(DESTINATION_TOKEN).shopId(SHOP_ID).invoiceNumber(INVOICE_NUMBER).transferAmountToOperator(transferAmountToOperator).currencyIsoCode(CURRENCY_ISO_CODE).build();
// @formatter:on
final HyperwalletPayment result = testObj.convert(invoice);
assertThat(result.getDestinationToken()).isEqualTo(OPERATOR_BANK_ACCOUNT_TOKEN);
assertThat(result.getClientPaymentId()).isEqualTo(INVOICE_NUMBER + PAYMENT_OPERATOR_SUFFIX);
assertThat(result.getAmount()).isEqualTo(transferAmountToOperator);
assertThat(result.getCurrency()).isEqualTo(CURRENCY_ISO_CODE);
assertThat(result.getPurpose()).isEqualTo("OTHER");
assertThat(result.getProgramToken()).isEqualTo(PROGRAM_TOKEN);
}
use of com.hyperwallet.clientsdk.model.HyperwalletPayment in project mirakl-hyperwallet-connector by paypal.
the class PayeeCreditNoteModelToHyperwalletPaymentConverterTest method convert_populatesHyperwalletPaymentWithCreditNotesInformationAndPurposeOther.
@Test
void convert_populatesHyperwalletPaymentWithCreditNotesInformationAndPurposeOther() {
when(hyperwalletSDKServiceMock.getProgramTokenByHyperwalletProgram("myProgramToken")).thenReturn("the-real-token");
final CreditNoteModel creditNoteModelStub = CreditNoteModel.builder().destinationToken("destination-token").creditAmount(20.00D).currencyIsoCode("EUR").hyperwalletProgram("myProgramToken").invoiceNumber("invoiceNumber").build();
final HyperwalletPayment result = testObj.convert(creditNoteModelStub);
assertThat(result.getAmount()).isEqualTo(20.00D);
assertThat(result.getCurrency()).isEqualTo("EUR");
assertThat(result.getProgramToken()).isEqualTo("the-real-token");
assertThat(result.getDestinationToken()).isEqualTo("destination-token");
assertThat(result.getClientPaymentId()).isEqualTo("invoiceNumber");
assertThat(result.getPurpose()).isEqualTo("OTHER");
}
use of com.hyperwallet.clientsdk.model.HyperwalletPayment in project mirakl-hyperwallet-connector by paypal.
the class AbstractInvoiceExtractServiceImplTest method extractCreditNotes_shouldCallMiraklInvoiceExtractServiceAndHyperwalletPaymentExtractServiceAndCollectCreditNotesWithDeltaPassedAsArgument.
@Test
void extractCreditNotes_shouldCallMiraklInvoiceExtractServiceAndHyperwalletPaymentExtractServiceAndCollectCreditNotesWithDeltaPassedAsArgument() {
testObj = new MyInvoiceExtractService(miraklAccountingDocumentInvoicesExtractServiceMock, miraklAccountingDocumentCreditNotesExtractServiceMock, hyperWalletPaymentExtractServiceMock, List.of());
final LocalDateTime now = TimeMachine.now();
TimeMachine.useFixedClockAt(now);
final Date delta = DateUtil.convertToDate(now, ZoneId.systemDefault());
final List<CreditNoteModel> creditNotes = List.of(creditNoteOneMock, creditNoteTwoMock);
when(miraklAccountingDocumentCreditNotesExtractServiceMock.extractAccountingDocument(delta)).thenReturn(creditNotes);
final List<HyperwalletPayment> creditNotesCreatedPayments = List.of(creditNoteHyperWalletOneMock, creditNoteHyperWalletTwoMock);
when(hyperWalletPaymentExtractServiceMock.payPayeeCreditNote(creditNotes)).thenReturn(creditNotesCreatedPayments);
final List<HyperwalletPayment> result = testObj.extractCreditNotes(delta);
verify(miraklAccountingDocumentCreditNotesExtractServiceMock).extractAccountingDocument(delta);
verify(hyperWalletPaymentExtractServiceMock).payPayeeCreditNote(creditNotes);
assertThat(result).containsExactlyInAnyOrder(creditNoteHyperWalletOneMock, creditNoteHyperWalletTwoMock);
}
use of com.hyperwallet.clientsdk.model.HyperwalletPayment in project mirakl-hyperwallet-connector by paypal.
the class HyperWalletPaymentExtractServiceImpl method createPayment.
protected HyperwalletPayment createPayment(final HyperwalletPayment hyperwalletPayment) {
try {
log.info("Trying to create payment for invoice [{}]", hyperwalletPayment.getClientPaymentId());
final Hyperwallet hyperwalletAPIClient = invoicesHyperwalletSDKService.getHyperwalletInstanceWithProgramToken(hyperwalletPayment.getProgramToken());
final HyperwalletPayment payment = hyperwalletAPIClient.createPayment(hyperwalletPayment);
log.info("Payment successfully created for invoice [{}]", hyperwalletPayment.getClientPaymentId());
return payment;
} catch (final HyperwalletException e) {
mailNotificationUtil.sendPlainTextEmail("Issue detected when creating payment for an invoice in Hyperwallet", String.format("Something went wrong creating payment for invoice [%s]%n%s", hyperwalletPayment.getClientPaymentId(), HyperwalletLoggingErrorsUtil.stringify(e)));
log.error("Something went wrong creating payment for invoice [{}]", hyperwalletPayment.getClientPaymentId());
log.error(HyperwalletLoggingErrorsUtil.stringify(e));
return null;
}
}
Aggregations