Procházet zdrojové kódy

stripe auth/capture now working

tags/v0.1.6
Jonathan Cobb před 5 roky
rodič
revize
c070844c74
8 změnil soubory, kde provedl 23 přidání a 22 odebrání
  1. +1
    -1
      bubble-server/src/main/java/bubble/cloud/payment/PaymentDriverBase.java
  2. +1
    -1
      bubble-server/src/main/java/bubble/cloud/payment/PaymentServiceDriver.java
  3. +2
    -2
      bubble-server/src/main/java/bubble/cloud/payment/delegate/DelegatedPaymentDriver.java
  4. +14
    -11
      bubble-server/src/main/java/bubble/cloud/payment/stripe/StripePaymentDriver.java
  5. +1
    -1
      bubble-server/src/main/java/bubble/dao/bill/AccountPlanDAO.java
  6. +2
    -5
      bubble-server/src/main/java/bubble/notify/payment/NotificationHandler_payment_driver_authorize.java
  7. +1
    -0
      bubble-server/src/main/java/bubble/notify/payment/PaymentNotification.java
  8. +1
    -1
      bubble-server/src/test/resources/models/tests/payment/pay_credit.json

+ 1
- 1
bubble-server/src/main/java/bubble/cloud/payment/PaymentDriverBase.java Zobrazit soubor

@@ -60,7 +60,7 @@ public abstract class PaymentDriverBase<T> extends CloudServiceDriverBase<T> imp
return bill;
}

@Override public boolean authorize(BubblePlan plan, AccountPlan accountPlan, AccountPaymentMethod paymentMethod) {
@Override public boolean authorize(BubblePlan plan, AccountPaymentMethod paymentMethod) {
return true;
}



+ 1
- 1
bubble-server/src/main/java/bubble/cloud/payment/PaymentServiceDriver.java Zobrazit soubor

@@ -17,7 +17,7 @@ public interface PaymentServiceDriver {
default PaymentValidationResult claim(AccountPaymentMethod paymentMethod) { return notSupported("claim"); }
default PaymentValidationResult claim(AccountPlanPaymentMethod planPaymentMethod) { return notSupported("claim"); }

boolean authorize(BubblePlan plan, AccountPlan accountPlan, AccountPaymentMethod paymentMethod);
boolean authorize(BubblePlan plan, AccountPaymentMethod paymentMethod);

boolean purchase(String accountPlanUuid, String paymentMethodUuid, String billUuid);



+ 2
- 2
bubble-server/src/main/java/bubble/cloud/payment/delegate/DelegatedPaymentDriver.java Zobrazit soubor

@@ -52,12 +52,12 @@ public class DelegatedPaymentDriver extends DelegatedCloudServiceDriverBase impl
new PaymentMethodClaimNotification(cloud.getName(), planPaymentMethod));
}

@Override public boolean authorize(BubblePlan plan, AccountPlan accountPlan, AccountPaymentMethod paymentMethod) {
@Override public boolean authorize(BubblePlan plan, AccountPaymentMethod paymentMethod) {
final BubbleNode delegate = getDelegateNode();
final PaymentResult result = notificationService.notifySync(delegate, payment_driver_authorize,
new PaymentNotification()
.setCloud(cloud.getName())
.setAccountPlanUuid(accountPlan.getUuid())
.setPlanUuid(plan.getUuid())
.setPaymentMethodUuid(paymentMethod.getUuid()));
return processResult(result);
}


+ 14
- 11
bubble-server/src/main/java/bubble/cloud/payment/stripe/StripePaymentDriver.java Zobrazit soubor

@@ -14,6 +14,7 @@ import com.stripe.model.Customer;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.cobbzilla.wizard.cache.redis.RedisService;
import org.cobbzilla.wizard.validation.SimpleViolationException;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
@@ -123,9 +124,8 @@ public class StripePaymentDriver extends PaymentDriverBase<StripePaymentDriverCo
}

