GithubHelp home page GithubHelp logo

braintree / braintree_java Goto Github PK

View Code? Open in Web Editor NEW
155.0 98.0 96.0 6.21 MB

Braintree Java library

Home Page: https://developer.paypal.com/braintree/docs/start/overview

License: MIT License

Shell 0.01% Ruby 0.06% Java 99.92% Makefile 0.01% Dockerfile 0.01%
braintree java payments

braintree_java's Introduction

Braintree Java library

The Braintree Java library provides integration access to the Braintree Gateway.

Please Note

The Payment Card Industry (PCI) Council has mandated that early versions of TLS be retired from service. All organizations that handle credit card information are required to comply with this standard. As part of this obligation, Braintree is updating its services to require TLS 1.2 for all HTTPS connections. Braintree will also require HTTP/1.1 for all connections. Please see our technical documentation for more information.

Dependencies

  • none

Java version >= 8 is required. The Braintree Java SDK is tested against Java versions 8 and 11.

Versions

Braintree employs a deprecation policy for our SDKs. For more information on the statuses of an SDK check our developer docs.

Major version number Status Released Deprecated Unsupported
3.x.x Active June 2020 TBA TBA
2.x.x Inactive April 2010 June 2022 June 2023

Documentation

Updating from an Inactive, Deprecated, or Unsupported version of this SDK? Check our Migration Guide for tips.

Quick Start Example

import java.math.BigDecimal;
import com.braintreegateway.*;

public class BraintreeExample {
    public static void main(String[] args) {
        BraintreeGateway gateway = new BraintreeGateway(
            Environment.SANDBOX,
            "the_merchant_id",
            "the_public_key",
            "the_private_key"
        );

        TransactionRequest request = new TransactionRequest()
            .amount(new BigDecimal("1000.00"))
            .paymentMethodNonce(nonceFromTheClient)
            .options()
                .submitForSettlement(true)
                .done();

        Result<Transaction> result = gateway.transaction().sale(request);

        if (result.isSuccess()) {
            Transaction transaction = result.getTarget();
            System.out.println("Success!: " + transaction.getId());
        } else if (result.getTransaction() != null) {
            Transaction transaction = result.getTransaction();
            System.out.println("Error processing transaction:");
            System.out.println("  Status: " + transaction.getStatus());
            System.out.println("  Code: " + transaction.getProcessorResponseCode());
            System.out.println("  Text: " + transaction.getProcessorResponseText());
        } else {
            for (ValidationError error : result.getErrors().getAllDeepValidationErrors()) {
               System.out.println("Attribute: " + error.getAttribute());
               System.out.println("  Code: " + error.getCode());
               System.out.println("  Message: " + error.getMessage());
            }
        }
    }
}

Maven

With Maven installed, this package can be built simply by running this command:

 mvn package

The resulting jar file will be produced in the directory named "target".

In repositories:

 Maven Central, which should be enabled by default. No additional repositories are required.

In dependencies

<dependency>
  <groupId>com.braintreepayments.gateway</groupId>
  <artifactId>braintree-java</artifactId>
  <version>PUT VERSION NUMBER HERE</version>
</dependency>

Development

See our development notes.

Open Source Attribution

A list of open source projects that help power Braintree can be found here.

License

See the LICENSE file.

braintree_java's People

Contributors

aaomidi avatar aghareza avatar beane avatar benbenw avatar billwerges avatar bmcdonnel avatar braintreeps avatar chrissiedunham avatar crookedneighbor avatar csbraintree avatar dan-manges avatar demerino avatar dougbradbury avatar edebill avatar iainmaitland88 avatar jbrower2 avatar jonjchew avatar joshuaknox avatar juwlee avatar kate-paypal avatar lalayang avatar lkorth avatar matthewarkin avatar pgr0ss avatar sehrope avatar skunkworks avatar sonianigam avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

braintree_java's Issues

RiskData decision should be an enum

