-
Notifications
You must be signed in to change notification settings - Fork 38
add new billing functionality that allow user to add/refund payment #218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -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; | ||
} |
89 changes: 89 additions & 0 deletions
89
src/main/java/com/easypost/service/BetaReferralCustomerService.java
This file contains hidden or 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 |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains hidden or 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
91 changes: 91 additions & 0 deletions
91
src/test/cassettes/beta_referral_customer/add_payment_method.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
91 changes: 91 additions & 0 deletions
91
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.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.