Skip to content

Commit

Permalink
update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
vinceramcesoliveros committed Jun 30, 2021
1 parent d4eb5ea commit b914165
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 123 deletions.
5 changes: 2 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
## [0.0.1] - TODO: Add release date.

* TODO: Describe initial release.
## [1.0.1]
- added documentation for `Source`
110 changes: 19 additions & 91 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,30 +65,29 @@ class _MyAppState extends State<MyApp> {
onPressed: () async {
final _amount = _cart.fold<num>(0,
(previousValue, element) => previousValue + element.amount);
final source = PayMongoSDK(payMongoKey);
final sdk = PayMongoSDK(payMongoKey);
final url = 'google.com';
final result = await source.createSource(
Source(
type: "gcash",
amount: _amount.toDouble(),
currency: 'PHP',
redirect: Redirect(
success: "https://$url/success",
failed: "https://$url/failed",
),
billing: PayMongoBilling(
address: PayMongoAddress(
city: "Cotabato City",
country: "PH",
state: "Mindanao",
line1: "Secret Address",
),
name: "Anonymous",
email: "[email protected]",
phone: "09123456002",
final _source = Source(
type: "gcash",
amount: _amount.toDouble(),
currency: 'PHP',
redirect: Redirect(
success: "https://$url/success",
failed: "https://$url/failed",
),
billing: PayMongoBilling(
address: PayMongoAddress(
city: "Cotabato City",
country: "PH",
state: "Mindanao",
line1: "Secret Address",
),
name: "Anonymous",
email: "[email protected]",
phone: "09123456002",
),
);
final result = await sdk.createSource(_source);
final response = await Navigator.push<String>(
context,
CupertinoPageRoute(
Expand All @@ -105,77 +104,6 @@ class _MyAppState extends State<MyApp> {
label: Text('Single Payment(${_cart?.length})'),
icon: const Icon(Icons.credit_card),
),
// FloatingActionButton.extended(
// onPressed: () async {
// final _amount = _cart.fold<num>(0,
// (previousValue, element) => previousValue + element.amount);
// final _items = _cart.map((cart) {
// return PaymayaItem(
// name: cart.name,
// quantity: 1,
// code: 'ABP-797',
// description: cart.description,
// amount: PaymayaAmount(
// value: cart.amount,
// currency: cart.currency,
// ),
// totalAmount: PaymayaAmount(
// value: cart.amount,
// currency: cart.currency,
// ),
// );
// }).toList();
// final totalAmount = PaymayaAmount(
// value: _amount,
// currency: 'PHP',
// );
// const _buyer = PaymayaBuyer(
// firstName: 'John',
// middleName: '',
// lastName: 'Doe',
// customerSince: '2020-01-01',
// birthday: '1998-01-01',
// contact: PaymayaContact(
// email: '[email protected]', phone: '0912345678'),
// billingAddress: PaymayaBillingAddress(
// city: 'Davao City',
// countryCode: 'PH',
// zipCode: '8000',
// state: 'Davao',
// ),
// shippingAddress: PaymayaShippingAddress(
// city: 'Davao City',
// countryCode: 'PH',
// zipCode: '8000',
// state: 'Davao',
// firstName: 'John',
// middleName: '',
// lastName: 'Doe',
// email: '[email protected]',
// // ST - Standard
// // SD - Same Day
// shippingType: ShippingType.sd,
// ),
// );
// final redirectUrls = const PaymayaRedirectUrls(
// success: '',
// failure: '',
// cancel: '',
// );
// final _checkout = PaymayaCheckout(
// totalAmount: totalAmount,
// buyer: _buyer,
// items: _items,
// redirectUrl: redirectUrls,
// requestReferenceNumber: '6319921');
// final result = await _payMayaSdk.createCheckOut(
// _checkout,
// );
// await _onRedirectUrl(result.redirectUrl);
// },
// label: Text('Checkout Cart(${_cart.length})'),
// icon: const Icon(Icons.shopping_basket),
// ),
],
));
}
Expand Down
10 changes: 5 additions & 5 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ packages:
name: cupertino_icons
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
version: "1.0.3"
equatable:
dependency: transitive
description:
name: equatable
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
version: "2.0.3"
fake_async:
dependency: transitive
description:
Expand Down Expand Up @@ -115,7 +115,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.0.0"
version: "1.0.1"
pedantic:
dependency: transitive
description:
Expand Down Expand Up @@ -190,7 +190,7 @@ packages:
name: webview_flutter
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.7"
version: "2.0.9"
sdks:
dart: ">=2.12.0 <3.0.0"
flutter: ">=1.22.0"
flutter: ">=2.0.0"
6 changes: 3 additions & 3 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
version: 1.0.1

environment:
sdk: ">=2.7.0 <3.0.0"
Expand All @@ -27,10 +27,10 @@ dependencies:

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.0
cupertino_icons: ^1.0.3
paymongo_sdk:
path: ../
webview_flutter: ^1.0.7
webview_flutter: ^2.0.9
dev_dependencies:
flutter_test:
sdk: flutter
Expand Down
41 changes: 38 additions & 3 deletions lib/src/sources/payment.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,43 @@
import '../src.dart';

/// Instance of Source to provide a different payment gateway.
/// Options allowed are GCash and GrabPay
/// Link: https://developers.paymongo.com/docs/e-wallets-gcash-grabpay
extension PayMongoSource on PayMongoSDK {
/// A Source resource is used to generate GCash/GrabPay checkout URL to authorize
/// a certain amount to be deducted from your customer's GCash account
/// and send it to your PayMongo account. After completing the authorization,
/// your integration uses the chargeable
/// source to make a create payment request and receive the payment.
///
/// https://developers.paymongo.com/docs/accepting-gcash-payments#1-create-a-source
///
/// Example:
/// ```dart
/// final sdk = PayMongoSDK(payMongoKey);
/// final url = 'your-url-callback';
/// final _source = Source(
/// type: "gcash",
/// amount: _amount.toDouble(),
/// currency: 'PHP',
/// redirect: Redirect(
/// success: "https://$url/success",
/// failed: "https://$url/failed",
/// ),
/// billing: PayMongoBilling(
/// address: PayMongoAddress(
/// city: "Cotabato City",
/// country: "PH",
/// state: "Mindanao",
/// line1: "Secret Address",
/// ),
/// name: "Anonymous",
/// email: "[email protected]",
/// phone: "09123456002",
/// ),
/// );
/// final result = await sdk.createSource(_source);
/// ```
Future<SourceResult> createSource(Source source) async {
final options = PayMongoOptions(
path: '/sources',
Expand All @@ -13,10 +50,8 @@ extension PayMongoSource on PayMongoSDK {
return SourceResult.fromMap(response);
}

/// Retrieves the payment
Future<SourceResult> retreiveSource(int id) async {
if (id.runtimeType != int) {
throw ArgumentError("ID is required");
}
if (id <= 0) {
throw ArgumentError("ID must be greater than 0");
}
Expand Down
34 changes: 25 additions & 9 deletions lib/src/utils/http.dart
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
import 'dart:convert';

import 'package:http/http.dart' as http;
import 'package:http/http.dart' as _http;

import '../models/utils/options.dart';

/// {@template paymonggosdk}
///
/// Initialize PayMongo SDK.
/// {@endtemplate}
class PayMongoSDK {
/// {@macro paymonggosdk}
PayMongoSDK(this.secret, {this.http, String apiUrl = 'api.paymongo.com'})
: _apiUrl = apiUrl;

/// key generated from paymongo dashboard
/// you can use `--dart-define` command to store your private key.
final String secret;
final String _apiUrl;
PayMongoSDK(this.secret, [this._apiUrl = 'api.paymongo.com']);

T _request<T>(http.Response response, String path) {
/// custom http. be sure you include your api key to have basic base64
/// authorization headers.
final _http.BaseClient? http;
T _request<T>(_http.Response response, String path) {
final json = jsonDecode(response.body);
if (response.statusCode != 200) {
throw http.ClientException("${json['errors']}", response.request?.url);
throw _http.ClientException("${json['errors']}", response.request?.url);
}
return json?['data'] as T;
}

/// make POST response.
Future<T> post<T>(PayMongoOptions options) async {
final _http = PayMongoHttp(secret);
final _http = http ?? PayMongoHttp(secret);
final body = jsonEncode({"data": options.data});
final response = await _http.post(
Uri.https(_apiUrl, "v1${options.path}", options.params),
Expand All @@ -32,6 +39,7 @@ class PayMongoSDK {
return _request(response, options.path);
}

/// make GET response
Future<T> get<T>(PayMongoOptions options) async {
final _http = PayMongoHttp(secret);
final uri = Uri.https(_apiUrl, "v1${options.path}", options.params);
Expand All @@ -41,12 +49,20 @@ class PayMongoSDK {
}
}

class PayMongoHttp extends http.BaseClient {
/// {@template paymongohttp}
/// Alternative HTTP client for processing. can be extensible for custom http
/// client
/// {@endtemplate}
///
class PayMongoHttp extends _http.BaseClient {
/// {@macro paymongohttp}
PayMongoHttp(this.apiKey);

/// api key can be used private or public
final String apiKey;
final _client = http.Client();
@override
Future<http.StreamedResponse> send(http.BaseRequest request) {
Future<_http.StreamedResponse> send(_http.BaseRequest request) {
final _client = _http.Client();
final bytes = utf8.encode(apiKey);
final base64Str = base64.encode(bytes);
final headers = {
Expand Down
10 changes: 5 additions & 5 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ packages:
name: equatable
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
version: "2.0.3"
file:
dependency: transitive
description:
Expand Down Expand Up @@ -294,21 +294,21 @@ packages:
name: test
url: "https://pub.dartlang.org"
source: hosted
version: "1.17.3"
version: "1.17.9"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.0"
version: "0.4.1"
test_core:
dependency: transitive
description:
name: test_core
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.23"
version: "0.3.29"
typed_data:
dependency: transitive
description:
Expand All @@ -322,7 +322,7 @@ packages:
name: very_good_analysis
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.3"
version: "2.1.2"
vm_service:
dependency: transitive
description:
Expand Down
8 changes: 4 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
name: paymongo_sdk
description: Unofficial PayMongo SDK written in Dart for flutter
version: 1.0.0
version: 1.0.1
author: Vince Ramces Vicente OLiveros

environment:
sdk: ">=2.12.0 <3.0.0"

dependencies:
http: ^0.13.3
equatable: ^2.0.0
equatable: ^2.0.3

dev_dependencies:
test: ^1.17.3
very_good_analysis: ^2.0.3
test: ^1.17.9
very_good_analysis: ^2.1.2
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
Expand Down

0 comments on commit b914165

Please sign in to comment.