Search in sources :

Example 1 with PaymentProvider

use of org.structr.payment.api.PaymentProvider in project structr by structr.

the class PaymentNode method beginCheckout.

public static GraphObject beginCheckout(final PaymentNode thisNode, final String providerName, final String successUrl, final String cancelUrl) throws FrameworkException {
    final PaymentProvider provider = PaymentNode.getPaymentProvider(providerName);
    if (provider != null) {
        final BeginCheckoutResponse response = provider.beginCheckout(thisNode, successUrl, cancelUrl);
        if (CheckoutState.Success.equals(response.getCheckoutState())) {
            final GraphObjectMap data = new GraphObjectMap();
            data.put(StructrApp.key(PaymentNode.class, "token"), response.getToken());
            return data;
        } else {
            throwErrors("Unable to begin checkout.", response);
        }
    } else {
        throw new FrameworkException(422, "Payment provider " + providerName + " not found.");
    }
    return null;
}
Also used : PaymentProvider(org.structr.payment.api.PaymentProvider) PayPalPaymentProvider(org.structr.payment.impl.paypal.PayPalPaymentProvider) StripePaymentProvider(org.structr.payment.impl.stripe.StripePaymentProvider) TestPaymentProvider(org.structr.payment.impl.test.TestPaymentProvider) BeginCheckoutResponse(org.structr.payment.api.BeginCheckoutResponse) FrameworkException(org.structr.common.error.FrameworkException) GraphObjectMap(org.structr.core.GraphObjectMap)

Aggregations

FrameworkException (org.structr.common.error.FrameworkException)1 GraphObjectMap (org.structr.core.GraphObjectMap)1 BeginCheckoutResponse (org.structr.payment.api.BeginCheckoutResponse)1 PaymentProvider (org.structr.payment.api.PaymentProvider)1 PayPalPaymentProvider (org.structr.payment.impl.paypal.PayPalPaymentProvider)1 StripePaymentProvider (org.structr.payment.impl.stripe.StripePaymentProvider)1 TestPaymentProvider (org.structr.payment.impl.test.TestPaymentProvider)1