The RiskData class has a decision that is one of a few values. These values should be enum values instead of arbitrary strings.

This would be a breaking change to override the decision property directly, but it could be converted to an enum field with a delegating getter.

Use of the sandbox Fraud credit card (4000 1111 1111 1511) lead to an exception

using the last braintree lib and the credit card here :

https://www.braintreepayments.com/docs/ruby/reference/sandbox#fraud_information

java.lang.IllegalArgumentException: No enum const class com.braintreegateway.Transaction$GatewayRejectionReason.UNRECOGNIZED
    at java.lang.Enum.valueOf(Enum.java:214)
    at com.braintreegateway.util.EnumUtils.findByName(EnumUtils.java:12)
    at com.braintreegateway.CreditCardVerification.<init>(CreditCardVerification.java:33)
    at com.braintreegateway.Result.<init>(Result.java:46)
    at com.braintreegateway.CreditCardGateway.update(CreditCardGateway.java:118)
    at com.x.web.server.billing.BraintreeProvider.setCreditCardInternal(BraintreeProvider.java:539)

Possible NullPointerException during UsBankAccount instantiation

General information

  • SDK/Library version: 2.68.0 to 2.76.1-SNAPSHOT
  • Environment: Sandbox
  • Java, 1.8.0_111-b14, and Fedora 26

Possible NullPointerException during UsBankAccount instantiation

I have found that constructor of the class com.braintreegateway.UsBankAccount adds subscription objects to an uninitialized list

public UsBankAccount(NodeWrapper node) {
    this.routingNumber= node.findString("routing-number");
    this.last4 = node.findString("last-4");
    this.accountType = node.findString("account-type");
    this.accountHolderName = node.findString("account-holder-name");
    this.token = node.findString("token");
    this.imageUrl = node.findString("image-url");
    this.bankName = node.findString("bank-name");
    for (NodeWrapper subscriptionResponse : node.findAll("subscriptions/subscription")) {
       // Here is the place where NullPointerException can be thrown
        this.subscriptions.add(new Subscription(subscriptionResponse));
    }
    this.customerId = node.findString("customer-id");
    this.isDefault = node.findBoolean("default");
    this.achMandate = new AchMandate(node.findFirst("ach-mandate"));
}

In other places, like CoinbaseAccount, a for-loop is proceded with list initialization like this

this.subscriptions = new ArrayList<Subscription>();

Replace org.json with a friendly licensed JAR

In the 2.73.0 release there was this big commit that added org.json.json JAR dependency
7497c18

Its only used in one class, Http, where the JSONObject class is used.

As org.json has a special license that is not business friendly its has been deemed x-category at Apache Software Foundation and cannot be used whatsoever.
https://www.apache.org/legal/resolved.html#json

I wonder if braintree-java can look into using another small JSon library, like simplejson, or even jackson etc.

If not then we would have to remove camel-braintree from Apache Camel going forward in the future. Or stop at version 2.72.0 which was the last version of braintree-java that does not use org.json
https://issues.apache.org/jira/browse/CAMEL-12180

Exception message is always null when Http status code is checked in Http#httpRequest()

General information

  • SDK/Library version: 2.72.0 but also present in 2.83.0
  • Environment: all
  • Language, language version, and OS: Java 1.8

Issue description

When Http#throwExceptionIfErrorStatusCode(int code, String message) is called in Http#httpRequest(), the message parameter is always null as seen here: https://github.com/braintree/braintree_java/blob/master/src/main/java/com/braintreegateway/util/Http.java#L150

This leads to difficult debugging due to a lack of information when attempting to access the thrown exception's message via Exception#getMessage(), particularly when the exception is an AuthorizationException, whose message is set to the variable decodedMessage, which is initialised to null and its value is only set if message is not null.
See https://github.com/braintree/braintree_java/blob/master/src/main/java/com/braintreegateway/util/Http.java#L384 and https://github.com/braintree/braintree_java/blob/master/src/main/java/com/braintreegateway/util/Http.java#L399

