Repository: braintree/braintree-web-drop-in (js)

Issue:
Add a method to Drop-in UI to return supported payment types
### General information

* SDK/Library version: 1.22.0
* Environment: Sandbox and Production
* Browser and OS: any browser

### Feature request

I have a requirement to be able to detect whether or not Venmo is supported on the client browser, in order to provide further instructions to the user.  This would be useful for any other payment method as well.

I currently use a workaround where I check an array within "clientInstance" parameter, however this is not guaranteed to work with future releases.

`clientInstance._mainView.paymentMethodsViews.model.supportedPaymentOptions.includes('venmo')`

Please add a method like "clientInstance.isSupportedPaymentMethod(_paymentMethod_)".

See support ticket #2723511 for reference.

Pull request:
Add method to return the available payment options
closes #594

### Summary

Presents an array of payment options that have been presented to the customer.

### Checklist

- [x] Added a changelog entry

### Authors
> List GitHub usernames for everyone who contributed to this pull request.

- @crookedneighbor 


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fd6428b..6fc9c15 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,7 @@ unreleased
 - Update @braintree/event-emitter to v0.4.0
 - Update @braintree/wrap-promise to v2.1.0
 - Fix issue where `threeDSecureInfo` was not included in `requestPaymentMethod` payload
+- Add `getAvailablePaymentOptions` method to list what payment options have been presented to the customer (closes #594)
 - Add support for the shadow DOM for the card view
 
 1.23.0
diff --git a/src/dropin.js b/src/dropin.js
index bf04662..be17010 100644
--- a/src/dropin.js
+++ b/src/dropin.js
@@ -440,6 +440,28 @@ Dropin.prototype.updateConfiguration = function (property, key, value) {
   this._navigateToInitialView();
 };
 
+/**
+ * Get a list of the available payment methods presented to the user. This is useful for knowing if a paricular payment option was presented to a customer that is browser dependant such as Apple Pay, Google Pay and Venmo. Returns an array of strings. Possible values:
+ * * `applePay`
+ * * `card`
+ * * `googlePay`
+ * * `paypalCredit`
+ * * `paypal`
+ * * `venmo`
+ *
+ * @public
+ * @returns {string[]} An array of possible payment options.
+ * @example
+ * var paymentOptions = dropinInstance.getAvailablePaymentOptions(); // ['card', 'venmo', 'paypal']
+ *
+ * if (paymentOptions.includes('venmo')) {
+ *   // special logic for when venmo is displayed
+ * }
+ */
+Dropin.prototype.getAvailablePaymentOptions = function () {
+  return this._model.supportedPaymentOptions;
+};
+
 /**
  * Removes the currently selected payment method and returns the customer to the payment options view. Does not remove vaulted payment methods.
  * @public


Test patch:
diff --git a/test/unit/dropin.js b/test/unit/dropin.js
index 4fb2129..55171a0 100644
--- a/test/unit/dropin.js
+++ b/test/unit/dropin.js
@@ -2085,6 +2085,24 @@ describe('Dropin', () => {
     );
   });
 
+  describe('getAvailablePaymentOptions', () => {
+    test('returns an array of payment options presented to the customer', (done) => {
+      testContext.dropinOptions.merchantConfiguration.paypal = {
+        flow: 'vault'
+      };
+
+      const instance = new Dropin(testContext.dropinOptions);
+
+      instance._initialize(() => {
+        const result = instance.getAvailablePaymentOptions();
+
+        expect(result).toEqual(['card', 'paypal']);
+
+        done();
+      });
+    });
+  });
+
   describe('clearSelectedPaymentMethod', () => {
     test('refreshes saved payment methods', () => {
       const instance = new Dropin(testContext.dropinOptions);