[ 
https://issues.apache.org/jira/browse/CAMEL-12138?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16519306#comment-16519306
 ] 

ASF GitHub Bot commented on CAMEL-12138:
----------------------------------------

oscerd closed pull request #2389: CAMEL-12138: camel-braintree - expose dispute 
and documentUpload APIs
URL: https://github.com/apache/camel/pull/2389
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/components/camel-braintree/pom.xml 
b/components/camel-braintree/pom.xml
index 6f193b774fe..f1d9e3e61b7 100644
--- a/components/camel-braintree/pom.xml
+++ b/components/camel-braintree/pom.xml
@@ -159,6 +159,16 @@
                   <proxyClass>com.braintreegateway.DiscountGateway</proxyClass>
                   <fromJavadoc/>
                 </api>
+                <api>
+                  <apiName>dispute</apiName>
+                  <proxyClass>com.braintreegateway.DisputeGateway</proxyClass>
+                  <fromJavadoc/>
+                </api>
+                <api>
+                  <apiName>documentUpload</apiName>
+                  
<proxyClass>com.braintreegateway.DocumentUploadGateway</proxyClass>
+                  <fromJavadoc/>
+                </api>
                 <api>
                   <apiName>merchantAccount</apiName>
                   
<proxyClass>com.braintreegateway.MerchantAccountGateway</proxyClass>
diff --git a/components/camel-braintree/src/main/docs/braintree-component.adoc 
b/components/camel-braintree/src/main/docs/braintree-component.adoc
index 50bfde3917a..202274a7552 100644
--- a/components/camel-braintree/src/main/docs/braintree-component.adoc
+++ b/components/camel-braintree/src/main/docs/braintree-component.adoc
@@ -115,6 +115,8 @@ Endpoint prefix can be one of:
 * creditCardverification
 * customer
 * discount
+* dispute
+* documentUpload
 * merchantAccount
 * paymentmethod
 * paymentmethodNonce
@@ -357,6 +359,90 @@ braintree://discount/endpoint
 
  +
 
+#### Endpoint prefix _dispute_
+
+The following endpoints can be invoked with the prefix *dispute* as
+follows:
+
+[source,java]
+----------------------------------------------
+braintree://dispute/endpoint?[options]
+----------------------------------------------
+
+[cols="<,<,<,<",options="header",]
+|=======================================================================
+|Endpoint |Shorthand Alias |Options |Result Body Type
+|accept |  |id
+|com.braintreegateway.Result
+
+|addFileEvidence |  |disputeId, documentId
+|com.braintreegateway.Result<DisputeEvidence>
+
+|addFileEvidence |  |disputeId, fileEvidenceRequest
+|com.braintreegateway.Result<DisputeEvidence>
+
+|addTextEvidence |  |disputeId, content
+|com.braintreegateway.Result<DisputeEvidence>
+
+|addTextEvidence |  |disputeId, textEvidenceRequest
+|com.braintreegateway.Result<DisputeEvidence>
+
+|finalize |  |id
+|com.braintreegateway.Result
+
+|find |  |id
+|com.braintreegateway.Dispute
+
+|removeEvidence |  |id
+|com.braintreegateway.Result
+
+|search |  | disputeSearchRequest
+|com.braintreegateway.PaginatedCollection<com.braintreegateway.Dispute>
+|=======================================================================
+
+[[Braintree-URIOptionsfordispute]]
+URI Options for _dispute_
+
+[cols="<,<",options="header",]
+|==========================================================
+|Name |Type
+|id |String
+|disputeId |String
+|documentId |String
+|fileEvidenceRequest |com.braintreegateway.FileEvidenceRequest
+|content |String |
+|textEvidenceRequest |com.braintreegateway.TextEvidenceRequest
+|disputeSearchRequest |com.braintreegateway.DisputeSearchRequest
+|==========================================================
+
+
+#### Endpoint prefix _documentUpload_
+
+The following endpoints can be invoked with the prefix *documentUpload* as
+follows:
+
+[source,java]
+----------------------------------------------
+braintree://documentUpload/endpoint?[options]
+----------------------------------------------
+
+[cols="<,<,<,<",options="header",]
+|=======================================================================
+|Endpoint |Shorthand Alias |Options |Result Body Type
+|create |  |request
+|com.braintreegateway.Result<com.braintreegateway.DocumentUpload>
+|=======================================================================
+
+[[Braintree-URIOptionsfordocumentUpload]]
+URI Options for _documentUpload_
+
+[cols="<,<",options="header",]
+|==========================================================
+|Name |Type
+|request |com.braintreegateway.DocumentUploadRequest
+|==========================================================
+
+
 #### Endpoint prefix _merchantAccount_
 
 The following endpoints can be invoked with the