We encountered this today in our system when changes to our merchant account and public/private keys resulted in HTTP 403 errors in requests to generate client tokens.

We log results with a log statement similar to
log.error("Failed to get BraintreeToken. Error message: {}", e.getMessage());
which obviously was not very helpful in debugging.

One solution would be to pass the request's responseMessage from HttpURLConnection#getResponseMessage() to the call to throwExceptionIfErrorStatusCode(int, String), however that may not work well with the URLDecoder#decode() performed on message.

Is there a way to find default MerchantAccount?

Method gateway.merchantAccount().find(merchantAccountId) requires non-empty merchantAccount to get MerchantAccount object back. For default accounts we do not keep merchantAccount in configuration settings (as it is not required for transaction operations).
So my question is : How can I get a MerchantAccount object from Braintree API for default merchant account?

I understand that I can get it using merchant account id associated with default merchant account but is there a way to get it if I do not have id of default merchant account?

MerchantAccount defaultAccount = gateway.merchantAccount().find(null)?
MerchantAccount defaultAccount = gateway.merchantAccount().default()?

Request a test WebhookNotification from BraintreeGateway in sandbox mode

I'm currently discovering that Webhook-Testing is not very well supported yet.

I wonder if it would be possible to get a real Webhook message object from the BraintreeClient in the future.

Instead of sending the Webhook notification to a publicly visible server http://example.com/bt/subscription why not create it in the sandbox, receive it locally and then forward it to http://localhost:8080/bt/subscription?

private final static BraintreeGateway BT; // Gateway instance

public void subscriptionWentActiveTest() {

    // Create customer ..
    // Create payment method (credit card) ..
    // Create a subscription ..

    SubscriptionRequest subscriptionRequest = new SubscriptionRequest()
            .paymentMethodToken(creditCard.getToken())
            .planId("plan_id");

    Result<Subscription> createSubscriptionResult = BT.subscription().create(subscriptionRequest);
    Subscription subscription = createSubscriptionResult.getTarget();

    // Create and receive a webhook notification

    WebhookNotification webhookNotification = BT.webhookTesting()
            // Creates a 'real' fake notification having set all values
            // from the subscription, add-ons, etc.
            .createNotification(
                WebhookNotification.Kind.SUBSCRIPTION_WENT_ACTIVE, 
                subscription.getId()
            );

    // Forward the notification to the locally running server ..
    this.forwardNotification("/bt/subscription", webhookNotification);
}

Is something like this possible?

generate(ClientTokenRequest request) accepting "null" value for customerId

I am not entirely sure why this is the case but

ClientTokenRequest clientTokenRequest = new ClientTokenRequest()
        .customerId(null);

return BT.clientToken().generate(clientTokenRequest);

does create a server token. I did not test if I can use this token actually but shouldn't there be an error message saying that this user does not exist in my vault?

Null Transaction even if gateway returns a successful results

I am trying out this library (braintree-java, version 2.66), and I have noticed an issues/ problems earlier:

  1. My situation is:
  2. Assume that we have a gateway built using marchantId, private and public key
  3. Assume that we have a valid client nonce
  4. Here is my code, and my question follows:

TransactionRequest trRequest = new TransactionRequest().amount(10)
.paymentMethodNonce(clientNonce).options().submitForSettlement(true).done();
Result result = gateway.transaction().sale(trRequest);
if(result.isSuccess()){
Transaction transaction = result.getTransaction();
//From here I want to access other things from transaction
//such as transactionId so that I can keep a record of this transaction just in case.
}

I have tested this code and it seems to be working (I can see transactions updated in my sandbox account). However, the problem I am facing is that the transaction object in the if block is null. Am I doing something wrong here? My understanding is that if the result was successful then we would have a way to access the underlying transaction object, and it shouldn't be null.

Thank you.

Create a new Plan

I'd like to create new Plans via the API - that would be a great feature.