@Override public boolean authorize(BubblePlan plan,
AccountPlan accountPlan,
AccountPaymentMethod paymentMethod) {
final String accountPlanUuid = accountPlan.getUuid();
final String planUuid = plan.getUuid();
final String paymentMethodUuid = paymentMethod.getUuid();

final Charge charge;
@@ -136,10 +136,10 @@ public class StripePaymentDriver extends PaymentDriverBase<StripePaymentDriverCo
chargeParams.put("currency", plan.getCurrency().toLowerCase());
chargeParams.put("customer", paymentMethod.getPaymentInfo());
chargeParams.put("description", plan.chargeDescription());
chargeParams.put("statement_description", plan.chargeDescription());
chargeParams.put("statement_descriptor", plan.chargeDescription());
chargeParams.put("capture", false);
final String chargeJson = json(chargeParams, COMPACT_MAPPER);
final String authCacheKey = getAuthCacheKey(accountPlanUuid, paymentMethodUuid);
final String authCacheKey = getAuthCacheKey(planUuid, paymentMethodUuid);
final String chargeId = authCache.get(authCacheKey);
if (chargeId != null) {
log.warn("authorize: already authorized: "+authCacheKey);
@@ -149,7 +149,7 @@ public class StripePaymentDriver extends PaymentDriverBase<StripePaymentDriverCo
charge = Charge.create(chargeParams);
}
if (charge.getStatus() == null) {
final String msg = "authorize: no status returned for Charge, accountPlan=" + accountPlanUuid + " with paymentMethod=" + paymentMethodUuid;
final String msg = "authorize: no status returned for Charge, plan=" + planUuid + " with paymentMethod=" + paymentMethodUuid;
log.error(msg);
throw invalidEx("err.purchase.cardUnknownError", msg);
} else {
@@ -165,29 +165,32 @@ public class StripePaymentDriver extends PaymentDriverBase<StripePaymentDriverCo
return true;

case "pending":
msg = "authorize: status='pending' (expected 'succeeded'), accountPlan=" + accountPlanUuid + " with paymentMethod=" + paymentMethodUuid;
msg = "authorize: status='pending' (expected 'succeeded'), plan=" + planUuid + " with paymentMethod=" + paymentMethodUuid;
log.error(msg);
throw invalidEx("err.purchase.chargePendingError", msg);

default:
msg = "authorize: status='" + charge.getStatus() + "' (expected 'succeeded'), accountPlan=" + accountPlanUuid + " with paymentMethod=" + paymentMethodUuid;
msg = "authorize: status='" + charge.getStatus() + "' (expected 'succeeded'), plan=" + planUuid + " with paymentMethod=" + paymentMethodUuid;
log.error(msg);
throw invalidEx("err.purchase.chargeFailedError", msg);
}
}
} catch (CardException e) {
// The card has been declined
final String msg = "authorize: CardException for accountPlan=" + accountPlanUuid + " with paymentMethod=" + paymentMethodUuid + ": requestId=" + e.getRequestId() + ", code="+e.getCode()+", declineCode="+e.getDeclineCode()+", error=" + e.toString();
final String msg = "authorize: CardException for plan=" + planUuid + " with paymentMethod=" + paymentMethodUuid + ": requestId=" + e.getRequestId() + ", code="+e.getCode()+", declineCode="+e.getDeclineCode()+", error=" + e.toString();
log.error(msg);
throw invalidEx("err.purchase.cardError", msg);

} catch (StripeException e) {
final String msg = "authorize: "+e.getClass().getSimpleName()+" for accountPlan=" + accountPlanUuid + " with paymentMethod=" + paymentMethodUuid + ": requestId=" + e.getRequestId() + ", code="+e.getCode()+", error=" + e.toString();
final String msg = "authorize: " + e.getClass().getSimpleName() + " for plan=" + planUuid + " with paymentMethod=" + paymentMethodUuid + ": requestId=" + e.getRequestId() + ", code=" + e.getCode() + ", error=" + e.toString();
log.error(msg);
throw invalidEx("err.purchase.cardProcessingError", msg);

} catch (SimpleViolationException e) {
throw e;

} catch (Exception e) {
final String msg = "authorize: "+e.getClass().getSimpleName()+" for accountPlan=" + accountPlanUuid + " with paymentMethod=" + paymentMethodUuid + ": error=" + e.toString();
final String msg = "authorize: "+e.getClass().getSimpleName()+" for plan=" + planUuid + " with paymentMethod=" + paymentMethodUuid + ": error=" + e.toString();
log.error(msg);
throw invalidEx("err.purchase.cardUnknownError", msg);
}
@@ -206,7 +209,7 @@ public class StripePaymentDriver extends PaymentDriverBase<StripePaymentDriverCo
final RedisService authCache = getAuthCache();
final RedisService chargeCache = getChargeCache();