diff --git 
a/components/camel-braintree/src/test/java/org/apache/camel/component/braintree/DisputeGatewayIntegrationTest.java
 
b/components/camel-braintree/src/test/java/org/apache/camel/component/braintree/DisputeGatewayIntegrationTest.java
new file mode 100644
index 00000000000..bc867e616eb
--- /dev/null
+++ 
b/components/camel-braintree/src/test/java/org/apache/camel/component/braintree/DisputeGatewayIntegrationTest.java
@@ -0,0 +1,349 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.braintree;
+
+import java.io.File;
+import java.math.BigDecimal;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.braintreegateway.BraintreeGateway;
+import com.braintreegateway.Dispute;
+import com.braintreegateway.DisputeEvidence;
+import com.braintreegateway.DisputeSearchRequest;
+import com.braintreegateway.DocumentUpload;
+import com.braintreegateway.DocumentUploadRequest;
+import com.braintreegateway.FileEvidenceRequest;
+import com.braintreegateway.PaginatedCollection;
+import com.braintreegateway.Result;
+import com.braintreegateway.TextEvidenceRequest;
+import com.braintreegateway.Transaction;
+import com.braintreegateway.TransactionRequest;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.braintree.internal.BraintreeApiCollection;
+import org.apache.camel.component.braintree.internal.DisputeGatewayApiMethod;
+import 
org.apache.camel.component.braintree.internal.DocumentUploadGatewayApiMethod;
+import 
org.apache.camel.component.braintree.internal.TransactionGatewayApiMethod;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DisputeGatewayIntegrationTest extends 
AbstractBraintreeTestSupport {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(DisputeGatewayIntegrationTest.class);
+    private static final String PATH_PREFIX = 
BraintreeApiCollection.getCollection().getApiName(DisputeGatewayApiMethod.class).getName();
+    private static final String TRANSACTION_PATH_PREFIX = 
BraintreeApiCollection.getCollection().getApiName(TransactionGatewayApiMethod.class).getName();
+    private static final String DOCUMENT_UPLOAD_PATH_PREFIX = 
BraintreeApiCollection.getCollection().getApiName(DocumentUploadGatewayApiMethod.class).getName();
+
+    private BraintreeGateway gateway;
+
+    @Override
+    protected void doPostSetup() throws Exception {
+        this.gateway = getGateway();
+    }
+
+    @Test
+    public void testAccept() throws Exception {
+        Dispute createdDispute = createDispute();
+        assertEquals(Dispute.Status.OPEN, createdDispute.getStatus());
+
+        final Result result = requestBody(
+                "direct://ACCEPT",
+                createdDispute.getId()
+        );
+        assertNotNull("accept result", result);
+        assertTrue("accept result success", result.isSuccess());
+
+        final Dispute finalizedDispute = requestBody(
+                "direct://FIND",
+                createdDispute.getId()
+        );
+        assertNotNull("accepted dispute", finalizedDispute);
+        assertEquals(Dispute.Status.ACCEPTED, finalizedDispute.getStatus());
+    }
+
+    @Test
+    public void testAddFileEvidence() throws Exception {
+        Dispute createdDispute = createDispute();
+        assertEquals(Dispute.Status.OPEN, createdDispute.getStatus());
+        DocumentUpload uploadedDocument = uploadDocument();
+
+        final Map<String, Object> headers = new HashMap<String, Object>();
+        headers.put("CamelBraintree.disputeId", createdDispute.getId());
+        headers.put("CamelBraintree.documentId", uploadedDocument.getId());
+
+        final Result<DisputeEvidence>  result = requestBodyAndHeaders(
+                "direct://ADDFILEEVIDENCE",
+                null,
+                headers
+        );
+
+        assertNotNull("addFileEvidence result", result);
+        assertTrue("addFileEvidence result success", result.isSuccess());
+    }
+
+    @Test
+    public void testAddFileEvidenceOne() throws Exception {
+        Dispute createdDispute = createDispute();
+        assertEquals(Dispute.Status.OPEN, createdDispute.getStatus());
+        DocumentUpload uploadedDocument = uploadDocument();
+
+        final Map<String, Object> headers = new HashMap<String, Object>();
+        headers.put("CamelBraintree.disputeId", createdDispute.getId());
+        FileEvidenceRequest fileEvidenceRequest = new 
FileEvidenceRequest().documentId(uploadedDocument.getId());
+        headers.put("CamelBraintree.fileEvidenceRequest", fileEvidenceRequest);
+
+        final Result<DisputeEvidence> result = requestBodyAndHeaders(
+                "direct://ADDFILEEVIDENCE_1",
+                null,
+                headers
+        );
+
+        assertNotNull("addFileEvidence result", result);
+        assertTrue("addFileEvidence result success", result.isSuccess());
+    }
+
+    @Test
+    public void testAddTextEvidence() throws Exception {
+        final String textEvidence = "Text Evidence";
+
+        Dispute createdDispute = createDispute();
+        assertEquals(Dispute.Status.OPEN, createdDispute.getStatus());
+
+        final Map<String, Object> headers = new HashMap<String, Object>();
+        headers.put("CamelBraintree.id", createdDispute.getId());
+        headers.put("CamelBraintree.content", textEvidence);
+        final Result<DisputeEvidence> result = requestBodyAndHeaders(
+                "direct://ADDTEXTEVIDENCE",
+                null,
+                headers
+        );
+
+        assertNotNull("addTextEvidence result", result);
+        assertTrue("addTextEvidence result success", result.isSuccess());
+
+        DisputeEvidence disputeEvidence = result.getTarget();
+        assertEquals(textEvidence, disputeEvidence.getComment());
+    }
+
+    @Test
+    public void testAddTextEvidenceOne() throws Exception {
+        final String textEvidence = "Text Evidence";
+
+        Dispute createdDispute = createDispute();
+        assertEquals(Dispute.Status.OPEN, createdDispute.getStatus());
+
+        final Map<String, Object> headers = new HashMap<String, Object>();
+        headers.put("CamelBraintree.id", createdDispute.getId());
+        TextEvidenceRequest textEvidenceRequest = new 
TextEvidenceRequest().content(textEvidence);
+        headers.put("CamelBraintree.textEvidenceRequest", textEvidenceRequest);
+
+        final Result<DisputeEvidence> result = requestBodyAndHeaders(
+                "direct://ADDTEXTEVIDENCE_1",
+                null,
+                headers
+        );
+
+        assertNotNull("addTextEvidence result", result);
+        assertTrue("addTextEvidence result success", result.isSuccess());
+
+        DisputeEvidence disputeEvidence = result.getTarget();
+        assertEquals(textEvidence, disputeEvidence.getComment());
+    }
+
+    @Test
+    public void testFinalize() throws Exception {
+        Dispute createdDispute = createDispute();
+        assertEquals(Dispute.Status.OPEN, createdDispute.getStatus());
+
+        final Result result = requestBody(
+                "direct://FINALIZE",
+                createdDispute.getId()
+        );
+        assertNotNull("finalize result", result);
+        assertTrue("finalize result success", result.isSuccess());
+
+        final Dispute finalizedDispute = requestBody(
+                "direct://FIND",
+                createdDispute.getId()
+        );
+        assertNotNull("finalized dispute", finalizedDispute);
+        assertEquals(Dispute.Status.DISPUTED, finalizedDispute.getStatus());
+    }
+
+    @Test
+    public void testFind() throws Exception {
+        Dispute createdDispute = createDispute();
+        assertEquals(Dispute.Status.OPEN, createdDispute.getStatus());
+
+        final Dispute foundDispute = requestBody(
+                "direct://FIND",
+                createdDispute.getId()
+        );
+        assertNotNull("found dispute", foundDispute);
+        assertEquals(Dispute.Status.OPEN, foundDispute.getStatus());
+    }
+
+    @Test
+    public void testRemoveEvidence() throws Exception {
+        final String textEvidence = "Text Evidence";
+
+        Dispute createdDispute = createDispute();
+        assertEquals(Dispute.Status.OPEN, createdDispute.getStatus());
+
+        final Map<String, Object> addTextEvidenceHeaders = new HashMap<String, 
Object>();
+        addTextEvidenceHeaders.put("CamelBraintree.id", 
createdDispute.getId());
+        addTextEvidenceHeaders.put("CamelBraintree.content", textEvidence);
+
+        final Result<DisputeEvidence> addTextEvidenceResult = 
requestBodyAndHeaders(
+                "direct://ADDTEXTEVIDENCE",
+                null,
+                addTextEvidenceHeaders
+        );
+
+        assertNotNull("addTextEvidence result", addTextEvidenceResult);
+        assertTrue("addTextEvidence result success", 
addTextEvidenceResult.isSuccess());
+
+        DisputeEvidence disputeEvidence = addTextEvidenceResult.getTarget();
+        assertEquals(textEvidence, disputeEvidence.getComment());
+
+        final Map<String, Object> removeTextEvidenceHeaders = new 
HashMap<String, Object>();
+        removeTextEvidenceHeaders.put("CamelBraintree.disputeId", 
createdDispute.getId());
+        removeTextEvidenceHeaders.put("CamelBraintree.evidenceId", 
disputeEvidence.getId());
+
+        final Result removeTextEvidenceResult = requestBodyAndHeaders(
+                "direct://REMOVEEVIDENCE",
+                null,
+                removeTextEvidenceHeaders
+        );
+
+        assertNotNull("removeEvidence result", removeTextEvidenceResult);
+        assertTrue("removeEvidence result success", 
removeTextEvidenceResult.isSuccess());
+    }
+
+    @Test
+    public void testSearch() throws Exception {
+        Dispute createdDispute = createDispute();
+        assertEquals(Dispute.Status.OPEN, createdDispute.getStatus());
+
+        DisputeSearchRequest query = new 
DisputeSearchRequest().id().is(createdDispute.getId());
+        final PaginatedCollection<Dispute> result = requestBody(
+                "direct://SEARCH",
+                query
+        );
+
+        assertNotNull("search result", result);
+        for (Dispute foundDispute : result) {
+            assertEquals(createdDispute.getId(), foundDispute.getId());
+        }
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() {
+                // route to create transaction
+                from("direct://SALE")
+                        .to("braintree://" + TRANSACTION_PATH_PREFIX + 
"/sale?inBody=request");
+
+                // route to create documents
+                from("direct://CREATE")
+                        .to("braintree://" + DOCUMENT_UPLOAD_PATH_PREFIX + 
"/create?inBody=request");
+
+                // test route for accept
+                from("direct://ACCEPT")
+                    .to("braintree://" + PATH_PREFIX + "/accept?inBody=id");
+
+                // test route for addFileEvidence
+                from("direct://ADDFILEEVIDENCE")
+                    .to("braintree://" + PATH_PREFIX + "/addFileEvidence");
+
+                // test route for addFileEvidence
+                from("direct://ADDFILEEVIDENCE_1")
+                    .to("braintree://" + PATH_PREFIX + "/addFileEvidence");
+
+                // test route for addTextEvidence
+                from("direct://ADDTEXTEVIDENCE")
+                    .to("braintree://" + PATH_PREFIX + "/addTextEvidence");
+
+                // test route for addTextEvidence
+                from("direct://ADDTEXTEVIDENCE_1")
+                    .to("braintree://" + PATH_PREFIX + "/addTextEvidence");
+
+                // test route for finalize
+                from("direct://FINALIZE")
+                    .to("braintree://" + PATH_PREFIX + "/finalize?inBody=id");
+
+                // test route for find
+                from("direct://FIND")
+                    .to("braintree://" + PATH_PREFIX + "/find?inBody=id");
+
+                // test route for removeEvidence
+                from("direct://REMOVEEVIDENCE")
+                    .to("braintree://" + PATH_PREFIX + "/removeEvidence");
+
+                // test route for search
+                from("direct://SEARCH")
+                    .to("braintree://" + PATH_PREFIX + "/search?inBody=query");
+
+            }
+        };
+    }
+
+    private Dispute createDispute() {
+        return createDispute(100.00);
+    }
+
+    private Dispute createDispute(double amount) {
+        final Result<Transaction> transactionResult = requestBody(
+                "direct://SALE",
+                new TransactionRequest()
+                        .amount(new BigDecimal(amount))
+                        .paymentMethodNonce("fake-valid-nonce")
+                        .creditCard()
+                            .number("4023898493988028")
+                        .done()
+                        .options()
+                            .submitForSettlement(true)
+                        .done(),
+                Result.class);
+
+        assertTrue(transactionResult.isSuccess());
+        List<Dispute> disputes = transactionResult.getTarget().getDisputes();
+        assertListSize(disputes, 1);
+        return disputes.get(0);
+    }
+
+    private DocumentUpload uploadDocument() {
+        final String documentName = "pdf-sample.pdf";
+
+        File evidenceDocument = new 
File(getClass().getClassLoader().getResource(documentName).getPath());
+        DocumentUploadRequest documentUploadRequest = new 
DocumentUploadRequest(
+                DocumentUpload.Kind.EVIDENCE_DOCUMENT,
+                evidenceDocument
+        );
+        final Result<DocumentUpload> documentUploadResult = requestBody(
+                "direct://CREATE",
+                documentUploadRequest
+        );
+        assertNotNull("create result", documentUploadResult);
+        assertTrue("create result success", documentUploadResult.isSuccess());
+        return documentUploadResult.getTarget();
+    }
+}
diff --git 
a/components/camel-braintree/src/test/java/org/apache/camel/component/braintree/DocumentUploadGatewayIntegrationTest.java
 