Braintree API returning invalid currency scale

I'm testing my app with the Sandbox API.

If I issue a transaction for 3 JPY, the Braintree API will send me back a success response containing "3.00 JPY". This is an error, because Japanese Yen can't have decimal points.

For example:

Result<Transaction> result =
        braintreeGateway.transaction().sale(
            new TransactionRequest()
                .amount(new BigDecimal("3"))
                .paymentMethodNonce("omg-im-a-nonce")
                .merchantAccountId("jpy-merchant-account")
                .options()
                    .submitForSettlement(true)
                    .done());
Transaction transaction = result.getTarget();
Money.of(CurrencyUnit.of(transaction.getCurrencyIsoCode()), transaction.getAmount());

Causes:

java.lang.ArithmeticException: Scale of amount 3.00 is greater than the scale of the currency JPY
    at org.joda.money.Money.of(Money.java:74)

Invalid SSL certificate

I'm getting the following error when using the library in SANDBOX env:

sun.security.validator.ValidatorException: PKIX path validation failed: java.security.cert.CertPathValidatorException: Path does not chain with any of the trust anchors

Braintree version: 2.19.0
Java version: 1.7.0_10-ea

Name is null for Add-On

The name is null only when I get add-ons from the subscriptions. For example (scala):

for ( sub <- gateway.creditCard().find( "token" ).getSubscriptions )
for ( addOn <- sub.getAddOns )
println( addOn.getName )

The names are not null if I get them all directly via gateway.addOn().all

I am trying to do Braintree encrytion in java using braintree-android-encryption-1.0.0.jar downloaded from https://www.braintreepayments.com/docs/android

and i get the below error .Could some one please assist.

java.security.InvalidKeyException: Illegal key size
at javax.crypto.Cipher.a(DashoA13_..)
at javax.crypto.Cipher.a(DashoA13_..)
at javax.crypto.Cipher.a(DashoA13_..)
at javax.crypto.Cipher.init(DashoA13_..)
at javax.crypto.Cipher.init(DashoA13*..)
at com.braintreegateway.encryption.Aes.encrypt(Aes.java:42)
at com.braintreegateway.encryption.Aes.encrypt(Aes.java:34)
at com.braintreegateway.encryption.Braintree.encrypt(Braintree.java:23)
at com.equinoxfitness.levelup.service.BraintreeExample.main(BraintreeExample.java:9)

Thanks in advance !!

Change log level

How do I change the log level? I'd like it to be set to Level.FINE so that I can see the response codes for all requests, and I attempted to do this using the following snippet:

BraintreeGateway gateway = new BraintreeGateway(Environment.SANDBOX,
    BTMerchantAccountID,
    BTPublicKey,
    BTPrivateKey);
gateway.getConfiguration().getLogger().setLevel(Level.FINE);

However, this did not work, and I still only saw logs with level >= Level.INFO. Would be grateful for a solution.

equals() and hashCode() methods are missing in classed provided by SDK

General information

  • SDK/Library version: 2.27.2 and any previous version
  • Environment: N/A
  • Language, language version, and OS: Any version of Java and any OS

Issue description

Looks like equals() and hashCode() methods are not available for classes provided by SDK. It makes integration and unit testing much harder, as custom assertions/matchers are needed to check for example if com.braintreegateway.Trasanction instance contains all necessary data.
Currenlty to assert an object state I have to implement customer Hamcrest matcher, create long list of assertions (what is not the best idea from test design or good practices perspective) or use additional tools to perform reflection based comparison.
Adding implementation for equals() and hashCode() methods will simplify testing process.

com.braintreegateway.exceptions.UnexpectedException: Invalid argument

I'm frequently getting the following exception:

com.braintreegateway.exceptions.UnexpectedException: Invalid argument
    at com.braintreegateway.util.Http.httpRequest(Http.java:92)
    at com.braintreegateway.util.Http.httpRequest(Http.java:63)
    at com.braintreegateway.util.Http.get(Http.java:43)
    at com.braintreegateway.CustomerGateway.find(CustomerGateway.java:99)

