You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pay/README.md
+59-10Lines changed: 59 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,12 +27,10 @@ dependencies:
27
27
pay: ^1.0.11
28
28
```
29
29
30
-
### Payment configuration
31
-
Create a payment profile with the desired configuration for your payment, either using a local file or loading it from a remote server. Take a look at some examples under the [`example/assets/` folder](https://github.com/google-pay/flutter-plugin/tree/main/pay/example/assets) and explore the documentation for a complete list of options available:
Define the configuration for your payment provider(s). Take a look at the parameters available in the documentation for [Apple Pay](https://developer.apple.com/documentation/passkit/pkpaymentrequest) and [Google Pay](https://developers.google.com/pay/api/android/reference/request-objects), and explore the [sample configurations in this package](https://github.com/google-pay/flutter-plugin/tree/main/pay/example/lib/payment_configurations.dart).
34
31
35
32
### Example
33
+
This snippet assumes the existence a payment configuration for Apple Pay ([`defaultApplePayConfigString`](https://github.com/google-pay/flutter-plugin/tree/main/pay/example/lib/payment_configurations.dart#L27)) and another one for Google Pay ([`defaultGooglePayConfigString`](https://github.com/google-pay/flutter-plugin/tree/main/pay/example/lib/payment_configurations.dart#L63)):
// Send the resulting Google Pay token to your server / PSP
76
76
}
77
77
```
78
+
79
+
### Alternative methods to load your payment configurations
80
+
#### JSON strings
81
+
The example above uses the `PaymentConfiguration.fromJsonString` method to load your payment configuration from a string in JSON format ([example](https://github.com/google-pay/flutter-plugin/tree/main/pay/example/lib/payment_configurations.dart#L27)). This configuration can be retrieved from a remote location at runtime ([recommended](https://github.com/google-pay/flutter-plugin/tree/main/pay/example/lib/payment_configurations.dart#L18)) or provided at build time.
82
+
83
+
#### Asset files
84
+
You can also place payment configurations under your `assets` folder and load them at runtime. Suppose that you add a JSON file with the name `google_pay_config.json` to your `assets` folder to configure your Google Pay integration. You can load it in your app state and use it to create a `PaymentConfiguration` object for the button:
If you prefer to have more control over each individual request and the button separately, you can instantiate a payment client and add the buttons to your layout independently:
80
124
@@ -89,10 +133,15 @@ const _paymentItems = [
89
133
)
90
134
];
91
135
92
-
Pay _payClient = Pay.withAssets([
93
-
'default_payment_profile_apple_pay.json',
94
-
'default_payment_profile_google_pay.json'
95
-
]);
136
+
final applePayConfig = PaymentConfiguration.fromJsonString(
137
+
defaultApplePayConfigString)
138
+
final googlePayConfig = PaymentConfiguration.fromJsonString(
139
+
defaultGooglePayConfigString)
140
+
141
+
Pay _payClient = Pay({
142
+
PayProvider.apple_pay: applePayConfig,
143
+
PayProvider.google_pay: googlePayConfig
144
+
});
96
145
```
97
146
98
147
As you can see, you can add multiple configurations to your payment client, one for each payment provider supported.
0 commit comments