b/components/camel-braintree/src/test/java/org/apache/camel/component/braintree/DocumentUploadGatewayIntegrationTest.java
new file mode 100644
index 00000000000..e392ceef2ee
--- /dev/null
+++ 
b/components/camel-braintree/src/test/java/org/apache/camel/component/braintree/DocumentUploadGatewayIntegrationTest.java
@@ -0,0 +1,70 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.braintree;
+
+import java.io.File;
+
+import com.braintreegateway.DocumentUpload;
+import com.braintreegateway.DocumentUploadRequest;
+import com.braintreegateway.Result;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.braintree.internal.BraintreeApiCollection;
+import 
org.apache.camel.component.braintree.internal.DocumentUploadGatewayApiMethod;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DocumentUploadGatewayIntegrationTest extends 
AbstractBraintreeTestSupport {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(DocumentUploadGatewayIntegrationTest.class);
+    private static final String PATH_PREFIX = 
BraintreeApiCollection.getCollection().getApiName(DocumentUploadGatewayApiMethod.class).getName();
+
+    @Test
+    public void testCreate() throws Exception {
+        final String documentName = "pdf-sample.pdf";
+
+        File evidenceDocument = new 
File(getClass().getClassLoader().getResource(documentName).getPath());
+        DocumentUploadRequest documentUploadRequest = new 
DocumentUploadRequest(
+                DocumentUpload.Kind.EVIDENCE_DOCUMENT,
+                evidenceDocument
+        );
+
+        final Result<DocumentUpload> result = requestBody(
+                "direct://CREATE",
+                documentUploadRequest
+        );
+
+        assertNotNull("create result", result);
+        assertTrue("create result success", result.isSuccess());
+
+        DocumentUpload documentUpload = result.getTarget();
+        assertEquals(documentName, documentUpload.getName());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() {
+                // test route for create
+                from("direct://CREATE")
+                    .to("braintree://" + PATH_PREFIX + 
"/create?inBody=request");
+
+            }
+        };
+    }
+}
diff --git a/components/camel-braintree/src/test/resources/pdf-sample.pdf 
b/components/camel-braintree/src/test/resources/pdf-sample.pdf
new file mode 100644
index 00000000000..f698ff53d41
Binary files /dev/null and 
b/components/camel-braintree/src/test/resources/pdf-sample.pdf differ


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Expose Braintree Dispute API
> ----------------------------
>
>                 Key: CAMEL-12138
>                 URL: https://issues.apache.org/jira/browse/CAMEL-12138
>             Project: Camel
>          Issue Type: New Feature
>          Components: camel-braintree
>            Reporter: Russ Johnson
>            Assignee: Andrea Cosentino
>            Priority: Major
>             Fix For: 2.22.0
>
>
> Braintree's Dispute API, described here: 
> https://developers.braintreepayments.com/reference/response/dispute/java, is 
> not currently exposed in the Braintree Component.
> The intention of this ticket is to expose the Braintree Dispute API in the 
> Component.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to