The exception is thrown by:

throwExceptionIfErrorStatusCode(connection.getResponseCode(), null);

at Http.java line 78. I'm using version 2.22.1

The exception is intermittent: sometimes it works, some other times doesn't.

Inability to change read or connection timeouts

It appears that the read timeout is hard coded in the com.braintreegateway.util.Http. buildConnection(...), line 177.

Unfortunately, 1 minute timeouts are unacceptable with the project with which I am using this client. I'm assuming it would have the most usability to have this default value put in the Configuration object with the ability to change it if needed.

braintree AuthorizationException

If i pass merchantAccountId in the request it throws an exception but if you dont it doesnt happen.
I think either error message should be more clear or it should just accept the merchantAccountId.
TransactionRequest request = new TransactionRequest()
.amount(new BigDecimal(""+amount)).
merchantAccountId("testdfcc2f3w26rdff")

Exception in thread "main" com.braintreegateway.exceptions.AuthorizationException
at com.braintreegateway.util.Http.throwExceptionIfErrorStatusCode(Http.java:196)
at com.braintreegateway.util.Http.httpRequest(Http.java:94)
at com.braintreegateway.util.Http.post(Http.java:56)
at com.braintreegateway.TransactionGateway.sale(TransactionGateway.java:105)
at com.mobiletopup.service.paymentgateway.BraintreePaymentService.takePayment(BraintreePaymentService.java:154)
at com.mobiletopup.service.paymentgateway.BraintreePaymentService.main(BraintreePaymentService.java:90)

Get CVV from object CreditCard

After CreditCardRequest is processed successfully for a customerId with CVV, cardHolderName, number etc, I want CreditCard to provide CVV, number later. How can I achieve that, so that I can make a TransactionRequest with already added CreditCard?

Snippet of my code is :

def defaultCreditCard =  getDefaultCreditCard(merchant)
TransactionRequest encourageTransaction = new TransactionRequest()
                                                   .amount(invoiceToEncourage.subtotal)
                                                   .creditCard()
                                                   .number("4111111111111111") //get it from default CreditCard
                                                   .cvv("111") //get it from default CreditCard
                                                   .expirationMonth(defaultCreditCard.getExpirationMonth())
                                                   .expirationYear(defaultCreditCard.getExpirationYear())
                                                   .done()
         Result<Transaction> result = gateway.transaction().sale(encourageTransaction);

HTTP 406 on find/delete customer in Sandbox

I'm not sure if this is just an issue with the sandbox but periodically when our integration tests run we get this exception:
com.braintreegateway.exceptions.UnexpectedException: Unexpected HTTP_RESPONSE 406

Customer customer = gateway.customer().find("the_customer_id");

When it should be a NOT_FOUND exception.

Are any others getting this exception? Should I bring this up with braintree support?

Interactions with MerchantAccountGateway are hard to test because class is marked as final.

General information

  • SDK/Library version: 2.81.1
  • Environment: N/A
  • Language, language version, and OS: Any version of Java and any OS

Issue description

The class com.braintreegateway.MerchantAccountGateway has been marked as final, what makes it pretty hard to use in tests.
As I can see it's the only gateway class that has been implemented in that way. Is there any specific reason for that? If not could you please change this, as without using additional libraries that can mock MerchantAccountGateway object through reflection it is pretty hard to write tests which include this gateway in the flow.

Null Pointer Exception for existing user in sandbox

I'm getting this error when trying to retrieve an existing user from the sandbox.

java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
...
Caused by: java.lang.reflect.InvocationTargetException
...
Caused by: java.lang.NullPointerException
    at com.braintreegateway.CreditCard.getPayroll(CreditCard.java:299)
    ...

with this Clojure code:

(def gateway (new BraintreeGateway Environment/SANDBOX
    "xxx"
    "xxx"
    "xxx"))
(defpage [:post "/btreeuser"] {:keys [userid securitytag]}
  (if
    (and
      (not
        (nil? userid))
      (= "xxx" securitytag))
    (try
      (let [user (from-java
        (.. gateway customer (find userid)))]
      (response/json {:success true
                                :user user}))
      (catch com.braintreegateway.exceptions.NotFoundException e
        (response/json {:success false
                                  :msg "Not Found"})))
   (response/json {:success false})))

I'm 99% sure I haven't changed any relevant code since the last time it worked.
I'm using noir (defpage) if that matters and the exception catches successfully if the user doesn't exist.
Using lib v2.18.0

Java API improvements - provide access to subobjects in builders

I have found myself writing wrapper classes like this the following scala class to expose the sub-objects that are created in methods like creditCard() and billingAddress.

/**
 * Created 3/25/12 5:38 PM
 *
 * @author donohoe
 * @since 1.0
 *
 * Extension to keep track of items created so they can be modified after initial creation (overcomes limitation
 * in BT API).  Created for testing, but may be useful in the future.
 */

class BraintreeTransactionRequest extends TransactionRequest
{
  private var _lastCreditCard: TransactionCreditCardRequest = _
  private var _lastBillingAddress: TransactionAddressRequest = _

  def lastCreditCard = _lastCreditCard

  def lastBillingAddress = _lastBillingAddress

  override def creditCard() =
  {
    _lastCreditCard = super.creditCard()
    _lastCreditCard
  }

  override def billingAddress() =
  {
    _lastBillingAddress = super.billingAddress()
    _lastBillingAddress
  }

}

I had to do this because our code creates template Braintree transactions where we do typical boilerplate setup. Our desire is that callers can tweak whatever settings they wish. However, new subobjects are created due to code like this:

   public TransactionCreditCardRequest creditCard() {
        creditCardRequest = new TransactionCreditCardRequest(this);
        return creditCardRequest;
    }

There is no way to get back at the creditCardRequest after it has been created - each time one callscreditCard(), a new one is created, replacing the prior one.

I've had to wrap TransactionCreditCardRequest and TransactionRequest so far.

The purpose of this request is to enhance the builders to provide access to the already created subobjects.

I am integrating braintree gateway in my code, so ica

General information

I am integrating braintree gateway in my code, so i create maven project and add braintree dependency 2.46.0 in code, at compile time its not giving any issue but on time is giving following exception

  • SDK/Library version: 2.46.0
  • Environment: Sandbox
  • Language, language version, and OS: Java 1.7.0_60 on window 7

Issue description

Caused by: java.lang.ExceptionInInitializerError
	at com.braintreegateway.BraintreeGateway.<init>(BraintreeGateway.java:56)
	at com.bdbizviz.yujaa.services.impl.YujaaServicesImpl.<clinit>(YujaaServicesImpl.java:1516)
	at com.bdbizviz.yujaa.services.activator.YujaaServicesActivator.start(YujaaServicesActivator.java:19)
	at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:645)
	at org.apache.felix.framework.Felix.activateBundle(Felix.java:2146)
	... 22 more
Caused by: java.lang.NullPointerException

Add support for client-side encryption

I have a Java application that needs to securely transmit credit card information to Braintree. However, this application runs on untrusted machines; it has no business interfacing with Braintree directly, and it should never be exposed to any Braintree API credentials.

This situation is exactly analogous to a web browser in a normal web application. Braintree has already addressed this use case with client-side encryption. Unfortunately, client-side encryption appears to have only one implementation and has no public specification. Therefore, my options are:

  1. Ask Braintree to add client side encryption to the Java client
  2. Ask Braintree for a client side encryption specification
  3. Embed Braintree.js along with a JavaScript interpreter and interface with it as needed
  4. Re-implement client-side encryption using Braintree.js as a reference, hope I don't make any mistakes, and hope nothing changes on the other end

So... could you add client-side encryption to the Braintree Java client? Alternately, could you publish a specification and maybe add some kind of validation tool in the sandbox?

invalid transaction amount format issue

Service gateway returns me a TRANSACTION_AMOUNT_FORMAT_IS_INVALID if I pass a float decimal number.

TransactionRequest request = new TransactionRequest()
.amount(new BigDecimal(0.10f));

this returns TRANSACTION_AMOUNT_FORMAT_IS_INVALID where as

TransactionRequest request = new TransactionRequest()
.amount(new BigDecimal("0.10"));

returns a Approved, SUBMITTED_FOR_SETTLEMENT value.

this is how request parameter looks if you pass a float number
transaction[amount]=0.100000001490116119384765625

Version 2.57.0 breaks on Google AppEngine

Hi,

you have added logging support, but you used restricted class "java.util.logging.ConsoleHandler" on Google AppEngine, so this library does not work, it is not possible to override or do anything to be able to use 2.57.0 on AppEngine. Version 2.56.0 still works on AppEngine.

Please add support for constructor BraintreeGateway for passing Logger instead of static initialisation with new ConsoleHandler() in Configuration.

Dean

Please add currencyIsoCode to MerchantAccount

The class MerchantAccount does not provide access to the information of the merchant account's assigned currency (although is included in the source NodeWrapper in node currency-iso-code).

Would be great to have access to this information in order to implement some validation checks in the code. Thanks!

Missing constant in Reason enum

The client throws the following error when fetching a transaction.

No enum constant com.braintreegateway.Dispute.Reason.UNRECOGNIZED

There is no "UNRECOGNIZED" constant defined in Reason enum.

Kind Regards

Hanging in Http class

I have some code that is working on my local dev systems (Ubuntu,
Windows), but isn't working on my digital ocean server.

On the page where I generate the client token, it requests via the
gateway a new client token, and it hangs internally doing this.

I've managed to trace it down to:

sslContext.init((KeyManager[]) kmf.getKeyManagers(), tmf.getTrustManagers(), SecureRandom.getInstance("SHA1PRNG"));
(line 230 in Http class)

However when I try to go any deeper it simply hangs.

Is this a known issue? How may I work around this?

Source code is not java 1.5 compliant

Some merchants with old but robust and big stacks might be using java 1.5 still in their servers.
They would fail to import the jars or recompile the code.
Could we provide a Java 1.5 compliance code? (current requires 1.6). Only RequestBuilder and Environment need to be slightly changed.

Support for configuring connection timeout

Support for configuring connection timeout

  • SDK/Library version: 2.73.0
  • Environment: Sandbox and Production
  • Language, language version, and OS: Java 1.8

Braintree does not currently set a connection timeout in its Java SDK

Braintree Java SDK currently sets only request timeout value. We would like to set the connection timeout value as well.

Below is the email thread related to the above request

Dustin (Braintree)
Dec 18, 12:49 PM CST 

Vinai,

Thanks for the clarification.  

Currently, Braintree does not currently set a connection timeout in our SDK.  The only timeout that is set is the read timeout, as previously mentioned.

I apologize for the inconvenience, but feel free to open a feature request if this is something that is causing an issue on your end.Cheers,Dustin

⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼

Kari (Braintree)
Dec 17, 4:39 PM CST

Hey Vinai,

Thanks for writing back in.

I reached out to a specialized team here at Braintree in order to see what options we could offer you. For clarification, I'd like to ensure that we understand your goal. Are you looking to adjust the timeframe of incoming data sent to your website or are you looking to adjust the time where outgoing data is being sent to Braintree from your website? Once they've gotten the chance to review your request, they'll reach out to you with any relevant information they might find.

Kindest Regards,

Kari
Braintree

⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼

Arunachalam, Vinai
Dec 15, 1:06 PM CST

Hi Casey,

Thanks for the details. I was able to find the read timeout details and the recommendation to not set the read timeout myself.

My question is not about read timeout. I would like to know how the connect timeout value is set and how to configure it. By looking into the Java SDK I found that Braintree is using URLConnection. But I couldn’t find how the connect timeout value is set in the code for the URLConnection.

The timeout value that we set in the configuration is used only to set the read timeout value. I see the below code in com.braintreegateway.util.Http
connection.setReadTimeout(configuration.getTimeout());

I am looking for something like
connection.setConnectTimeout….

I tried my best to explain my question in a better way. Please let me know if it is still not clear or if you need more details.

Thank you.
Vinai

⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼

Casey C. (Braintree)
Dec 15, 3:57 AM CST

Hi Vinai,

Thanks for reaching out to us. Happy to help out here.

The article that you linked me contains the code needed to set the timeout. In the article linked, it contains this code:
private static BraintreeGateway gateway = new BraintreeGateway(
Environment.SANDBOX,
"your_merchant_id",
"your_public_key",
"your_private_key"
);

gateway.configuration.setTimeout(10000);

This will timeout your API requests in 10000ms. I've tested this code and it does work successfully, throwing the timeout error.

The default timeout is 60 seconds. To be frank, however, I do not recommend setting a custom timeout. The timeout is thrown on your server's side, but Braintree will still process the API request. For example, if you set your timeout for 10 seconds and then issue a Braintree_Transaction::sale() API request, but the transaction takes more than 10 seconds to process, the transaction will still be completed. Your server will not receive the successful response, as the function already closes with a timeOutError.

I hope this clarifies everything! If you have any other questions, don't hesitate to reach back out!

Warmest Regards,

Casey C.
Braintree
⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼

Arunachalam, Vinai
Dec 14, 5:28 PM CST
Name: Vinai Arunachalam
Business Email: [email protected]
Business Name: Xoom
Message: Hi,
I would like to know how to configure the connection timeout. We are using the braintree Java SDK.
The link below explains only about the read timeout
https://developers.braintreepayments.com/reference/general/best-practices/java#timeouts
We would like to how to set the connection timeout value. Right it looks like the connection timeout value is around 120 seconds. But I couldn't find where this value was set in the Java SDK and don't know how to change it.
A code snippet that explains how to set this connection timeout value or any link to documents that explain this in detail would be very helpful.
Thank you.
Vinai
Environment: Sandbox
Referrer: https://developers.braintreepayments.com/reference/general/best-practices/java

SubscriptionRequest class should reuse the internal request objects instead of re-creating them each time

public class SubscriptionRequest extends Request {

    private ModificationsRequest discountsRequest;

    [...]
    public ModificationsRequest discounts() {
        discountsRequest = new ModificationsRequest(this, "discounts");
        return discountsRequest;
    }

    [...]
}

In the snippet above, we have this instance variable discountsRequest that is re-init each time one calls the method discounts(). The first call should definitely create a new ModificationsRequest but the subsequent calls should re-use it instead of creating another one. This behavior is definitively not intuitive and lead to a gentle developer wasting his time trying to figure out why the hell the discounts are not set as they should after calling multiple time the method discounts and doing stuff on it.

The work-around for this is to call the discounts once and then do my stuff on it.

Maybe there are reasons as to why you do that.

This issue is also true for other ModificationsRequest variables in this Class (descriptorRequest, options, addOnsRequest).

Thank you

Braintree JS SDK in sandbox iframe

Forgive me if this is not the proper place to file this bug.

If I try to embed the 'dropin' Braintree JS SDK v2 in an iframe with the HTML5 sandbox attribute (for bidirectional security), then the browser will raise an error saying that the script is accessing document.cookie to write a value named 'venmo' or something. Even though I'm not using Venmo.

A workaround exists, which is to host the iframe on a separate domain, so cross-origin browser security policies kick in. But it would simplify production systems management if the braintree iframe were able to be hosted inside a sandbox.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.