@paydock/client-sdk 1.11.3-beta → 1.11.5-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4868,183 +4868,615 @@ The final method to beginning, the load process of widget to html
4868
4868
 
4869
4869
  **Kind**: instance method of [<code>VaultDisplayWidget</code>](#VaultDisplayWidget)
4870
4870
 
4871
- ## Classes
4872
-
4873
- <dl>
4874
- <dt><a href="#WalletButtons">WalletButtons</a></dt>
4875
- <dd><p>Class WalletButtons to work with different E-Wallets within html (currently supports Apple Pay, Google Pay™ and Apple Pay via Stripe, Flypay, Paypal)</p>
4876
- </dd>
4877
- </dl>
4878
-
4879
- ## Constants
4871
+ ## Wallet Buttons
4872
+ You can find description of all methods and parameters [here](https://www.npmjs.com/package/@paydock/client-sdk#wallet-buttons-simple-example)
4880
4873
 
4881
- <dl>
4882
- <dt><a href="#EVENT">EVENT</a> : <code>object</code></dt>
4883
- <dd><p>List of available event&#39;s name in the wallet button lifecycle</p>
4884
- </dd>
4885
- </dl>
4874
+ Wallet Buttons allow you to easily integrate different E-Wallets into your checkout.
4875
+ Currently supports ApplePay, Google Pay and Apple Pay via Stripe, Flypay checkout and Paypal Smart Buttons Checkout.
4886
4876
 
4887
- ## Interfaces
4877
+ If available in your client environment, you will display a simple button that upon clicking it the user will follow the standard flow for the appropriate Wallet. If not available an event will be raised and no button will be displayed.
4888
4878
 
4889
- <dl>
4890
- <dt><a href="#IWalletMeta">IWalletMeta</a> : <code>object</code></dt>
4891
- <dd><p>Interface of data used by the wallet checkout and payment proccess.</p>
4892
- </dd>
4893
- <dt><a href="#IApplePayShippingOption">IApplePayShippingOption</a> : <code>object</code></dt>
4894
- <dd><p>Interface of Shipping Options for ApplePay</p>
4895
- </dd>
4896
- <dt><a href="#IGooglePayShippingOption">IGooglePayShippingOption</a> : <code>object</code></dt>
4897
- <dd><p>Interface of Shipping Options for GooglePay</p>
4898
- </dd>
4899
- <dt><a href="#IPayPalShippingOption">IPayPalShippingOption</a> : <code>object</code></dt>
4900
- <dd><p>Interface of Shipping Options for PayPal</p>
4901
- </dd>
4902
- </dl>
4879
+ ## Wallet Buttons simple example
4903
4880
 
4904
- <a name="IWalletMeta" id="IWalletMeta"></a>
4881
+ ### Container
4905
4882
 
4906
- ## IWalletMeta : <code>object</code>
4907
- Interface of data used by the wallet checkout and payment proccess.
4883
+ ```html
4884
+ <div id="widget"></div>
4885
+ ```
4908
4886
 
4909
- **Kind**: global interface
4887
+ You must create a container for the Wallet Buttons. Inside this tag, the button will be initialized.
4910
4888
 
4911
- | Param | Type | Description |
4912
- | --- | --- | --- |
4913
- | [amount_label] | <code>string</code> | Label shown next to the total amount to be paid. Required for [Stripe, ApplePay, GooglePay]. N/A for [FlyPay, PayPal]. |
4914
- | [country] | <code>string</code> | Country of the user. 2 letter ISO code format. Required for [Stripe, ApplePay, GooglePay]. N/A for [FlyPay, PayPal]. |
4915
- | [pay_later] | <code>string</code> | Used to enable Pay Later feature in PayPal Smart Checkout WalletButton integration when available. Optional for [PayPal]. N/A for other wallets. |
4916
- | [show_billing_address] | <code>boolean</code> | Used to hide/show the billing address on ApplePay and GooglePay popups. Default value is false. Optional for [ApplePay, GooglePay]. N/A for other wallets. |
4917
- | [request_payer_name] | <code>boolean</code> | Used mainly for fraud purposes - recommended set to true. Optional for [Stripe]. N/A for other wallets. |
4918
- | [request_payer_email] | <code>boolean</code> | Used mainly for fraud purposes - recommended set to true. Optional for [Stripe]. N/A for other wallets. |
4919
- | [request_payer_phone] | <code>boolean</code> | Used mainly for fraud purposes - recommended set to true. Optional for [Stripe]. N/A for other wallets. |
4920
- | [request_shipping] | <code>boolean</code> | Used to request or not shipping address in the Wallet checkout, being able to handle amount changes via the `update` event. Optional for [FlyPay, PayPal, ApplePay, GooglePay]. N/A for [Stripe]. |
4921
- | [shipping_options] | [<code>Array.&lt;IApplePayShippingOption&gt;</code>](#IApplePayShippingOption) \| [<code>Array.&lt;IPayPalShippingOption&gt;</code>](#IPayPalShippingOption) | Used to provide available shipping options.(To use shipping_options the request_shipping flag should be true). Optional for [ApplePay]. N/A for the other wallets. |
4922
- | [merchant_name] | <code>string</code> | Merchant Name used for GooglePay integration via MPGS. Required for [GooglePay]. N/A for other wallets. |
4923
- | [raw_data_initialization] | <code>object</code> | Used to provide values to initialize wallet with raw data. Optional for [ApplePay]. N/A for the other wallets. |
4924
- | [style] | <code>object</code> | Used to style PayPal buttons, check possible values at https://developer.paypal.com/docs/business/checkout/reference/style-guide. Also used at ApplePay to select button type. Optional for [PayPal, ApplePay]. N/A for [Stripe, FlyPay]. |
4925
- | [style.button_type] | <code>object</code> | Used to select ApplePay button type (e.g: 'buy','donate', etc), check possible values at https://developer.apple.com/documentation/apple_pay_on_the_web/displaying_apple_pay_buttons_using_css. Optional for [ApplePay]. N/A for other wallets. |
4926
- | [wallets] | <code>array</code> | By default if this is not sent or empty, we will try to show either Apple Pay or Google Pay buttons. This can be limited sending the following array in this field: ['apple','google]. Optional for [Stripe, ApplePay, GooglePay]. N/A for other wallets. |
4889
+ Before initializing the button, you must perform a POST request to `charges/wallet` from a secure environment like your server. This call will return a token that is required to load the button and securely complete the payment. You can find the documentation to this call in the PayDock API documentation.
4927
4890
 
4928
- <a name="IApplePayShippingOption" id="IApplePayShippingOption"></a>
4891
+ ### Initialization
4892
+ The following is the minimum required initialization parameters for Apple Pay and Google Pay via Stripe:
4893
+ ```javascript
4894
+ let button = new paydock.WalletButtons(
4895
+ "#widget",
4896
+ token,
4897
+ {
4898
+ amount_label: "Total",
4899
+ country: "DE",
4900
+ }
4901
+ );
4902
+ button.load();
4903
+ ```
4929
4904
 
4930
- ## IApplePayShippingOption : <code>object</code>
4931
- Interface of Shipping Options for ApplePay
4905
+ ```javascript--es2015
4906
+ // ES2015 | TypeScript
4907
+ import { WalletButtons } from '@paydock/client-sdk';
4932
4908
 
4933
- **Kind**: global interface
4909
+ var button = new WalletButtons(
4910
+ '#widget',
4911
+ token,
4912
+ {
4913
+ amount_label: 'Total',
4914
+ country: 'DE',
4915
+ }
4916
+ );
4917
+ button.load();
4918
+ ```
4934
4919
 
4935
- | Param | Type | Description |
4936
- | --- | --- | --- |
4937
- | [id] | <code>string</code> | Identifier of the Shipping Option. Required. |
4938
- | [label] | <code>string</code> | Identifier of the Shipping Option. Required. |
4939
- | [amount] | <code>string</code> | Amount of the Shipping Option. Required. |
4940
- | [detail] | <code>string</code> | Details of the Shipping Option. Required. |
4941
- | [type] | <code>string</code> | Type of the Shipping Option. Values can be 'ELECTRONIC', 'GROUND', 'NOT_SHIPPED', 'OVERNIGHT', 'PICKUP', 'PRIORITY', 'SAME_DAY'. Optional. |
4920
+ Flypay and Paypal wallets do not require any meta sent to the wallet, so the following is enough for initialization:
4921
+ ```javascript
4922
+ let button = new paydock.WalletButtons(
4923
+ "#widget",
4924
+ token,
4925
+ {}
4926
+ );
4927
+ button.load();
4928
+ ```
4942
4929
 
4943
- <a name="IGooglePayShippingOption" id="IGooglePayShippingOption"></a>
4930
+ ```javascript--es2015
4931
+ // ES2015 | TypeScript
4932
+ import { WalletButtons } from '@paydock/client-sdk';
4944
4933
 
4945
- ## IGooglePayShippingOption : <code>object</code>
4946
- Interface of Shipping Options for GooglePay
4934
+ var button = new WalletButtons(
4935
+ '#widget',
4936
+ token,
4937
+ {}
4938
+ );
4939
+ button.load();
4940
+ ```
4941
+ ### Setting environment
4947
4942
 
4948
- **Kind**: global interface
4943
+ Current method can change environment. By default environment = sandbox.
4944
+ Bear in mind that you must set an environment before calling `button.load()`.
4949
4945
 
4950
- | Param | Type | Description |
4951
- | --- | --- | --- |
4952
- | [id] | <code>string</code> | Identifier of the Shipping Option. Required. |
4953
- | [label] | <code>string</code> | Identifier of the Shipping Option. Required. |
4954
- | [detail] | <code>string</code> | Details of the Shipping Option. Optional. |
4955
- | [type] | <code>string</code> | Type of the Shipping Option. Values can be 'ELECTRONIC', 'GROUND', 'NOT_SHIPPED', 'OVERNIGHT', 'PICKUP', 'PRIORITY', 'SAME_DAY'. Optional. |
4946
+ ```javascript
4947
+ button.setEnv('sandbox');
4948
+ ```
4956
4949
 
4957
- <a name="IPayPalShippingOption" id="IPayPalShippingOption"></a>
4950
+ ### Full example
4958
4951
 
4959
- ## IPayPalShippingOption : <code>object</code>
4960
- Interface of Shipping Options for PayPal
4952
+ ```html
4953
+ <!DOCTYPE html>
4954
+ <html lang="en">
4955
+ <head>
4956
+ <meta charset="UTF-8">
4957
+ <title>Title</title>
4958
+ </head>
4959
+ <body>
4960
+ <h2>Payment using PayDock Wallet Button!</h2>
4961
+ <div id="widget"></div>
4962
+ </body>
4963
+ <script src="https://app-sandbox.paydock.com/v1/widget.umd.js" ></script>
4964
+ <script>
4965
+ let button = new paydock.WalletButtons(
4966
+ "#widget",
4967
+ token,
4968
+ {
4969
+ amount_label: "Total",
4970
+ country: "DE",
4971
+ }
4972
+ );
4973
+ button.load();
4974
+ </script>
4975
+ </html>
4976
+ ```
4961
4977
 
4962
- **Kind**: global interface
4978
+ ## Wallet Buttons advanced example
4963
4979
 
4964
- | Param | Type | Description |
4965
- | --- | --- | --- |
4966
- | [id] | <code>string</code> | Identifier of the Shipping Option. Required. |
4967
- | [label] | <code>string</code> | Identifier of the Shipping Option. Required. |
4968
- | [amount] | <code>string</code> | Amount of the Shipping Option. Required. |
4969
- | [currency] | <code>string</code> | Currency of the Shipping Option. Required. |
4970
- | [type] | <code>string</code> | Type of the Shipping Option. Values can be 'SHIPPING' or 'PICKUP'. Required. |
4980
+ ### Checking for button availability
4971
4981
 
4972
- <a name="WalletButtons" id="WalletButtons"></a>
4982
+ If the customer's browser is not supported, or the customer does not have any card added to their Google Pay or Apple Pay wallets, the button will not load. In this case the callback onUnavailable() will be called. You can define the behavior of this function before loading the button.
4973
4983
 
4974
- ## WalletButtons
4975
- Class WalletButtons to work with different E-Wallets within html (currently supports Apple Pay, Google Pay™ and Apple Pay via Stripe, Flypay, Paypal)
4984
+ ```javascript
4985
+ button.onUnavailable(() => console.log("No wallet buttons available"));
4986
+ ```
4976
4987
 
4977
- **Kind**: global class
4988
+ ### Forcibly closing the checkout
4978
4989
 
4979
- * [WalletButtons](#WalletButtons)
4980
- * [new exports.WalletButtons(selector, chargeToken, object)](#new_WalletButtons_new)
4981
- * [.load()](#WalletButtons+load)
4982
- * [.update()](#WalletButtons+update)
4983
- * [.setEnv(env, [alias])](#WalletButtons+setEnv)
4984
- * [.close()](#WalletButtons+close)
4985
- * [.on(eventName, [cb])](#WalletButtons+on) ⇒ <code>Promise.&lt;IEventData&gt;</code> \| <code>void</code>
4986
- * [.onUnavailable([handler])](#WalletButtons+onUnavailable)
4987
- * [.onUpdate([handler])](#WalletButtons+onUpdate)
4988
- * [.onPaymentSuccessful([handler])](#WalletButtons+onPaymentSuccessful)
4989
- * [.onPaymentInReview([handler])](#WalletButtons+onPaymentInReview)
4990
- * [.onPaymentError([handler])](#WalletButtons+onPaymentError)
4990
+ In some situations you may want to forcibly close the checkout so that your user is back in your checkout screen, fow which you can use this method. Currently supported by Flypay wallet only.
4991
4991
 
4992
- <a name="new_WalletButtons_new" id="new_WalletButtons_new"></a>
4992
+ ```javascript
4993
+ button.close();
4994
+ ```
4993
4995
 
4994
- ### new exports.WalletButtons(selector, chargeToken, object)
4996
+ ### Performing actions when shipping info is updated
4995
4997
 
4996
- | Param | Type | Description |
4997
- | --- | --- | --- |
4998
- | selector | <code>string</code> | Selector of html element. Container for the WalletButtons. |
4999
- | chargeToken | <code>string</code> | token for the wallet transaction, created with a secure call to `POST charges/wallet`. |
5000
- | object | [<code>IWalletMeta</code>](#IWalletMeta) | data that configures the E-Wallet, which can be shown on checkout page and configures required customer information. |
4998
+ In Flypay, Paypal and ApplePay via MPGS integrations after each shipping info update the `onUpdate(data)` will be called with the selected shipping address information (plus selected shipping method for Paypal). Merchants should handle this callback, recalculate shipping costs in their server by analyzing the new data, and submit a backend to backend request to `POST charges/:id` with the new total amount and shipping amount (you can find the documentation of this call in the PayDock API documentation).
5001
4999
 
5002
- **Example**
5003
- ```js
5004
- var button = new WalletButtons('#wallet-buttons', 'charge-token', { amount_label: 'Total', country: 'us' });
5005
- ```
5006
- <a name="WalletButtons+load" id="WalletButtons+load"></a>
5000
+ For Paypal integration specifically, if shipping is enabled for the wallet button and different shipping methods were provided in the create wallet charge call, Merchants must ensure that the posted `shipping.amount` to `POST charges/:id` matches the selected shipping option amount (value sent in when initializing the wallet charge). In other words, when providing shipping methods the shipping amount is bound to being one of the provided shipping method amount necessarily. Bear in mind that the total charge amount must include the `shipping.amount`, since it represents the full amount to be charged to the customer.
5007
5001
 
5008
- ### walletButtons.load()
5009
- Initializes the availability checks and inserts the button if possible.
5010
- Otherwise function onUnavailable(handler: VoidFunction) will be called.
5002
+ After analyzing the new shipping information, and making the post with the updated charge and shipping amounts if necessary, the `button.update({ success: true/false })` wallet button method needs to be called to resume the interactions with the customer. Not calling this will result in unexpected behavior.
5011
5003
 
5012
- **Kind**: instance method of [<code>WalletButtons</code>](#WalletButtons)
5013
- **Example**
5014
- ```js
5015
- var button = new WalletButtons(
5016
- '#buttons',
5017
- token,
5018
- {
5019
- amount_label: 'Total',
5020
- country: 'DE',
5021
- }
5022
- );
5023
- button.load();
5004
+ ```javascript
5005
+ button.onUpdate((data) => {
5006
+ console.log("Updating amount via a backend to backend call to POST charges/:id");
5007
+ // call `POST charges/:id` to modify charge
5008
+ button.update({ success: true });
5009
+ });
5024
5010
  ```
5025
- <a name="WalletButtons+update" id="WalletButtons+update"></a>
5026
5011
 
5027
- ### walletButtons.update()
5028
- Triggers the update process of the wallet, if available.
5029
- Currently supported by Flypay, Paypal and ApplePay/GooglePay via MPGS Wallets.
5012
+ For ApplePay via MPGS integration specifically, you must return the new `amount` and new `shipping_options` If new options are needed based on the updated shipping data. Before the user authorizes the transaction with Touch ID, Face ID, or passcode, you receive redacted address information (address_country, address_city, address_state, address_postcode), this data can be used to recalculate the amount and new shipping options. (https://developer.apple.com/documentation/apple_pay_on_the_web/applepaypayment/1916097-shippingcontact)
5030
5013
 
5031
- **Kind**: instance method of [<code>WalletButtons</code>](#WalletButtons)
5032
- **Example**
5033
- ```js
5034
- var button = new WalletButtons(
5035
- '#buttons',
5036
- token,
5037
- {
5038
- amount_label: 'Total',
5039
- country: 'DE',
5040
- }
5041
- );
5042
- button.on('update', (data) => {
5043
- updateChargeAmountInBackend(data);
5044
- button.update({ success: true });
5045
- });
5046
- ```
5047
- **Example**
5014
+ ```javascript
5015
+ button.onUpdate((data) => {
5016
+ console.log("Updating amount via a backend to backend call to POST charges/:id");
5017
+ // call `POST charges/:id` to modify charge
5018
+ button.update({
5019
+ success: true,
5020
+ body: {
5021
+ amount: 15,
5022
+ shipping_options: [
5023
+ {
5024
+ id: "NEW-FreeShip",
5025
+ label: "NEW - Free Shipping",
5026
+ detail: "Arrives in 3 to 5 days",
5027
+ amount: "0.00"
5028
+ },
5029
+ {
5030
+ id: "NEW - FastShip",
5031
+ label: "NEW - Fast Shipping",
5032
+ detail: "Arrives in less than 1 day",
5033
+ amount: "10.00"
5034
+ }
5035
+ ]
5036
+ }
5037
+ });
5038
+ });
5039
+ ```
5040
+
5041
+ ### Performing actions after the payment is completed
5042
+
5043
+ After the payment is completed, the onPaymentSuccessful(data) will be called if the payment was successful. If the payment was not successful, the function onPaymentError(data) will be called. If fraud check is active for the gateway, a fraud body was sent in the wallet charge initialize call and the fraud service left the charge in review, then the onPaymentInReview(data) will be called.
5044
+ All three callbacks return relevant data according to each one of the scenarios.
5045
+
5046
+ ```javascript
5047
+ button.onPaymentSuccessful((data) => console.log("The payment was successful"));
5048
+ ```
5049
+
5050
+ ```javascript
5051
+ button.onPaymentInReview((data) => console.log("The payment is on fraud review"));
5052
+ ```
5053
+
5054
+ ```javascript
5055
+ button.onPaymentError((data) => console.log("The payment was not successful"));
5056
+ ```
5057
+ ### Events
5058
+ The above events can be used in a more generic way via de `on` function, and making use
5059
+ of the corresponding event names.
5060
+
5061
+ ```javascript
5062
+ button.on(EVENT.UNAVAILABLE, () => console.log("No wallet buttons available"));
5063
+ button.on(EVENT.UPDATE, (data) => console.log("Updating amount via a backend to backend call to POST charges/:id");
5064
+ button.on(EVENT.PAYMENT_SUCCESSFUL, (data) => console.log("The payment was successful"));
5065
+ button.on(EVENT.PAYMENT_ERROR, (data) => console.log("The payment was not successful"));
5066
+ ```
5067
+
5068
+ This example shows how to use these functions for **Apple and Google Pay via Stripe**:
5069
+ _(Required `meta` fields: `amount_label`, `country`. Optional `meta` fields: `wallets`)_
5070
+ ### Full example
5071
+
5072
+ ```html
5073
+ <!DOCTYPE html>
5074
+ <html lang="en">
5075
+ <head>
5076
+ <meta charset="UTF-8">
5077
+ <title>Title</title>
5078
+ </head>
5079
+ <body>
5080
+ <h2>Payment using PayDock Wallet Button!</h2>
5081
+ <div id="widget"></div>
5082
+ </body>
5083
+ <script src="https://app-sandbox.paydock.com/v1/widget.umd.js" ></script>
5084
+ <script>
5085
+ let button = new paydock.WalletButtons(
5086
+ "#widget",
5087
+ charge_token,
5088
+ {
5089
+ amount_label: "Total",
5090
+ country: "DE",
5091
+ wallets: ["google", "apple"],
5092
+ }
5093
+ );
5094
+ button.setEnv('sandbox');
5095
+ button.onUnavailable(() => console.log("No wallet buttons available"));
5096
+ button.onPaymentSuccessful((data) => console.log("The payment was successful"));
5097
+ button.onPaymentError((data) => console.log("The payment was not successful"));
5098
+ button.onPaymentInReview((data) => console.log("The payment is on fraud review"));
5099
+ button.load();
5100
+ </script>
5101
+ </html>
5102
+ ```
5103
+
5104
+ This example shows how to use these functions for **Paypal Smart Checkout Buttons**:
5105
+ _(Required `meta` fields: - . Optional `meta` fields: `request_shipping`, `pay_later`, `style`)_
5106
+ ### Full example
5107
+ ```html
5108
+ <!DOCTYPE html>
5109
+ <html lang="en">
5110
+ <head>
5111
+ <meta charset="UTF-8">
5112
+ <title>Title</title>
5113
+ </head>
5114
+ <body>
5115
+ <h2>Payment using PayDock Wallet Button!</h2>
5116
+ <div id="widget"></div>
5117
+ </body>
5118
+ <script src="https://app-sandbox.paydock.com/v1/widget.umd.js" ></script>
5119
+ <script>
5120
+ let button = new paydock.WalletButtons(
5121
+ "#widget",
5122
+ charge_token,
5123
+ {
5124
+ request_shipping: true,
5125
+ pay_later: true,
5126
+ style: {
5127
+ layout: 'horizontal',
5128
+ color: 'blue',
5129
+ shape: 'rect',
5130
+ label: 'paypal',
5131
+ },
5132
+ }
5133
+ );
5134
+ button.setEnv('sandbox');
5135
+ button.onUnavailable(() => console.log("No wallet buttons available"));
5136
+ button.onUpdate((data) => {
5137
+ console.log("Updating amount via a backend to backend call to POST charges/:id");
5138
+ // call `POST charges/:id` to modify charge
5139
+ button.update({ success: true });
5140
+ });
5141
+ button.onPaymentSuccessful((data) => console.log("The payment was successful"));
5142
+ button.onPaymentError((data) => console.log("The payment was not successful"));
5143
+ button.onPaymentInReview((data) => console.log("The payment is on fraud review"));
5144
+ button.load();
5145
+ </script>
5146
+ </html>
5147
+ ```
5148
+
5149
+ This example shows how to use these functions for **Flypay Checkout**.
5150
+ _(Required `meta` fields: - . Optional `meta` fields: `request_shipping`, `pay_later`, `style`)_
5151
+ ### Full example
5152
+ ```html
5153
+ <!DOCTYPE html>
5154
+ <html lang="en">
5155
+ <head>
5156
+ <meta charset="UTF-8">
5157
+ <title>Title</title>
5158
+ </head>
5159
+ <body>
5160
+ <h2>Payment using PayDock Wallet Button!</h2>
5161
+ <div id="widget"></div>
5162
+ </body>
5163
+ <script src="https://app-sandbox.paydock.com/v1/widget.umd.js" ></script>
5164
+ <script>
5165
+ let button = new paydock.WalletButtons(
5166
+ "#widget",
5167
+ charge_token,
5168
+ {
5169
+ request_shipping: true
5170
+ }
5171
+ );
5172
+ button.setEnv('sandbox');
5173
+ button.onUnavailable(() => console.log("No wallet buttons available"));
5174
+ button.onUpdate((data) => {
5175
+ console.log("Updating amount via a backend to backend call to POST charges/:id");
5176
+ // call `POST charges/:id` to modify charge
5177
+ button.update({ success: true });
5178
+ });
5179
+ button.onPaymentSuccessful((data) => console.log("The payment was successful"));
5180
+ button.onPaymentError((data) => console.log("The payment was not successful"));
5181
+ button.onPaymentInReview((data) => console.log("The payment is on fraud review"));
5182
+ button.load();
5183
+ </script>
5184
+ </html>
5185
+ ```
5186
+
5187
+ This example shows how to use these functions for **ApplePay via MPGS**:
5188
+ _(Required `meta` fields: `amount_label`, `country`. Optional `meta` fields: `raw_data_initialization`, `request_shipping`, `style.button_type`)_
5189
+ ### Full example
5190
+
5191
+ ```html
5192
+ <!DOCTYPE html>
5193
+ <html lang="en">
5194
+ <head>
5195
+ <meta charset="UTF-8">
5196
+ <title>Title</title>
5197
+ </head>
5198
+ <body>
5199
+ <h2>Payment using PayDock Wallet Button!</h2>
5200
+ <div id="widget"></div>
5201
+ </body>
5202
+ <script src="https://app-sandbox.paydock.com/v1/widget.umd.js" ></script>
5203
+ <script>
5204
+ let button = new paydock.WalletButtons(
5205
+ "#widget",
5206
+ charge_token,
5207
+ {
5208
+ amount_label: "Total",
5209
+ country: 'DE',
5210
+ request_shipping: true,
5211
+ style: {
5212
+ button_type: 'buy',
5213
+ },
5214
+ shipping_options: [
5215
+ {
5216
+ id: "FreeShip",
5217
+ label: "Free Shipping",
5218
+ detail: "Arrives in 5 to 7 days",
5219
+ amount: "0.00"
5220
+ },
5221
+ {
5222
+ id: "FastShip",
5223
+ label: "Fast Shipping",
5224
+ detail: "Arrives in 1 day",
5225
+ amount: "10.00"
5226
+ }
5227
+ ]
5228
+ }
5229
+ );
5230
+ button.setEnv('sandbox');
5231
+ button.onUnavailable(() => console.log("No wallet buttons available"));
5232
+ button.onPaymentSuccessful((data) => console.log("The payment was successful"));
5233
+ button.onPaymentError((data) => console.log("The payment was not successful"));
5234
+ button.load();
5235
+ </script>
5236
+ </html>
5237
+ ```
5238
+
5239
+ Also, for **ApplePay via MPGS** you can initialize the `ApplePayPaymentRequest` with your own values instead of using the default ones. Below you can see an example on how to initialize the `ApplePayPaymentRequest` with the `raw_data_initialization` meta field:
5240
+
5241
+ ### Raw data initialization example
5242
+
5243
+ ```html
5244
+ <!DOCTYPE html>
5245
+ <html lang="en">
5246
+ <head>
5247
+ <meta charset="UTF-8">
5248
+ <title>Title</title>
5249
+ </head>
5250
+ <body>
5251
+ <h2>Payment using PayDock Wallet Button!</h2>
5252
+ <div id="widget"></div>
5253
+ </body>
5254
+ <script src="https://app-sandbox.paydock.com/v1/widget.umd.js" ></script>
5255
+ <script>
5256
+ let button = new paydock.WalletButtons(
5257
+ "#widget",
5258
+ charge_token,
5259
+ {
5260
+ raw_data_initialization: {
5261
+ countryCode: "AU",
5262
+ currencyCode: "AUD",
5263
+ merchantCapabilities: ["supports3DS","supportsCredit","supportsDebit"],
5264
+ supportedNetworks: ["visa","masterCard","amex","discover"],
5265
+ requiredBillingContactFields: ["name","postalAddress"],
5266
+ requiredShippingContactFields:["postalAddress","name","phone","email" ],
5267
+ total: {
5268
+ label: "Total",
5269
+ amount: "10",
5270
+ type: "final",
5271
+ }
5272
+ },
5273
+ amount_label: "Total",
5274
+ country: 'DE',
5275
+ request_shipping: true,
5276
+ style: {
5277
+ button_type: 'buy',
5278
+ },
5279
+ shipping_options: [
5280
+ {
5281
+ id: "FreeShip",
5282
+ label: "Free Shipping",
5283
+ detail: "Arrives in 5 to 7 days",
5284
+ amount: "0.00"
5285
+ },
5286
+ {
5287
+ id: "FastShip",
5288
+ label: "Fast Shipping",
5289
+ detail: "Arrives in 1 day",
5290
+ amount: "10.00"
5291
+ }
5292
+ ]
5293
+ }
5294
+ );
5295
+ button.setEnv('sandbox');
5296
+ button.onUnavailable(() => console.log("No wallet buttons available"));
5297
+ button.onPaymentSuccessful((data) => console.log("The payment was successful"));
5298
+ button.onPaymentError((data) => console.log("The payment was not successful"));
5299
+ button.load();
5300
+ </script>
5301
+ </html>
5302
+ ```
5303
+ ## Classes
5304
+
5305
+ <dl>
5306
+ <dt><a href="#WalletButtons">WalletButtons</a></dt>
5307
+ <dd><p>Class WalletButtons to work with different E-Wallets within html (currently supports Apple Pay, Google Pay™ and Apple Pay via Stripe, Flypay, Paypal)</p>
5308
+ </dd>
5309
+ </dl>
5310
+
5311
+ ## Constants
5312
+
5313
+ <dl>
5314
+ <dt><a href="#EVENT">EVENT</a> : <code>object</code></dt>
5315
+ <dd><p>List of available event&#39;s name in the wallet button lifecycle</p>
5316
+ </dd>
5317
+ </dl>
5318
+
5319
+ ## Interfaces
5320
+
5321
+ <dl>
5322
+ <dt><a href="#IWalletMeta">IWalletMeta</a> : <code>object</code></dt>
5323
+ <dd><p>Interface of data used by the wallet checkout and payment proccess.</p>
5324
+ </dd>
5325
+ <dt><a href="#IApplePayShippingOption">IApplePayShippingOption</a> : <code>object</code></dt>
5326
+ <dd><p>Interface of Shipping Options for ApplePay</p>
5327
+ </dd>
5328
+ <dt><a href="#IGooglePayShippingOption">IGooglePayShippingOption</a> : <code>object</code></dt>
5329
+ <dd><p>Interface of Shipping Options for GooglePay</p>
5330
+ </dd>
5331
+ <dt><a href="#IPayPalShippingOption">IPayPalShippingOption</a> : <code>object</code></dt>
5332
+ <dd><p>Interface of Shipping Options for PayPal</p>
5333
+ </dd>
5334
+ </dl>
5335
+
5336
+ <a name="IWalletMeta" id="IWalletMeta"></a>
5337
+
5338
+ ## IWalletMeta : <code>object</code>
5339
+ Interface of data used by the wallet checkout and payment proccess.
5340
+
5341
+ **Kind**: global interface
5342
+
5343
+ | Param | Type | Description |
5344
+ | --- | --- | --- |
5345
+ | [amount_label] | <code>string</code> | Label shown next to the total amount to be paid. Required for [Stripe, ApplePay, GooglePay]. N/A for [FlyPay, PayPal]. |
5346
+ | [country] | <code>string</code> | Country of the user. 2 letter ISO code format. Required for [Stripe, ApplePay, GooglePay]. N/A for [FlyPay, PayPal]. |
5347
+ | [pay_later] | <code>string</code> | Used to enable Pay Later feature in PayPal Smart Checkout WalletButton integration when available. Optional for [PayPal]. N/A for other wallets. |
5348
+ | [show_billing_address] | <code>boolean</code> | Used to hide/show the billing address on ApplePay and GooglePay popups. Default value is false. Optional for [ApplePay, GooglePay]. N/A for other wallets. |
5349
+ | [request_payer_name] | <code>boolean</code> | Used mainly for fraud purposes - recommended set to true. Optional for [Stripe]. N/A for other wallets. |
5350
+ | [request_payer_email] | <code>boolean</code> | Used mainly for fraud purposes - recommended set to true. Optional for [Stripe]. N/A for other wallets. |
5351
+ | [request_payer_phone] | <code>boolean</code> | Used mainly for fraud purposes - recommended set to true. Optional for [Stripe]. N/A for other wallets. |
5352
+ | [request_shipping] | <code>boolean</code> | Used to request or not shipping address in the Wallet checkout, being able to handle amount changes via the `update` event. Optional for [FlyPay, PayPal, ApplePay, GooglePay]. N/A for [Stripe]. |
5353
+ | [shipping_options] | [<code>Array.&lt;IApplePayShippingOption&gt;</code>](#IApplePayShippingOption) \| [<code>Array.&lt;IPayPalShippingOption&gt;</code>](#IPayPalShippingOption) | Used to provide available shipping options.(To use shipping_options the request_shipping flag should be true). Optional for [ApplePay]. N/A for the other wallets. |
5354
+ | [merchant_name] | <code>string</code> | Merchant Name used for GooglePay integration via MPGS. Required for [GooglePay]. N/A for other wallets. |
5355
+ | [raw_data_initialization] | <code>object</code> | Used to provide values to initialize wallet with raw data. Optional for [ApplePay]. N/A for the other wallets. |
5356
+ | [style] | <code>object</code> | Used to style PayPal buttons, check possible values at https://developer.paypal.com/docs/business/checkout/reference/style-guide. Also used at ApplePay to select button type. Optional for [PayPal, ApplePay]. N/A for [Stripe, FlyPay]. |
5357
+ | [style.button_type] | <code>object</code> | Used to select ApplePay button type (e.g: 'buy','donate', etc), check possible values at https://developer.apple.com/documentation/apple_pay_on_the_web/displaying_apple_pay_buttons_using_css. Optional for [ApplePay]. N/A for other wallets. |
5358
+ | [wallets] | <code>array</code> | By default if this is not sent or empty, we will try to show either Apple Pay or Google Pay buttons. This can be limited sending the following array in this field: ['apple','google]. Optional for [Stripe, ApplePay, GooglePay]. N/A for other wallets. |
5359
+
5360
+ <a name="IApplePayShippingOption" id="IApplePayShippingOption"></a>
5361
+
5362
+ ## IApplePayShippingOption : <code>object</code>
5363
+ Interface of Shipping Options for ApplePay
5364
+
5365
+ **Kind**: global interface
5366
+
5367
+ | Param | Type | Description |
5368
+ | --- | --- | --- |
5369
+ | [id] | <code>string</code> | Identifier of the Shipping Option. Required. |
5370
+ | [label] | <code>string</code> | Identifier of the Shipping Option. Required. |
5371
+ | [amount] | <code>string</code> | Amount of the Shipping Option. Required. |
5372
+ | [detail] | <code>string</code> | Details of the Shipping Option. Required. |
5373
+ | [type] | <code>string</code> | Type of the Shipping Option. Values can be 'ELECTRONIC', 'GROUND', 'NOT_SHIPPED', 'OVERNIGHT', 'PICKUP', 'PRIORITY', 'SAME_DAY'. Optional. |
5374
+
5375
+ <a name="IGooglePayShippingOption" id="IGooglePayShippingOption"></a>
5376
+
5377
+ ## IGooglePayShippingOption : <code>object</code>
5378
+ Interface of Shipping Options for GooglePay
5379
+
5380
+ **Kind**: global interface
5381
+
5382
+ | Param | Type | Description |
5383
+ | --- | --- | --- |
5384
+ | [id] | <code>string</code> | Identifier of the Shipping Option. Required. |
5385
+ | [label] | <code>string</code> | Identifier of the Shipping Option. Required. |
5386
+ | [detail] | <code>string</code> | Details of the Shipping Option. Optional. |
5387
+ | [type] | <code>string</code> | Type of the Shipping Option. Values can be 'ELECTRONIC', 'GROUND', 'NOT_SHIPPED', 'OVERNIGHT', 'PICKUP', 'PRIORITY', 'SAME_DAY'. Optional. |
5388
+
5389
+ <a name="IPayPalShippingOption" id="IPayPalShippingOption"></a>
5390
+
5391
+ ## IPayPalShippingOption : <code>object</code>
5392
+ Interface of Shipping Options for PayPal
5393
+
5394
+ **Kind**: global interface
5395
+
5396
+ | Param | Type | Description |
5397
+ | --- | --- | --- |
5398
+ | [id] | <code>string</code> | Identifier of the Shipping Option. Required. |
5399
+ | [label] | <code>string</code> | Identifier of the Shipping Option. Required. |
5400
+ | [amount] | <code>string</code> | Amount of the Shipping Option. Required. |
5401
+ | [currency] | <code>string</code> | Currency of the Shipping Option. Required. |
5402
+ | [type] | <code>string</code> | Type of the Shipping Option. Values can be 'SHIPPING' or 'PICKUP'. Required. |
5403
+
5404
+ <a name="WalletButtons" id="WalletButtons"></a>
5405
+
5406
+ ## WalletButtons
5407
+ Class WalletButtons to work with different E-Wallets within html (currently supports Apple Pay, Google Pay™ and Apple Pay via Stripe, Flypay, Paypal)
5408
+
5409
+ **Kind**: global class
5410
+
5411
+ * [WalletButtons](#WalletButtons)
5412
+ * [new exports.WalletButtons(selector, chargeToken, object)](#new_WalletButtons_new)
5413
+ * [.load()](#WalletButtons+load)
5414
+ * [.update()](#WalletButtons+update)
5415
+ * [.setEnv(env, [alias])](#WalletButtons+setEnv)
5416
+ * [.close()](#WalletButtons+close)
5417
+ * [.on(eventName, [cb])](#WalletButtons+on) ⇒ <code>Promise.&lt;IEventData&gt;</code> \| <code>void</code>
5418
+ * [.onUnavailable([handler])](#WalletButtons+onUnavailable)
5419
+ * [.onUpdate([handler])](#WalletButtons+onUpdate)
5420
+ * [.onPaymentSuccessful([handler])](#WalletButtons+onPaymentSuccessful)
5421
+ * [.onPaymentInReview([handler])](#WalletButtons+onPaymentInReview)
5422
+ * [.onPaymentError([handler])](#WalletButtons+onPaymentError)
5423
+
5424
+ <a name="new_WalletButtons_new" id="new_WalletButtons_new"></a>
5425
+
5426
+ ### new exports.WalletButtons(selector, chargeToken, object)
5427
+
5428
+ | Param | Type | Description |
5429
+ | --- | --- | --- |
5430
+ | selector | <code>string</code> | Selector of html element. Container for the WalletButtons. |
5431
+ | chargeToken | <code>string</code> | token for the wallet transaction, created with a secure call to `POST charges/wallet`. |
5432
+ | object | [<code>IWalletMeta</code>](#IWalletMeta) | data that configures the E-Wallet, which can be shown on checkout page and configures required customer information. |
5433
+
5434
+ **Example**
5435
+ ```js
5436
+ var button = new WalletButtons('#wallet-buttons', 'charge-token', { amount_label: 'Total', country: 'us' });
5437
+ ```
5438
+ <a name="WalletButtons+load" id="WalletButtons+load"></a>
5439
+
5440
+ ### walletButtons.load()
5441
+ Initializes the availability checks and inserts the button if possible.
5442
+ Otherwise function onUnavailable(handler: VoidFunction) will be called.
5443
+
5444
+ **Kind**: instance method of [<code>WalletButtons</code>](#WalletButtons)
5445
+ **Example**
5446
+ ```js
5447
+ var button = new WalletButtons(
5448
+ '#buttons',
5449
+ token,
5450
+ {
5451
+ amount_label: 'Total',
5452
+ country: 'DE',
5453
+ }
5454
+ );
5455
+ button.load();
5456
+ ```
5457
+ <a name="WalletButtons+update" id="WalletButtons+update"></a>
5458
+
5459
+ ### walletButtons.update()
5460
+ Triggers the update process of the wallet, if available.
5461
+ Currently supported by Flypay, Paypal and ApplePay/GooglePay via MPGS Wallets.
5462
+
5463
+ **Kind**: instance method of [<code>WalletButtons</code>](#WalletButtons)
5464
+ **Example**
5465
+ ```js
5466
+ var button = new WalletButtons(
5467
+ '#buttons',
5468
+ token,
5469
+ {
5470
+ amount_label: 'Total',
5471
+ country: 'DE',
5472
+ }
5473
+ );
5474
+ button.on('update', (data) => {
5475
+ updateChargeAmountInBackend(data);
5476
+ button.update({ success: true });
5477
+ });
5478
+ ```
5479
+ **Example**
5048
5480
  ```js
5049
5481
  // ApplePay via MPGS example:
5050
5482
  var button = new WalletButtons(
@@ -5179,409 +5611,137 @@ button.onUpdate((data) => {
5179
5611
  button.update({ success: true });
5180
5612
  });
5181
5613
  ```
5182
- **Example**
5183
- ```js
5184
- button.onUpdate().then((data) => throw new Error());
5185
- ```
5186
- <a name="WalletButtons+onPaymentSuccessful" id="WalletButtons+onPaymentSuccessful"></a>
5187
-
5188
- ### walletButtons.onPaymentSuccessful([handler])
5189
- If the payment was successful, the function passed as parameter will be called.
5190
- Important: Do not perform thread blocking operations in callback such as window.alert() calls.
5191
-
5192
- **Kind**: instance method of [<code>WalletButtons</code>](#WalletButtons)
5193
-
5194
- | Param | Type | Description |
5195
- | --- | --- | --- |
5196
- | [handler] | <code>listener</code> | Function to be called when the payment was successful. |
5197
-
5198
- **Example**
5199
- ```js
5200
- button.onPaymentSuccessful((data) => {
5201
- console.log('Payment successful!');
5202
- });
5203
- ```
5204
- **Example**
5205
- ```js
5206
- button.onPaymentSuccessful().then((data) => console.log('Payment successful!'));
5207
- ```
5208
- <a name="WalletButtons+onPaymentInReview" id="WalletButtons+onPaymentInReview"></a>
5209
-
5210
- ### walletButtons.onPaymentInReview([handler])
5211
- If the payment was left in fraud review, the function passed as parameter will be called.
5212
- Important: Do not perform thread blocking operations in callback such as window.alert() calls.
5213
-
5214
- **Kind**: instance method of [<code>WalletButtons</code>](#WalletButtons)
5215
-
5216
- | Param | Type | Description |
5217
- | --- | --- | --- |
5218
- | [handler] | <code>listener</code> | Function to be called when the payment was left in fraud review status. |
5219
-
5220
- **Example**
5221
- ```js
5222
- button.onPaymentInReview((data) => {
5223
- console.log('Payment in fraud review');
5224
- });
5225
- ```
5226
- **Example**
5227
- ```js
5228
- button.onPaymentInReview().then((data) => console.log('Payment in fraud review'));
5229
- ```
5230
- <a name="WalletButtons+onPaymentError" id="WalletButtons+onPaymentError"></a>
5231
-
5232
- ### walletButtons.onPaymentError([handler])
5233
- If the payment was not successful, the function passed as parameter will be called.
5234
- Important: Do not perform thread blocking operations in callback such as window.alert() calls.
5235
-
5236
- **Kind**: instance method of [<code>WalletButtons</code>](#WalletButtons)
5237
-
5238
- | Param | Type | Description |
5239
- | --- | --- | --- |
5240
- | [handler] | <code>listener</code> | Function to be called when the payment was not successful. |
5241
-
5242
- **Example**
5243
- ```js
5244
- button.onPaymentError((err) => {
5245
- console.log('Payment not successful');
5246
- });
5247
- ```
5248
- **Example**
5249
- ```js
5250
- button.onPaymentError().then((err) => console.log('Payment not successful'));
5251
- ```
5252
- <a name="EVENT" id="EVENT"></a>
5253
-
5254
- ## EVENT : <code>object</code>
5255
- List of available event's name in the wallet button lifecycle
5256
-
5257
- **Kind**: global constant
5258
-
5259
- | Param | Type | Default |
5260
- | --- | --- | --- |
5261
- | UNAVAILABLE | <code>string</code> | <code>&quot;unavailable&quot;</code> |
5262
- | UPDATE | <code>string</code> | <code>&quot;update&quot;</code> |
5263
- | PAYMENT_SUCCESSFUL | <code>string</code> | <code>&quot;paymentSuccessful&quot;</code> |
5264
- | PAYMENT_ERROR | <code>string</code> | <code>&quot;paymentError&quot;</code> |
5265
-
5266
-
5267
- ## Wallet Buttons
5268
- You can find description of all methods and parameters [here](https://www.npmjs.com/package/@paydock/client-sdk#wallet-buttons-simple-example)
5269
-
5270
- Wallet Buttons allow you to easily integrate different E-Wallets into your checkout.
5271
- Currently supports ApplePay, Google Pay and Apple Pay via Stripe, Flypay checkout and Paypal Smart Buttons Checkout.
5272
-
5273
- If available in your client environment, you will display a simple button that upon clicking it the user will follow the standard flow for the appropriate Wallet. If not available an event will be raised and no button will be displayed.
5274
-
5275
- ## Wallet Buttons simple example
5276
-
5277
- ### Container
5278
-
5279
- ```html
5280
- <div id="widget"></div>
5281
- ```
5282
-
5283
- You must create a container for the Wallet Buttons. Inside this tag, the button will be initialized.
5284
-
5285
- Before initializing the button, you must perform a POST request to `charges/wallet` from a secure environment like your server. This call will return a token that is required to load the button and securely complete the payment. You can find the documentation to this call in the PayDock API documentation.
5286
-
5287
- ### Initialization
5288
- The following is the minimum required initialization parameters for Apple Pay and Google Pay via Stripe:
5289
- ```javascript
5290
- let button = new paydock.WalletButtons(
5291
- "#widget",
5292
- token,
5293
- {
5294
- amount_label: "Total",
5295
- country: "DE",
5296
- }
5297
- );
5298
- button.load();
5299
- ```
5300
-
5301
- ```javascript--es2015
5302
- // ES2015 | TypeScript
5303
- import { WalletButtons } from '@paydock/client-sdk';
5304
-
5305
- var button = new WalletButtons(
5306
- '#widget',
5307
- token,
5308
- {
5309
- amount_label: 'Total',
5310
- country: 'DE',
5311
- }
5312
- );
5313
- button.load();
5314
- ```
5315
-
5316
- Flypay and Paypal wallets do not require any meta sent to the wallet, so the following is enough for initialization:
5317
- ```javascript
5318
- let button = new paydock.WalletButtons(
5319
- "#widget",
5320
- token,
5321
- {}
5322
- );
5323
- button.load();
5324
- ```
5325
-
5326
- ```javascript--es2015
5327
- // ES2015 | TypeScript
5328
- import { WalletButtons } from '@paydock/client-sdk';
5329
-
5330
- var button = new WalletButtons(
5331
- '#widget',
5332
- token,
5333
- {}
5334
- );
5335
- button.load();
5336
- ```
5337
- ### Setting environment
5338
-
5339
- Current method can change environment. By default environment = sandbox.
5340
- Bear in mind that you must set an environment before calling `button.load()`.
5341
-
5342
- ```javascript
5343
- button.setEnv('sandbox');
5344
- ```
5345
-
5346
- ### Full example
5347
-
5348
- ```html
5349
- <!DOCTYPE html>
5350
- <html lang="en">
5351
- <head>
5352
- <meta charset="UTF-8">
5353
- <title>Title</title>
5354
- </head>
5355
- <body>
5356
- <h2>Payment using PayDock Wallet Button!</h2>
5357
- <div id="widget"></div>
5358
- </body>
5359
- <script src="https://app-sandbox.paydock.com/v1/widget.umd.js" ></script>
5360
- <script>
5361
- let button = new paydock.WalletButtons(
5362
- "#widget",
5363
- token,
5364
- {
5365
- amount_label: "Total",
5366
- country: "DE",
5367
- }
5368
- );
5369
- button.load();
5370
- </script>
5371
- </html>
5372
- ```
5373
-
5374
- ## Wallet Buttons advanced example
5375
-
5376
- ### Checking for button availability
5377
-
5378
- If the customer's browser is not supported, or the customer does not have any card added to their Google Pay or Apple Pay wallets, the button will not load. In this case the callback onUnavailable() will be called. You can define the behavior of this function before loading the button.
5379
-
5380
- ```javascript
5381
- button.onUnavailable(() => console.log("No wallet buttons available"));
5614
+ **Example**
5615
+ ```js
5616
+ button.onUpdate().then((data) => throw new Error());
5382
5617
  ```
5618
+ <a name="WalletButtons+onPaymentSuccessful" id="WalletButtons+onPaymentSuccessful"></a>
5383
5619
 
5384
- ### Forcibly closing the checkout
5620
+ ### walletButtons.onPaymentSuccessful([handler])
5621
+ If the payment was successful, the function passed as parameter will be called.
5622
+ Important: Do not perform thread blocking operations in callback such as window.alert() calls.
5385
5623
 
5386
- In some situations you may want to forcibly close the checkout so that your user is back in your checkout screen, fow which you can use this method. Currently supported by Flypay wallet only.
5624
+ **Kind**: instance method of [<code>WalletButtons</code>](#WalletButtons)
5387
5625
 
5388
- ```javascript
5389
- button.close();
5390
- ```
5626
+ | Param | Type | Description |
5627
+ | --- | --- | --- |
5628
+ | [handler] | <code>listener</code> | Function to be called when the payment was successful. |
5391
5629
 
5392
- ### Performing actions when shipping info is updated
5630
+ **Example**
5631
+ ```js
5632
+ button.onPaymentSuccessful((data) => {
5633
+ console.log('Payment successful!');
5634
+ });
5635
+ ```
5636
+ **Example**
5637
+ ```js
5638
+ button.onPaymentSuccessful().then((data) => console.log('Payment successful!'));
5639
+ ```
5640
+ <a name="WalletButtons+onPaymentInReview" id="WalletButtons+onPaymentInReview"></a>
5393
5641
 
5394
- In Flypay, Paypal and ApplePay via MPGS integrations after each shipping info update the `onUpdate(data)` will be called with the selected shipping address information (plus selected shipping method for Paypal). Merchants should handle this callback, recalculate shipping costs in their server by analyzing the new data, and submit a backend to backend request to `POST charges/:id` with the new total amount and shipping amount (you can find the documentation of this call in the PayDock API documentation).
5642
+ ### walletButtons.onPaymentInReview([handler])
5643
+ If the payment was left in fraud review, the function passed as parameter will be called.
5644
+ Important: Do not perform thread blocking operations in callback such as window.alert() calls.
5395
5645
 
5396
- For Paypal integration specifically, if shipping is enabled for the wallet button and different shipping methods were provided in the create wallet charge call, Merchants must ensure that the posted `shipping.amount` to `POST charges/:id` matches the selected shipping option amount (value sent in when initializing the wallet charge). In other words, when providing shipping methods the shipping amount is bound to being one of the provided shipping method amount necessarily. Bear in mind that the total charge amount must include the `shipping.amount`, since it represents the full amount to be charged to the customer.
5646
+ **Kind**: instance method of [<code>WalletButtons</code>](#WalletButtons)
5397
5647
 
5398
- After analyzing the new shipping information, and making the post with the updated charge and shipping amounts if necessary, the `button.update({ success: true/false })` wallet button method needs to be called to resume the interactions with the customer. Not calling this will result in unexpected behavior.
5648
+ | Param | Type | Description |
5649
+ | --- | --- | --- |
5650
+ | [handler] | <code>listener</code> | Function to be called when the payment was left in fraud review status. |
5399
5651
 
5400
- ```javascript
5401
- button.onUpdate((data) => {
5402
- console.log("Updating amount via a backend to backend call to POST charges/:id");
5403
- // call `POST charges/:id` to modify charge
5404
- button.update({ success: true });
5652
+ **Example**
5653
+ ```js
5654
+ button.onPaymentInReview((data) => {
5655
+ console.log('Payment in fraud review');
5405
5656
  });
5406
5657
  ```
5658
+ **Example**
5659
+ ```js
5660
+ button.onPaymentInReview().then((data) => console.log('Payment in fraud review'));
5661
+ ```
5662
+ <a name="WalletButtons+onPaymentError" id="WalletButtons+onPaymentError"></a>
5407
5663
 
5408
- For ApplePay via MPGS integration specifically, you must return the new `amount` and new `shipping_options` If new options are needed based on the updated shipping data. Before the user authorizes the transaction with Touch ID, Face ID, or passcode, you receive redacted address information (address_country, address_city, address_state, address_postcode), this data can be used to recalculate the amount and new shipping options. (https://developer.apple.com/documentation/apple_pay_on_the_web/applepaypayment/1916097-shippingcontact)
5664
+ ### walletButtons.onPaymentError([handler])
5665
+ If the payment was not successful, the function passed as parameter will be called.
5666
+ Important: Do not perform thread blocking operations in callback such as window.alert() calls.
5409
5667
 
5410
- ```javascript
5411
- button.onUpdate((data) => {
5412
- console.log("Updating amount via a backend to backend call to POST charges/:id");
5413
- // call `POST charges/:id` to modify charge
5414
- button.update({
5415
- success: true,
5416
- body: {
5417
- amount: 15,
5418
- shipping_options: [
5419
- {
5420
- id: "NEW-FreeShip",
5421
- label: "NEW - Free Shipping",
5422
- detail: "Arrives in 3 to 5 days",
5423
- amount: "0.00"
5424
- },
5425
- {
5426
- id: "NEW - FastShip",
5427
- label: "NEW - Fast Shipping",
5428
- detail: "Arrives in less than 1 day",
5429
- amount: "10.00"
5430
- }
5431
- ]
5432
- }
5433
- });
5668
+ **Kind**: instance method of [<code>WalletButtons</code>](#WalletButtons)
5669
+
5670
+ | Param | Type | Description |
5671
+ | --- | --- | --- |
5672
+ | [handler] | <code>listener</code> | Function to be called when the payment was not successful. |
5673
+
5674
+ **Example**
5675
+ ```js
5676
+ button.onPaymentError((err) => {
5677
+ console.log('Payment not successful');
5434
5678
  });
5435
5679
  ```
5680
+ **Example**
5681
+ ```js
5682
+ button.onPaymentError().then((err) => console.log('Payment not successful'));
5683
+ ```
5684
+ <a name="EVENT" id="EVENT"></a>
5436
5685
 
5437
- ### Performing actions after the payment is completed
5686
+ ## EVENT : <code>object</code>
5687
+ List of available event's name in the wallet button lifecycle
5438
5688
 
5439
- After the payment is completed, the onPaymentSuccessful(data) will be called if the payment was successful. If the payment was not successful, the function onPaymentError(data) will be called. If fraud check is active for the gateway, a fraud body was sent in the wallet charge initialize call and the fraud service left the charge in review, then the onPaymentInReview(data) will be called.
5440
- All three callbacks return relevant data according to each one of the scenarios.
5689
+ **Kind**: global constant
5441
5690
 
5442
- ```javascript
5443
- button.onPaymentSuccessful((data) => console.log("The payment was successful"));
5444
- ```
5691
+ | Param | Type | Default |
5692
+ | --- | --- | --- |
5693
+ | UNAVAILABLE | <code>string</code> | <code>&quot;unavailable&quot;</code> |
5694
+ | UPDATE | <code>string</code> | <code>&quot;update&quot;</code> |
5695
+ | PAYMENT_SUCCESSFUL | <code>string</code> | <code>&quot;paymentSuccessful&quot;</code> |
5696
+ | PAYMENT_ERROR | <code>string</code> | <code>&quot;paymentError&quot;</code> |
5445
5697
 
5446
- ```javascript
5447
- button.onPaymentInReview((data) => console.log("The payment is on fraud review"));
5448
- ```
5449
5698
 
5450
- ```javascript
5451
- button.onPaymentError((data) => console.log("The payment was not successful"));
5452
- ```
5453
- ### Events
5454
- The above events can be used in a more generic way via de `on` function, and making use
5455
- of the corresponding event names.
5699
+ ## Secure Remote Commerce
5700
+ You can find description of all methods and parameters [here](https://www.npmjs.com/package/@paydock/client-sdk#SRC).
5456
5701
 
5457
- ```javascript
5458
- button.on(EVENT.UNAVAILABLE, () => console.log("No wallet buttons available"));
5459
- button.on(EVENT.UPDATE, (data) => console.log("Updating amount via a backend to backend call to POST charges/:id");
5460
- button.on(EVENT.PAYMENT_SUCCESSFUL, (data) => console.log("The payment was successful"));
5461
- button.on(EVENT.PAYMENT_ERROR, (data) => console.log("The payment was not successful"));
5462
- ```
5702
+ This widget provides you with the ability to easily integrate with SRC providers. Currently Visa SRC is supported.
5463
5703
 
5464
- This example shows how to use these functions for **Apple and Google Pay via Stripe**:
5465
- _(Required `meta` fields: `amount_label`, `country`. Optional `meta` fields: `wallets`)_
5466
- ### Full example
5704
+ ## SRC simple example
5705
+
5706
+ ### Container
5467
5707
 
5468
5708
  ```html
5469
- <!DOCTYPE html>
5470
- <html lang="en">
5471
- <head>
5472
- <meta charset="UTF-8">
5473
- <title>Title</title>
5474
- </head>
5475
- <body>
5476
- <h2>Payment using PayDock Wallet Button!</h2>
5477
- <div id="widget"></div>
5478
- </body>
5479
- <script src="https://app-sandbox.paydock.com/v1/widget.umd.js" ></script>
5480
- <script>
5481
- let button = new paydock.WalletButtons(
5482
- "#widget",
5483
- charge_token,
5484
- {
5485
- amount_label: "Total",
5486
- country: "DE",
5487
- wallets: ["google", "apple"],
5488
- }
5489
- );
5490
- button.setEnv('sandbox');
5491
- button.onUnavailable(() => console.log("No wallet buttons available"));
5492
- button.onPaymentSuccessful((data) => console.log("The payment was successful"));
5493
- button.onPaymentError((data) => console.log("The payment was not successful"));
5494
- button.onPaymentInReview((data) => console.log("The payment is on fraud review"));
5495
- button.load();
5496
- </script>
5497
- </html>
5709
+ <div id="checkoutButton"></div>
5710
+ <div id="checkoutIframe"></div>
5498
5711
  ```
5499
5712
 
5500
- This example shows how to use these functions for **Paypal Smart Checkout Buttons**:
5501
- _(Required `meta` fields: - . Optional `meta` fields: `request_shipping`, `pay_later`, `style`)_
5502
- ### Full example
5503
- ```html
5504
- <!DOCTYPE html>
5505
- <html lang="en">
5506
- <head>
5507
- <meta charset="UTF-8">
5508
- <title>Title</title>
5509
- </head>
5510
- <body>
5511
- <h2>Payment using PayDock Wallet Button!</h2>
5512
- <div id="widget"></div>
5513
- </body>
5514
- <script src="https://app-sandbox.paydock.com/v1/widget.umd.js" ></script>
5515
- <script>
5516
- let button = new paydock.WalletButtons(
5517
- "#widget",
5518
- charge_token,
5519
- {
5520
- request_shipping: true,
5521
- pay_later: true,
5522
- style: {
5523
- layout: 'horizontal',
5524
- color: 'blue',
5525
- shape: 'rect',
5526
- label: 'paypal',
5527
- },
5528
- }
5529
- );
5530
- button.setEnv('sandbox');
5531
- button.onUnavailable(() => console.log("No wallet buttons available"));
5532
- button.onUpdate((data) => {
5533
- console.log("Updating amount via a backend to backend call to POST charges/:id");
5534
- // call `POST charges/:id` to modify charge
5535
- button.update({ success: true });
5536
- });
5537
- button.onPaymentSuccessful((data) => console.log("The payment was successful"));
5538
- button.onPaymentError((data) => console.log("The payment was not successful"));
5539
- button.onPaymentInReview((data) => console.log("The payment is on fraud review"));
5540
- button.load();
5541
- </script>
5542
- </html>
5713
+ You must create a container for the initial checkout button, and a different one for the checkout iFrame. Inside the first tag the button will be initialized, and inside the second one the iFrame will be loaded once the button is clicked.
5714
+
5715
+
5716
+ ### Initialization
5717
+ ```javascript
5718
+ var src = new paydock.SRC(
5719
+ "#checkoutButton",
5720
+ "#checkoutIframe",
5721
+ "scheme_service_id",
5722
+ "paydock_public_key_or_access_token",
5723
+ {}, // meta
5724
+ );
5725
+ src.load();
5543
5726
  ```
5544
5727
 
5545
- This example shows how to use these functions for **Flypay Checkout**.
5546
- _(Required `meta` fields: - . Optional `meta` fields: `request_shipping`, `pay_later`, `style`)_
5547
- ### Full example
5548
- ```html
5549
- <!DOCTYPE html>
5550
- <html lang="en">
5551
- <head>
5552
- <meta charset="UTF-8">
5553
- <title>Title</title>
5554
- </head>
5555
- <body>
5556
- <h2>Payment using PayDock Wallet Button!</h2>
5557
- <div id="widget"></div>
5558
- </body>
5559
- <script src="https://app-sandbox.paydock.com/v1/widget.umd.js" ></script>
5560
- <script>
5561
- let button = new paydock.WalletButtons(
5562
- "#widget",
5563
- charge_token,
5564
- {
5565
- request_shipping: true
5566
- }
5567
- );
5568
- button.setEnv('sandbox');
5569
- button.onUnavailable(() => console.log("No wallet buttons available"));
5570
- button.onUpdate((data) => {
5571
- console.log("Updating amount via a backend to backend call to POST charges/:id");
5572
- // call `POST charges/:id` to modify charge
5573
- button.update({ success: true });
5574
- });
5575
- button.onPaymentSuccessful((data) => console.log("The payment was successful"));
5576
- button.onPaymentError((data) => console.log("The payment was not successful"));
5577
- button.onPaymentInReview((data) => console.log("The payment is on fraud review"));
5578
- button.load();
5579
- </script>
5580
- </html>
5728
+ ```javascript--es2015
5729
+ // ES2015 | TypeScript
5730
+
5731
+ import { SRC } from '@paydock/client-sdk';
5732
+
5733
+ var src = new SRC(
5734
+ "#checkoutButton",
5735
+ "#checkoutIframe",
5736
+ "scheme_service_id",
5737
+ "paydock_public_key_or_access_token",
5738
+ {}, // meta
5739
+ );
5740
+ src.load();
5581
5741
  ```
5582
5742
 
5583
- This example shows how to use these functions for **ApplePay via MPGS**:
5584
- _(Required `meta` fields: `amount_label`, `country`. Optional `meta` fields: `raw_data_initialization`, `request_shipping`, `style.button_type`)_
5743
+ *NOTE:* it's highly recommended to use a Paydock Access Token instead of the public key for security reasons. When creating it, you will need to enable the `Secure Remote Commerce` and add a whiteliste for the domain of your checkout screen.
5744
+
5585
5745
  ### Full example
5586
5746
 
5587
5747
  ```html
@@ -5590,51 +5750,71 @@ _(Required `meta` fields: `amount_label`, `country`. Optional `meta` fields: `ra
5590
5750
  <head>
5591
5751
  <meta charset="UTF-8">
5592
5752
  <title>Title</title>
5753
+ <style>iframe {border: 0;width: 40%;height: 300px;}</style>
5593
5754
  </head>
5594
5755
  <body>
5595
- <h2>Payment using PayDock Wallet Button!</h2>
5596
- <div id="widget"></div>
5756
+ <div id="checkoutButton"></div>
5757
+ <div id="checkoutIframe"></div>
5758
+ <script src="https://app-sandbox.paydock.com/v1/widget.umd.js" ></script>
5759
+ <script>
5760
+ var src = new paydock.SRC(
5761
+ "#checkoutButton",
5762
+ "#checkoutIframe",
5763
+ "scheme_service_id",
5764
+ "paydock_public_key_or_access_token",
5765
+ {},
5766
+ );
5767
+ src.load();
5768
+ </script>
5597
5769
  </body>
5598
- <script src="https://app-sandbox.paydock.com/v1/widget.umd.js" ></script>
5599
- <script>
5600
- let button = new paydock.WalletButtons(
5601
- "#widget",
5602
- charge_token,
5603
- {
5604
- amount_label: "Total",
5605
- country: 'DE',
5606
- request_shipping: true,
5607
- style: {
5608
- button_type: 'buy',
5609
- },
5610
- shipping_options: [
5611
- {
5612
- id: "FreeShip",
5613
- label: "Free Shipping",
5614
- detail: "Arrives in 5 to 7 days",
5615
- amount: "0.00"
5616
- },
5617
- {
5618
- id: "FastShip",
5619
- label: "Fast Shipping",
5620
- detail: "Arrives in 1 day",
5621
- amount: "10.00"
5622
- }
5623
- ]
5624
- }
5625
- );
5626
- button.setEnv('sandbox');
5627
- button.onUnavailable(() => console.log("No wallet buttons available"));
5628
- button.onPaymentSuccessful((data) => console.log("The payment was successful"));
5629
- button.onPaymentError((data) => console.log("The payment was not successful"));
5630
- button.load();
5631
- </script>
5632
5770
  </html>
5633
5771
  ```
5634
5772
 
5635
- Also, for **ApplePay via MPGS** you can initialize the `ApplePayPaymentRequest` with your own values instead of using the default ones. Below you can see an example on how to initialize the `ApplePayPaymentRequest` with the `raw_data_initialization` meta field:
5636
5773
 
5637
- ### Raw data initialization example
5774
+ ## SRC advanced example
5775
+
5776
+ ### Settings
5777
+
5778
+ ```javascript
5779
+
5780
+ src.setEnv('sandbox'); // set enviroment
5781
+
5782
+ src.hideButton(); // hide button
5783
+
5784
+ src.showButton(); // show button
5785
+
5786
+ src.hideCheckout(); // hide checkout iframe
5787
+
5788
+ src.showCheckout(); // show checkout iframe
5789
+
5790
+ src.on('checkoutButtonLoaded', () => {
5791
+ console.log("Button loaded");
5792
+ });
5793
+
5794
+ src.on('checkoutButtonClicked', () => {
5795
+ console.log("Button clicked");
5796
+ });
5797
+
5798
+ src.on('iframeLoaded', () => {
5799
+ console.log("Initial iframe loaded");
5800
+ });
5801
+
5802
+ src.on('checkoutReady', () => {
5803
+ console.log("Checkout ready to be used");
5804
+ });
5805
+
5806
+ src.on('checkoutCompleted', (token) => {
5807
+ console.log(token);
5808
+ });
5809
+
5810
+ src.on('checkoutError', (error) => {
5811
+ console.log(error);
5812
+ });
5813
+ ```
5814
+
5815
+ Here you can see how you can use this methods to customize your checkout experience
5816
+
5817
+ ### Full example
5638
5818
 
5639
5819
  ```html
5640
5820
  <!DOCTYPE html>
@@ -5642,60 +5822,139 @@ Also, for **ApplePay via MPGS** you can initialize the `ApplePayPaymentRequest`
5642
5822
  <head>
5643
5823
  <meta charset="UTF-8">
5644
5824
  <title>Title</title>
5825
+ <style>iframe {border: 0;width: 40%;height: 450px;}</style>
5645
5826
  </head>
5646
5827
  <body>
5647
- <h2>Payment using PayDock Wallet Button!</h2>
5648
- <div id="widget"></div>
5828
+ <div id="checkoutButton"></div>
5829
+ <div id="checkoutIframe"></div>
5830
+ <script src="https://app-sandbox.paydock.com/v1/widget.umd.js" ></script>
5831
+ <script>
5832
+ var src = new paydock.SRC(
5833
+ "#checkoutButton",
5834
+ "#checkoutIframe",
5835
+ "scheme_service_id",
5836
+ "paydock_public_key_or_access_token",
5837
+ {},
5838
+ );
5839
+
5840
+ src.on('checkoutReady', () => {
5841
+ console.log("Checkout ready to be used");
5842
+ });
5843
+
5844
+ src.on('checkoutCompleted', (token) => {
5845
+ console.log(token);
5846
+ });
5847
+ src.load();
5848
+ </script>
5649
5849
  </body>
5650
- <script src="https://app-sandbox.paydock.com/v1/widget.umd.js" ></script>
5651
- <script>
5652
- let button = new paydock.WalletButtons(
5653
- "#widget",
5654
- charge_token,
5655
- {
5656
- raw_data_initialization: {
5657
- countryCode: "AU",
5658
- currencyCode: "AUD",
5659
- merchantCapabilities: ["supports3DS","supportsCredit","supportsDebit"],
5660
- supportedNetworks: ["visa","masterCard","amex","discover"],
5661
- requiredBillingContactFields: ["name","postalAddress"],
5662
- requiredShippingContactFields:["postalAddress","name","phone","email" ],
5663
- total: {
5664
- label: "Total",
5665
- amount: "10",
5666
- type: "final",
5667
- }
5668
- },
5669
- amount_label: "Total",
5670
- country: 'DE',
5671
- request_shipping: true,
5672
- style: {
5673
- button_type: 'buy',
5850
+ </html>
5851
+ ```
5852
+
5853
+ ## Customization options for address fields
5854
+ ### Shipping address:
5855
+
5856
+ To customize shipping address experience we use a flag that manages how VisaSRC requires or not shipping address to the customer. Options are NONE (default option), POSTAL_COUNTRY or ALL.
5857
+
5858
+ ```
5859
+ var src = new paydock.SRC(
5860
+ "#checkoutButton",
5861
+ "#checkoutIframe",
5862
+ "scheme_service_id",
5863
+ "paydock_public_key_or_access_token",
5864
+ {
5865
+ "dpa_transaction_options": {
5866
+ "dpa_shipping_preference": "ALL"
5867
+ }
5868
+ },
5869
+ );
5870
+ ```
5871
+
5872
+ With this the Visa popup requires the shipping address from consumer, and these information will be stored in the Paydock charge.
5873
+
5874
+ Another option is at time of creating the charge. Say that you have a different way of collecting the shipping address (outside Paydock checkout), you can then disable the shipping address on our SRC widget and send it when creating the charge creation after getting the One Time Token out of the SRC widget:
5875
+
5876
+ ```
5877
+ POST v1/charges
5878
+
5879
+ {
5880
+ "amount": "10.00",
5881
+ "currency": "AUD",
5882
+ "token": "token",
5883
+ "customer": {
5884
+ "payment_source": {
5885
+ "gateway_id": "gateway_id"
5886
+ }
5887
+ },
5888
+ "shipping": {
5889
+ "address_line1": "address_line1",
5890
+ "address_line2": "address_line2",
5891
+ "address_line3": "address_line3",
5892
+ "address_city": "address_city",
5893
+ "address_postcode": "address_postcode",
5894
+ "address_state": "address_state",
5895
+ "address_country": "address_country"
5896
+ }
5897
+ }
5898
+ ```
5899
+
5900
+ - Billing address:
5901
+
5902
+ Billing address fields are always present on the checkout and required when adding a new credit card (or for new consumer checkout). You can send billing fields on the meta data to pre-fill these fields inside the customer object:
5903
+
5904
+ ```
5905
+ var src = new paydock.SRC(
5906
+ "#checkoutButton",
5907
+ "#checkoutIframe",
5908
+ "scheme_service_id",
5909
+ "paydock_public_key_or_access_token",
5910
+ {
5911
+ "customer": {
5912
+ "email": "test@email.com",
5913
+ "first_name": "Name",
5914
+ "last_name": "Surname",
5915
+ "phone": {
5916
+ "country_code": "1",
5917
+ "phone": "2124567890"
5674
5918
  },
5675
- shipping_options: [
5676
- {
5677
- id: "FreeShip",
5678
- label: "Free Shipping",
5679
- detail: "Arrives in 5 to 7 days",
5680
- amount: "0.00"
5681
- },
5682
- {
5683
- id: "FastShip",
5684
- label: "Fast Shipping",
5685
- detail: "Arrives in 1 day",
5686
- amount: "10.00"
5687
- }
5688
- ]
5919
+ "payment_source": {
5920
+ "address_line1": "Line 1",
5921
+ "address_line2": "Line 2",
5922
+ "address_city": "Miami",
5923
+ "address_postcode": "33126",
5924
+ "address_state": "FL",
5925
+ "address_country": "US"
5926
+ }
5689
5927
  }
5690
- );
5691
- button.setEnv('sandbox');
5692
- button.onUnavailable(() => console.log("No wallet buttons available"));
5693
- button.onPaymentSuccessful((data) => console.log("The payment was successful"));
5694
- button.onPaymentError((data) => console.log("The payment was not successful"));
5695
- button.load();
5696
- </script>
5697
- </html>
5928
+ },
5929
+ );
5930
+ ```
5931
+
5932
+ ## Personalization Styling
5933
+
5934
+ To improve the experience in the use of the widget, it is allowed to send props that customize the UI.
5935
+
5936
+ ### Example code
5937
+
5938
+ ```
5939
+ var src = new paydock.SRC(
5940
+ "#checkoutButton",
5941
+ "#checkoutIframe",
5942
+ "scheme_service_id",
5943
+ "paydock_public_key",
5944
+ );
5945
+
5946
+ button.setStyles({"primary_color":"#a83232","button_text_color":"#171e9c","font_family":"sans-serif"})
5947
+
5698
5948
  ```
5949
+ ## Event and Values
5950
+
5951
+ | Event Value | Type | Description |
5952
+ | ------------------- | ------------------- | -------------------------------------------------------------- |
5953
+ | primary_color | <code>string</code> | HEX color for the principal buttons, example : #32a852 |
5954
+ | button_text_color | <code>string</code> | HEX color for the text of the buttons, example : #32a852|
5955
+ | font_family | <code>string</code> | Look more [mozilla.org/color](https://developer.mozilla.org/en-US/docs/Web/CSS/font-family)|
5956
+ | card_schemes | <code>[string] - array of string</code> | Possible values "visa", "mastercard", "amex" and "discover" - Default show all logos
5957
+
5699
5958
  ## Classes
5700
5959
 
5701
5960
  <dl>
@@ -5771,7 +6030,8 @@ Class SRC include methods for interacting with different secure remote commerce
5771
6030
  **Kind**: global class
5772
6031
 
5773
6032
  * [SRC](#SRC)
5774
- * [new exports.SRC(button_selector, iframe_selector, service_id, public_key, meta)](#new_SRC_new)
6033
+ * [new exports.SRC(button_selector, iframe_selector, service_id, public_key_or_access_token, meta)](#new_SRC_new)
6034
+ * [.setStyles(fields)](#SRC+setStyles)
5775
6035
  * [.load()](#SRC+load)
5776
6036
  * [.setEnv(env, [alias])](#SRC+setEnv)
5777
6037
  * [.getEnv()](#SRC+getEnv)
@@ -5785,20 +6045,40 @@ Class SRC include methods for interacting with different secure remote commerce
5785
6045
 
5786
6046
  <a name="new_SRC_new" id="new_SRC_new"></a>
5787
6047
 
5788
- ### new exports.SRC(button_selector, iframe_selector, service_id, public_key, meta)
6048
+ ### new exports.SRC(button_selector, iframe_selector, service_id, public_key_or_access_token, meta)
5789
6049
 
5790
6050
  | Param | Type | Description |
5791
6051
  | --- | --- | --- |
5792
6052
  | button_selector | <code>string</code> | Selector of html element. Container for SRC checkout button. |
5793
6053
  | iframe_selector | <code>string</code> | Selector of html element. Container for SRC checkout iFrame. |
5794
6054
  | service_id | <code>string</code> | Card Scheme Service ID |
5795
- | public_key | <code>string</code> | Paydock public key |
6055
+ | public_key_or_access_token | <code>string</code> | Paydock public key or Access Token |
5796
6056
  | meta | [<code>IVisaSRCMeta</code>](#IVisaSRCMeta) | Data that configures the SRC checkout |
5797
6057
 
5798
6058
  **Example**
5799
6059
  ```js
5800
6060
  var SRC = new SRC('#checkoutButton', '#checkoutIframe', 'service_id', 'public_key', {});
5801
6061
  ```
6062
+ <a name="SRC+setStyles" id="SRC+setStyles"></a>
6063
+
6064
+ ### srC.setStyles(fields)
6065
+ Object contain styles for widget - call before `.load()`.
6066
+
6067
+ **Kind**: instance method of [<code>SRC</code>](#SRC)
6068
+
6069
+ | Param | Type | Description |
6070
+ | --- | --- | --- |
6071
+ | fields | <code>IStyles</code> | name of styles which can be shown in widget [STYLE](STYLE) |
6072
+
6073
+ **Example**
6074
+ ```js
6075
+ widget.setStyles({
6076
+ button_text_color: '#32a852',
6077
+ primary_color: '#32a852',
6078
+ font_family: 'sans-serif',
6079
+ card_schemes: ['visa']
6080
+ });
6081
+ ```
5802
6082
  <a name="SRC+load" id="SRC+load"></a>
5803
6083
 
5804
6084
  ### srC.load()
@@ -5941,236 +6221,5 @@ List of available event's name in the SRC checkout lifecycle
5941
6221
  | CHECKOUT_ERROR | <code>string</code> | <code>&quot;checkoutError&quot;</code> |
5942
6222
 
5943
6223
 
5944
- ## Secure Remote Commerce
5945
- You can find description of all methods and parameters [here](https://www.npmjs.com/package/@paydock/client-sdk#secure-remote-commerce)
5946
-
5947
- This widget provides you with the ability to easily integrate with SRC providers. Currently Visa SRC is supported.
5948
-
5949
- ## SRC simple example
5950
-
5951
- ### Container
5952
-
5953
- ```html
5954
- <div id="checkoutButton"></div>
5955
- <div id="checkoutIframe"></div>
5956
- ```
5957
-
5958
- You must create a container for the initial checkout button, and a different one for the checkout iFrame. Inside the first tag the button will be initialized, and inside the second one the iFrame will be loaded once the button is clicked.
5959
-
5960
-
5961
- ### Initialization
5962
- ```javascript
5963
- var src = new paydock.SRC(
5964
- "#checkoutButton",
5965
- "#checkoutIframe",
5966
- "scheme_service_id",
5967
- "paydock_public_key",
5968
- {}, // meta
5969
- );
5970
- src.load();
5971
- ```
5972
-
5973
- ```javascript--es2015
5974
- // ES2015 | TypeScript
5975
-
5976
- import { SRC } from '@paydock/client-sdk';
5977
-
5978
- var src = new SRC(
5979
- "#checkoutButton",
5980
- "#checkoutIframe",
5981
- "scheme_service_id",
5982
- "paydock_public_key",
5983
- {}, // meta
5984
- );
5985
- src.load();
5986
- ```
5987
-
5988
- ### Full example
5989
-
5990
- ```html
5991
- <!DOCTYPE html>
5992
- <html lang="en">
5993
- <head>
5994
- <meta charset="UTF-8">
5995
- <title>Title</title>
5996
- <style>iframe {border: 0;width: 40%;height: 300px;}</style>
5997
- </head>
5998
- <body>
5999
- <div id="checkoutButton"></div>
6000
- <div id="checkoutIframe"></div>
6001
- <script src="https://app-sandbox.paydock.com/v1/widget.umd.js" ></script>
6002
- <script>
6003
- var src = new paydock.SRC(
6004
- "#checkoutButton",
6005
- "#checkoutIframe",
6006
- "scheme_service_id",
6007
- "paydock_public_key",
6008
- {},
6009
- );
6010
- src.load();
6011
- </script>
6012
- </body>
6013
- </html>
6014
- ```
6015
-
6016
-
6017
- ## SRC advanced example
6018
-
6019
- ### Settings
6020
-
6021
- ```javascript
6022
-
6023
- src.setEnv('sandbox'); // set enviroment
6024
-
6025
- src.hideButton(); // hide button
6026
-
6027
- src.showButton(); // show button
6028
-
6029
- src.hideCheckout(); // hide checkout iframe
6030
-
6031
- src.showCheckout(); // show checkout iframe
6032
-
6033
- src.on('checkoutButtonLoaded', () => {
6034
- console.log("Button loaded");
6035
- });
6036
-
6037
- src.on('checkoutButtonClicked', () => {
6038
- console.log("Button clicked");
6039
- });
6040
-
6041
- src.on('iframeLoaded', () => {
6042
- console.log("Initial iframe loaded");
6043
- });
6044
-
6045
- src.on('checkoutReady', () => {
6046
- console.log("Checkout ready to be used");
6047
- });
6048
-
6049
- src.on('checkoutCompleted', (token) => {
6050
- console.log(token);
6051
- });
6052
-
6053
- src.on('checkoutError', (error) => {
6054
- console.log(error);
6055
- });
6056
- ```
6057
-
6058
- Here you can see how you can use this methods to customize your checkout experience
6059
-
6060
- ### Full example
6061
-
6062
- ```html
6063
- <!DOCTYPE html>
6064
- <html lang="en">
6065
- <head>
6066
- <meta charset="UTF-8">
6067
- <title>Title</title>
6068
- <style>iframe {border: 0;width: 40%;height: 450px;}</style>
6069
- </head>
6070
- <body>
6071
- <div id="checkoutButton"></div>
6072
- <div id="checkoutIframe"></div>
6073
- <script src="https://app-sandbox.paydock.com/v1/widget.umd.js" ></script>
6074
- <script>
6075
- var src = new paydock.SRC(
6076
- "#checkoutButton",
6077
- "#checkoutIframe",
6078
- "scheme_service_id",
6079
- "paydock_public_key",
6080
- {},
6081
- );
6082
-
6083
- src.on('checkoutReady', () => {
6084
- console.log("Checkout ready to be used");
6085
- });
6086
-
6087
- src.on('checkoutCompleted', (token) => {
6088
- console.log(token);
6089
- });
6090
- src.load();
6091
- </script>
6092
- </body>
6093
- </html>
6094
- ```
6095
-
6096
- ## Customization options for address fields
6097
- ### Shipping address:
6098
-
6099
- To customize shipping address experience we use a flag that manages how VisaSRC requires or not shipping address to the customer. Options are NONE (default option), POSTAL_COUNTRY or ALL.
6100
-
6101
- ```
6102
- var src = new paydock.SRC(
6103
- "#checkoutButton",
6104
- "#checkoutIframe",
6105
- "scheme_service_id",
6106
- "paydock_public_key",
6107
- {
6108
- "dpa_transaction_options": {
6109
- "dpa_shipping_preference": "ALL"
6110
- }
6111
- },
6112
- );
6113
- ```
6114
-
6115
- With this the Visa popup requires the shipping address from consumer, and these information will be stored in the Paydock charge.
6116
-
6117
- Another option is at time of creating the charge. Say that you have a different way of collecting the shipping address (outside Paydock checkout), you can then disable the shipping address on our SRC widget and send it when creating the charge creation after getting the One Time Token out of the SRC widget:
6118
-
6119
- ```
6120
- POST v1/charges
6121
-
6122
- {
6123
- "amount": "10.00",
6124
- "currency": "AUD",
6125
- "token": "token",
6126
- "customer": {
6127
- "payment_source": {
6128
- "gateway_id": "gateway_id"
6129
- }
6130
- },
6131
- "shipping": {
6132
- "address_line1": "address_line1",
6133
- "address_line2": "address_line2",
6134
- "address_line3": "address_line3",
6135
- "address_city": "address_city",
6136
- "address_postcode": "address_postcode",
6137
- "address_state": "address_state",
6138
- "address_country": "address_country"
6139
- }
6140
- }
6141
- ```
6142
-
6143
- - Billing address:
6144
-
6145
- Billing address fields are always present on the checkout and required when adding a new credit card (or for new consumer checkout). You can send billing fields on the meta data to pre-fill these fields inside the customer object:
6146
-
6147
- ```
6148
- var src = new paydock.SRC(
6149
- "#checkoutButton",
6150
- "#checkoutIframe",
6151
- "scheme_service_id",
6152
- "paydock_public_key",
6153
- {
6154
- "customer": {
6155
- "email": "test@email.com",
6156
- "first_name": "Name",
6157
- "last_name": "Surname",
6158
- "phone": {
6159
- "country_code": "1",
6160
- "phone": "2124567890"
6161
- },
6162
- "payment_source": {
6163
- "address_line1": "Line 1",
6164
- "address_line2": "Line 2",
6165
- "address_city": "Miami",
6166
- "address_postcode": "33126",
6167
- "address_state": "FL",
6168
- "address_country": "US"
6169
- }
6170
- }
6171
- },
6172
- );
6173
- ```
6174
-
6175
6224
  ## License
6176
6225
  Copyright (c) 2017 paydock