Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# CHANGELOG

## Next Release

- [ADDED] Adds new beta billing functionality for ReferralCustomer users
- `addPaymentMethod` can add a pre-existing Stripe bank account or credit card to your EasyPost account
- `refundByAmount` refunds your wallet by a dollar amount
- `refundByPaymentLog` refunds you wallet by a PaymentLog ID

## v6.0.0 (2023-01-05)

Includes all the changes from `v6.0.0-rc1` listed below in addition to the following:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,4 @@ Some tests may require an EasyPost user with a particular set of enabled feature

- `USPS_CARRIER_ACCOUNT_ID` (eg: one-call buying a shipment for non-EasyPost employees)
- `PARTNER_USER_PROD_API_KEY` (eg: creating a referral user)
- `REFERRAL_USER_PROD_API_KEY` (eg: adding a credit card to a referral user)
- `REFERRAL_CUSTOMER_PROD_API_KEY` (eg: adding a credit card to a referral user)
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@
<plugin>
<groupId>org.owasp</groupId>
<artifactId>dependency-check-maven</artifactId>
<version>7.1.1</version>
<version>7.4.4</version>
<configuration>
<failBuildOnCVSS>7</failBuildOnCVSS>
<junitFailOnCVSS>7</junitFailOnCVSS>
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/easypost/model/BetaPaymentRefund.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.easypost.model;

import java.util.List;
import lombok.Getter;

@Getter
public class BetaPaymentRefund extends EasyPostResource{
private int refundedAmount;
private List<Error> errors;
private List<String> refundedPaymentLogs;
private String paymentLogId;
private String refundedAmountCurrencys;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package com.easypost.service;

import java.util.HashMap;

import com.easypost.exception.EasyPostException;
import com.easypost.http.Requestor;
import com.easypost.http.Requestor.RequestMethod;
import com.easypost.model.BetaPaymentRefund;
import com.easypost.model.PaymentMethod;
import com.easypost.model.PaymentMethodObject;

public class BetaReferralCustomerService {
private final EasyPostClient client;

/**
* BetaReferralCustomerService constructor.
*
* @param client The client object.
*/
BetaReferralCustomerService(EasyPostClient client) {
this.client = client;
}

/**
* Add Stripe payment method to referral customer.
*
* @param stripeCustomerId ID of the Stripe account.
* @param paymentMethodReference Reference of Stripe payment method.
* @return PaymentMethodObject object.
* @throws EasyPostException
*/
public PaymentMethodObject addPaymentMethod(String stripeCustomerId, String paymentMethodReference)
throws EasyPostException {
return addPaymentMethod(stripeCustomerId, paymentMethodReference, PaymentMethod.Priority.PRIMARY);
}

/**
* Add Stripe payment method to referral customer.
*
* @param stripeCustomerId ID of the Stripe account.
* @param paymentMethodReference Reference of Stripe payment method.
* @param primaryOrSecondary Primary or secondary of this payment method.
* @return PaymentMethodObject object.
* @throws EasyPostException
*/
public PaymentMethodObject addPaymentMethod(String stripeCustomerId, String paymentMethodReference,
PaymentMethod.Priority primaryOrSecondary) throws EasyPostException {
HashMap<String, Object> params = new HashMap<>();
params.put("stripe_customer_id", stripeCustomerId);
params.put("payment_method_reference", paymentMethodReference);
params.put("priority", primaryOrSecondary);

HashMap<String, Object> wrappedParams = new HashMap<>();
wrappedParams.put("payment_method", params);

return Requestor.request(RequestMethod.POST, "%s/beta/referral_customers/payment_method", wrappedParams,
PaymentMethodObject.class, client);
}

/**
* Refund by amount for a recent payment.
*
* @param refundAmount Amount to be refunded by cents.
* @return BetaPaymentRefund object.
* @throws EasyPostException
*/
public BetaPaymentRefund refundByAmount(int refundAmount) throws EasyPostException {
HashMap<String, Object> params = new HashMap<>();
params.put("refund_amount", refundAmount);

return Requestor.request(RequestMethod.POST, "%s/beta/referral_customers/refunds", params,
BetaPaymentRefund.class, client);
}

/**
* Refund a payment by a payment log ID.
*
* @param paymentLogId ID of the payment log.
* @return BetaPaymentRefund object.
* @throws EasyPostException
*/
public BetaPaymentRefund refundByPaymentLog(String paymentLogId) throws EasyPostException {
HashMap<String, Object> params = new HashMap<>();
params.put("payment_log_id", paymentLogId);

return Requestor.request(RequestMethod.POST, "%s/beta/referral_customers/refunds", params,
BetaPaymentRefund.class, client);
}
}
2 changes: 2 additions & 0 deletions src/main/java/com/easypost/service/EasyPostClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class EasyPostClient {
public final AddressService address;
public final ApiKeyService apiKey;
public final BatchService batch;
public final BetaReferralCustomerService betaReferralCustomer;
public final BillingService billing;
public final CarrierAccountService carrierAccount;
public final CarrierTypeService carrierType;
Expand Down Expand Up @@ -114,6 +115,7 @@ public EasyPostClient(String apiKey, int connectTimeoutMilliseconds, int readTim
this.address = new AddressService(this);
this.apiKey = new ApiKeyService(this);
this.batch = new BatchService(this);
this.betaReferralCustomer = new BetaReferralCustomerService(this);
this.billing = new BillingService(this);
this.carrierAccount = new CarrierAccountService(this);
this.carrierType = new CarrierTypeService(this);
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

91 changes: 91 additions & 0 deletions src/test/cassettes/beta_referral_customer/refund_by_amount.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading