All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.braintreegateway.test.TestingGateway Maven / Gradle / Ivy

The newest version!
package com.braintreegateway.test;

import com.braintreegateway.Configuration;
import com.braintreegateway.Environment;
import com.braintreegateway.Result;
import com.braintreegateway.Transaction;
import com.braintreegateway.exceptions.TestOperationPerformedInProductionException;
import com.braintreegateway.util.Http;
import com.braintreegateway.util.NodeWrapper;

public class TestingGateway {
    private Http http;
    private Configuration configuration;

    public TestingGateway(Http http, Configuration configuration) {
        this.configuration = configuration;
        this.http = http;
    }

    public Result settle(String transactionId) {
        checkEnvironment();
        NodeWrapper node = http.put(configuration.getMerchantPath() + "/transactions/" + transactionId + "/settle");
        return new Result(node, Transaction.class);
    }

    public Result settlementConfirm(String transactionId) {
        checkEnvironment();
        NodeWrapper node = http.put(configuration.getMerchantPath() + "/transactions/" + transactionId + "/settlement_confirm");
        return new Result(node, Transaction.class);
    }

    public Result settlementDecline(String transactionId) {
        checkEnvironment();
        NodeWrapper node = http.put(configuration.getMerchantPath() + "/transactions/" + transactionId + "/settlement_decline");
        return new Result(node, Transaction.class);
    }

    public Result settlementPending(String transactionId) {
        checkEnvironment();
        NodeWrapper node = http.put(configuration.getMerchantPath() + "/transactions/" + transactionId + "/settlement_pending");
        return new Result(node, Transaction.class);
    }

    private void checkEnvironment() throws TestOperationPerformedInProductionException {
        if (configuration.getEnvironment() == Environment.PRODUCTION) {
          throw new TestOperationPerformedInProductionException();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy