|
| 1 | +package com.bitpay.sdk.examples.Merchant; |
| 2 | + |
| 3 | +import com.bitpay.sdk.Client; |
| 4 | +import com.bitpay.sdk.exceptions.BitPayApiException; |
| 5 | +import com.bitpay.sdk.exceptions.BitPayGenericException; |
| 6 | +import com.bitpay.sdk.model.invoice.Buyer; |
| 7 | +import com.bitpay.sdk.model.invoice.Invoice; |
| 8 | +import com.bitpay.sdk.examples.ClientProvider; |
| 9 | +import java.util.List; |
| 10 | + |
| 11 | +public class InvoiceRequests { |
| 12 | + |
| 13 | + public void createInvoice() throws BitPayGenericException, BitPayApiException { |
| 14 | + Client client = ClientProvider.create(); |
| 15 | + |
| 16 | + Invoice invoice = new Invoice(); |
| 17 | + invoice.setFullNotifications(true); |
| 18 | + invoice.setExtendedNotifications(true); |
| 19 | + invoice.setNotificationUrl("https://test/lJnJg9WW7MtG9GZlPVdj"); |
| 20 | + invoice.setRedirectUrl("https://test/lJnJg9WW7MtG9GZlPVdj"); |
| 21 | + invoice. setNotificationEmail( "[email protected]"); |
| 22 | + invoice.setBuyerSms("+12223334445"); |
| 23 | + |
| 24 | + Buyer buyer = new Buyer(); |
| 25 | + buyer.setName("Test"); |
| 26 | + buyer. setEmail( "[email protected]"); |
| 27 | + buyer.setAddress1("168 General Grove"); |
| 28 | + buyer.setCountry("AD"); |
| 29 | + buyer.setLocality("Port Horizon"); |
| 30 | + buyer.setNotify(true); |
| 31 | + buyer.setPhone("+990123456789"); |
| 32 | + buyer.setPostalCode("KY7 1TH"); |
| 33 | + buyer.setRegion("New Port"); |
| 34 | + |
| 35 | + invoice.setBuyer(buyer); |
| 36 | + |
| 37 | + Invoice result = client.createInvoice(invoice); |
| 38 | + } |
| 39 | + |
| 40 | + public void getInvoice() throws BitPayGenericException, BitPayApiException { |
| 41 | + Client client = ClientProvider.create(); |
| 42 | + |
| 43 | + Invoice invoiceById = client.getInvoice("myInvoiceId"); |
| 44 | + |
| 45 | + Invoice invoiceByGuid = client.getInvoiceByGuid("someGuid"); // we can add a GUID during the invoice creation |
| 46 | + |
| 47 | + List<Invoice> invoices = client.getInvoices("2023-04-14", "2023-04-17", null, null, null, null); |
| 48 | + } |
| 49 | + |
| 50 | + public void updateInvoice() throws BitPayGenericException, BitPayApiException { |
| 51 | + Client client = ClientProvider.create(); |
| 52 | + |
| 53 | + Invoice invoice = client.updateInvoice("someInvoiceId", "12312321321", null, null, null); |
| 54 | + } |
| 55 | + |
| 56 | + public void cancelInvoice() throws BitPayGenericException, BitPayApiException { |
| 57 | + Client client = ClientProvider.create(); |
| 58 | + |
| 59 | + client.cancelInvoice("invoiceId"); |
| 60 | + |
| 61 | + client.cancelInvoiceByGuid("invoiceGuid"); |
| 62 | + } |
| 63 | + |
| 64 | + public void requestInvoiceWebhookToBeResent() throws BitPayGenericException, BitPayApiException { |
| 65 | + Client client = ClientProvider.create(); |
| 66 | + |
| 67 | + client.requestInvoiceWebhookToBeResent("someInvoiceId"); |
| 68 | + } |
| 69 | +} |
0 commit comments