Skip to content

Commit 1be0099

Browse files
authored
add new billing functionality that allow user to add/refund payment (#218)
1 parent 012d014 commit 1be0099

File tree

11 files changed

+460
-3
lines changed

11 files changed

+460
-3
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# CHANGELOG
22

3+
## Next Release
4+
5+
- [ADDED] Adds new beta billing functionality for ReferralCustomer users
6+
- `addPaymentMethod` can add a pre-existing Stripe bank account or credit card to your EasyPost account
7+
- `refundByAmount` refunds your wallet by a dollar amount
8+
- `refundByPaymentLog` refunds you wallet by a PaymentLog ID
9+
310
## v6.0.0 (2023-01-05)
411

512
Includes all the changes from `v6.0.0-rc1` listed below in addition to the following:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,4 @@ Some tests may require an EasyPost user with a particular set of enabled feature
146146

147147
- `USPS_CARRIER_ACCOUNT_ID` (eg: one-call buying a shipment for non-EasyPost employees)
148148
- `PARTNER_USER_PROD_API_KEY` (eg: creating a referral user)
149-
- `REFERRAL_USER_PROD_API_KEY` (eg: adding a credit card to a referral user)
149+
- `REFERRAL_CUSTOMER_PROD_API_KEY` (eg: adding a credit card to a referral user)

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@
313313
<plugin>
314314
<groupId>org.owasp</groupId>
315315
<artifactId>dependency-check-maven</artifactId>
316-
<version>7.1.1</version>
316+
<version>7.4.4</version>
317317
<configuration>
318318
<suppressionFile>dependency-check-suppressions.xml</suppressionFile>
319319
<failBuildOnCVSS>7</failBuildOnCVSS>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.easypost.model;
2+
3+
import java.util.List;
4+
import lombok.Getter;
5+
6+
@Getter
7+
public class BetaPaymentRefund extends EasyPostResource{
8+
private int refundedAmount;
9+
private List<Error> errors;
10+
private List<String> refundedPaymentLogs;
11+
private String paymentLogId;
12+
private String refundedAmountCurrencys;
13+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package com.easypost.service;
2+
3+
import java.util.HashMap;
4+
5+
import com.easypost.exception.EasyPostException;
6+
import com.easypost.http.Requestor;
7+
import com.easypost.http.Requestor.RequestMethod;
8+
import com.easypost.model.BetaPaymentRefund;
9+
import com.easypost.model.PaymentMethod;
10+
import com.easypost.model.PaymentMethodObject;
11+
12+
public class BetaReferralCustomerService {
13+
private final EasyPostClient client;
14+
15+
/**
16+
* BetaReferralCustomerService constructor.
17+
*
18+
* @param client The client object.
19+
*/
20+
BetaReferralCustomerService(EasyPostClient client) {
21+
this.client = client;
22+
}
23+
24+
/**
25+
* Add Stripe payment method to referral customer.
26+
*
27+
* @param stripeCustomerId ID of the Stripe account.
28+
* @param paymentMethodReference Reference of Stripe payment method.
29+
* @return PaymentMethodObject object.
30+
* @throws EasyPostException
31+
*/
32+
public PaymentMethodObject addPaymentMethod(String stripeCustomerId, String paymentMethodReference)
33+
throws EasyPostException {
34+
return addPaymentMethod(stripeCustomerId, paymentMethodReference, PaymentMethod.Priority.PRIMARY);
35+
}
36+
37+
/**
38+
* Add Stripe payment method to referral customer.
39+
*
40+
* @param stripeCustomerId ID of the Stripe account.
41+
* @param paymentMethodReference Reference of Stripe payment method.
42+
* @param primaryOrSecondary Primary or secondary of this payment method.
43+
* @return PaymentMethodObject object.
44+
* @throws EasyPostException
45+
*/
46+
public PaymentMethodObject addPaymentMethod(String stripeCustomerId, String paymentMethodReference,
47+
PaymentMethod.Priority primaryOrSecondary) throws EasyPostException {
48+
HashMap<String, Object> params = new HashMap<>();
49+
params.put("stripe_customer_id", stripeCustomerId);
50+
params.put("payment_method_reference", paymentMethodReference);
51+
params.put("priority", primaryOrSecondary);
52+
53+
HashMap<String, Object> wrappedParams = new HashMap<>();
54+
wrappedParams.put("payment_method", params);
55+
56+
return Requestor.request(RequestMethod.POST, "%s/beta/referral_customers/payment_method", wrappedParams,
57+
PaymentMethodObject.class, client);
58+
}
59+
60+
/**
61+
* Refund by amount for a recent payment.
62+
*
63+
* @param refundAmount Amount to be refunded by cents.
64+
* @return BetaPaymentRefund object.
65+
* @throws EasyPostException
66+
*/
67+
public BetaPaymentRefund refundByAmount(int refundAmount) throws EasyPostException {
68+
HashMap<String, Object> params = new HashMap<>();
69+
params.put("refund_amount", refundAmount);
70+
71+
return Requestor.request(RequestMethod.POST, "%s/beta/referral_customers/refunds", params,
72+
BetaPaymentRefund.class, client);
73+
}
74+
75+
/**
76+
* Refund a payment by a payment log ID.
77+
*
78+
* @param paymentLogId ID of the payment log.
79+
* @return BetaPaymentRefund object.
80+
* @throws EasyPostException
81+
*/
82+
public BetaPaymentRefund refundByPaymentLog(String paymentLogId) throws EasyPostException {
83+
HashMap<String, Object> params = new HashMap<>();
84+
params.put("payment_log_id", paymentLogId);
85+
86+
return Requestor.request(RequestMethod.POST, "%s/beta/referral_customers/refunds", params,
87+
BetaPaymentRefund.class, client);
88+
}
89+
}

src/main/java/com/easypost/service/EasyPostClient.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class EasyPostClient {
1212
public final AddressService address;
1313
public final ApiKeyService apiKey;
1414
public final BatchService batch;
15+
public final BetaReferralCustomerService betaReferralCustomer;
1516
public final BillingService billing;
1617
public final CarrierAccountService carrierAccount;
1718
public final CarrierTypeService carrierType;
@@ -114,6 +115,7 @@ public EasyPostClient(String apiKey, int connectTimeoutMilliseconds, int readTim
114115
this.address = new AddressService(this);
115116
this.apiKey = new ApiKeyService(this);
116117
this.batch = new BatchService(this);
118+
this.betaReferralCustomer = new BetaReferralCustomerService(this);
117119
this.billing = new BillingService(this);
118120
this.carrierAccount = new CarrierAccountService(this);
119121
this.carrierType = new CarrierTypeService(this);

src/test/cassettes/beta_referral_customer/add_payment_method.json

Lines changed: 91 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/test/cassettes/beta_referral_customer/refund_by_amount.json

Lines changed: 91 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)