final String authCacheKey = getAuthCacheKey(accountPlanUuid, paymentMethodUuid);
final String authCacheKey = getAuthCacheKey(plan.getUuid(), paymentMethodUuid);
try {
final String charged = chargeCache.get(billUuid);
if (charged != null) {


+ 1
- 1
bubble-server/src/main/java/bubble/dao/bill/AccountPlanDAO.java Zobrazit soubor

@@ -36,7 +36,7 @@ public class AccountPlanDAO extends AccountOwnedEntityDAO<AccountPlan> {
final PaymentServiceDriver paymentDriver = paymentService.getPaymentDriver(configuration);
if (paymentDriver.getPaymentMethodType().requiresAuth()) {
final BubblePlan plan = planDAO.findByUuid(accountPlan.getPlan());
paymentDriver.authorize(plan, accountPlan, accountPlan.getPaymentMethod());
paymentDriver.authorize(plan, accountPlan.getPaymentMethod());
}

return super.preCreate(accountPlan);


+ 2
- 5
bubble-server/src/main/java/bubble/notify/payment/NotificationHandler_payment_driver_authorize.java Zobrazit soubor

@@ -4,7 +4,6 @@ import bubble.dao.bill.AccountPaymentMethodDAO;
import bubble.dao.bill.AccountPlanDAO;
import bubble.dao.bill.BubblePlanDAO;
import bubble.model.bill.AccountPaymentMethod;
import bubble.model.bill.AccountPlan;
import bubble.model.bill.BubblePlan;
import bubble.model.cloud.CloudService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -16,11 +15,9 @@ public class NotificationHandler_payment_driver_authorize extends NotificationHa
@Autowired private AccountPlanDAO accountPlanDAO;

@Override public boolean handlePaymentRequest(PaymentNotification paymentNotification, CloudService paymentService) {
// todo: this returns null because the AccountPlan has not yet been created....
final AccountPlan accountPlan = accountPlanDAO.findByUuid(paymentNotification.getAccountPlanUuid());
final BubblePlan plan = planDAO.findByUuid(accountPlan.getPlan());
final BubblePlan plan = planDAO.findByUuid(paymentNotification.getPlanUuid());
final AccountPaymentMethod paymentMethod = paymentMethodDAO.findByUuid(paymentNotification.getPaymentMethodUuid());
return paymentService.getPaymentDriver(configuration).authorize(plan, accountPlan, paymentMethod);
return paymentService.getPaymentDriver(configuration).authorize(plan, paymentMethod);
}

}

+ 1
- 0
bubble-server/src/main/java/bubble/notify/payment/PaymentNotification.java Zobrazit soubor

@@ -10,6 +10,7 @@ import lombok.experimental.Accessors;
public class PaymentNotification extends SynchronousNotification {

@Getter @Setter private String cloud;
@Getter @Setter private String planUuid;
@Getter @Setter private String accountPlanUuid;
@Getter @Setter private String paymentMethodUuid;
@Getter @Setter private String billUuid;


+ 1
- 1
bubble-server/src/test/resources/models/tests/payment/pay_credit.json Zobrazit soubor

@@ -161,7 +161,7 @@
},

{
"before": "sleep 5s",
"before": "sleep 15s",
"comment": "verify account plans, should be one",
"request": { "uri": "me/plans" },
"response": {


Načítá se…
Zrušit
Uložit