Skip to content

Commit

Permalink
Merge pull request #26 from pokepay/feature/credit-card-api
Browse files Browse the repository at this point in the history
Credit Card Endpoints
  • Loading branch information
DanRidh authored Aug 7, 2024
2 parents 7381086 + fa1b48e commit 56505c5
Show file tree
Hide file tree
Showing 15 changed files with 428 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.16
* Added `GetVeritransToken` endpoint
* Added CreditCard endpoints (create, get, delete, topup)

## 2.0.14
* Fix `createAccountCPMToken` API to handle multiple key values in metadata

Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ dependencies {
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.11.1'
implementation 'com.fasterxml.jackson.core:jackson-core:2.11.1'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.11.1'
implementation 'jp.pocket-change.pokepay.android-sdk:pokepaylib:2.0.14'
implementation 'jp.pocket-change.pokepay.android-sdk:pokepaylib:2.0.16'
}
95 changes: 93 additions & 2 deletions android/src/main/java/jp/pokepay/pokepay_sdk/PokepaySdkPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@
import jp.pokepay.pokepaylib.BankAPI.User.GetBankPay;
import jp.pokepay.pokepaylib.BankAPI.User.DeleteBankPay;
import jp.pokepay.pokepaylib.BankAPI.User.BankPayTopUp;
import jp.pokepay.pokepaylib.BankAPI.autogen.requests.CreateCreditCard;
import jp.pokepay.pokepaylib.BankAPI.autogen.requests.DeleteCreditCard;
import jp.pokepay.pokepaylib.BankAPI.autogen.requests.GetCreditCards;
import jp.pokepay.pokepaylib.BankAPI.autogen.requests.TopupWithCreditCardMdkToken;
import jp.pokepay.pokepaylib.BankAPI.autogen.requests.TopupWithCreditCardMembership;
import jp.pokepay.pokepaylib.Env;
import jp.pokepay.pokepaylib.JsonConverter;
import jp.pokepay.pokepaylib.MessagingAPI.GetMessage;
Expand All @@ -87,6 +92,7 @@
import jp.pokepay.pokepaylib.OAuthAPI.OAuthRequestError;
import jp.pokepay.pokepaylib.OAuthAPI.Token.ExchangeAuthCode;
import jp.pokepay.pokepaylib.OAuthAPI.Token.RefreshAccessToken;
import jp.pokepay.pokepaylib.ExternalServiceAPI.Veritrans.GetVeritransToken;
import jp.pokepay.pokepaylib.Parameters.TransactionStrategy;
import jp.pokepay.pokepaylib.Parameters.Gender;
import jp.pokepay.pokepaylib.Parameters.Product;
Expand Down Expand Up @@ -122,6 +128,9 @@
import jp.pokepay.pokepaylib.Responses.BankPayRedirectUrl;
import jp.pokepay.pokepaylib.Responses.IdentificationResult;
import jp.pokepay.pokepaylib.Responses.AccountCampaignPointAmounts;
import jp.pokepay.pokepaylib.Responses.VeritransToken;
import jp.pokepay.pokepaylib.BankAPI.autogen.responses.CreditCard;
import jp.pokepay.pokepaylib.BankAPI.autogen.responses.PaginatedCreditCards;;
import jp.pokepay.pokepaylib.TokenInfo;

/** PokepaySdkPlugin */
Expand Down Expand Up @@ -948,7 +957,7 @@ private TaskResult invokeMethod() {
BankPayTopUp req = new BankPayTopUp(id, accountId, bankId, amount, requestId);
Pokepay.setEnv(env);
UserTransaction res = req.send(accessToken);
return new TaskResult(null, res.toString());
return new TaskResult(null, res.toString());
}
case "deleteBankPay": {
Env env = flutterEnvToSDKEnv((int)call.argument("env"));
Expand Down Expand Up @@ -986,7 +995,89 @@ private TaskResult invokeMethod() {
GetAccountCampaignPointAmounts req = new GetAccountCampaignPointAmounts(accountId, campaignId);
Pokepay.setEnv(env);
AccountCampaignPointAmounts res = req.send(accessToken);
return new TaskResult(null, res.toString());
return new TaskResult(null, res.toString());
}
case "createCreditCard": {
Env env = flutterEnvToSDKEnv((int)call.argument("env"));
String accessToken = call.argument("accessToken");
String token = call.argument("token");
Boolean isCardholderNameSpecified = call.argument("isCardholderNameSpecified");
String organizationCode = call.argument("organizationCode");
String userId = call.argument("userId");

CreateCreditCard req = new CreateCreditCard(userId, token, organizationCode).isCardholderNameSpecified(isCardholderNameSpecified);

Pokepay.setEnv(env);
CreditCard res = req.send(accessToken);
return new TaskResult(null, res.toString());
}
case "deleteCreditCard": {
Env env = flutterEnvToSDKEnv((int)call.argument("env"));
String accessToken = call.argument("accessToken");
String cardRegisteredAt = call.argument("cardRegisteredAt");
String organizationCode = call.argument("organizationCode");
String userId = call.argument("userId");

DeleteCreditCard req = new DeleteCreditCard(userId, cardRegisteredAt, organizationCode);
Pokepay.setEnv(env);
NoContent res = req.send(accessToken);
return new TaskResult(null, res.toString());
}
case "getCreditCards": {
Env env = flutterEnvToSDKEnv((int)call.argument("env"));
String accessToken = call.argument("accessToken");
String userId = call.argument("userId");
String before = call.argument("before");
String after = call.argument("after");
Integer perPage = call.argument("perPage");
String organizationCode = call.argument("organizationCode");

GetCreditCards req = new GetCreditCards(userId, organizationCode).before(before).after(after).perPage(perPage);

Pokepay.setEnv(env);
PaginatedCreditCards res = req.send(accessToken);
return new TaskResult(null, res.toString());
}
case "topupWithCreditCardMdkToken": {
Env env = flutterEnvToSDKEnv((int)call.argument("env"));
String accessToken = call.argument("accessToken");
String userId = call.argument("userId");
String token = call.argument("token");
String accountId = call.argument("accountId");
Integer amount = call.argument("amount");
String organizationCode = call.argument("organizationCode");
Boolean isCardholderNameSpecified = call.argument("isCardholderNameSpecified");

TopupWithCreditCardMdkToken req = new TopupWithCreditCardMdkToken(userId, token, accountId, amount, organizationCode).isCardholderNameSpecified(isCardholderNameSpecified);
Pokepay.setEnv(env);
String res = req.send(accessToken);
return new TaskResult(null, res);
}
case "topupWithCreditCardMembership": {
Env env = flutterEnvToSDKEnv((int)call.argument("env"));
String accessToken = call.argument("accessToken");
String userId = call.argument("userId");
String cardRegisteredAt = call.argument("cardRegisteredAt");
String accountId = call.argument("accountId");
Integer amount = call.argument("amount");
Boolean deleteCardIfAuthFail = call.argument("deleteCardIfAuthFail");
String organizationCode = call.argument("organizationCode");

TopupWithCreditCardMembership req = new TopupWithCreditCardMembership(userId, cardRegisteredAt, accountId, amount, organizationCode).deleteCardIfAuthFail(deleteCardIfAuthFail);
Pokepay.setEnv(env);
String res = req.send(accessToken);
return new TaskResult(null, res);
}
case "getVeritransToken": {
String cardNumber = call.argument("cardNumber");
String cardExpiryDate = call.argument("cardExpiryDate");
String securityCode = call.argument("securityCode");
String tokenApiKey = call.argument("tokenApiKey");
String cardholderName = call.argument("cardholderName");

GetVeritransToken req = new GetVeritransToken(cardNumber, cardExpiryDate, securityCode, tokenApiKey, cardholderName);
VeritransToken res = req.send();
return new TaskResult(null, res.toString());
}
default:
throw new java.lang.UnsupportedOperationException();
Expand Down
57 changes: 57 additions & 0 deletions ios/Classes/SwiftPokepaySdkPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,63 @@ private class MethodCallTask {
let accountId = args["accountId"] as! String
let campaignId = args["campaignId"] as! String
client.send(BankAPI.Account.GetAccountCampaignPointAmounts(accountId: accountId, campaignId: campaignId), handler: self.after)
case "createCreditCard":
let env = flutterEnvToSDKEnv(ienv: args["env"] as! Int32)
let accessToken = args["accessToken"] as! String
let client = Pokepay.Client(accessToken:accessToken, env: env)
let token = args["token"] as! String
let isCardholderNameSpecified = args["isCardholderNameSpecified"] as? Bool
let organizationCode = args["organizationCode"] as? String
let userId = args["userId"] as! String
client.send(BankAPI.CreditCard.CreateCreditCard(token: token, isCardholderNameSpecified: isCardholderNameSpecified, organizationCode: organizationCode, userId: userId), handler: self.after)
case "deleteCreditCard":
let env = flutterEnvToSDKEnv(ienv: args["env"] as! Int32)
let accessToken = args["accessToken"] as! String
let client = Pokepay.Client(accessToken:accessToken, env: env)
let cardRegisteredAt = args["cardRegisteredAt"] as! String
let organizationCode = args["organizationCode"] as? String
let userId = args["userId"] as! String
client.send(BankAPI.CreditCard.DeleteCreditCard(cardRegisteredAt: cardRegisteredAt, organizationCode: organizationCode, userId: userId), handler: self.after)
case "getCreditCards":
let env = flutterEnvToSDKEnv(ienv: args["env"] as! Int32)
let accessToken = args["accessToken"] as! String
let client = Pokepay.Client(accessToken:accessToken, env: env)
let userId = args["userId"] as! String
let before = args["before"] as? String
let after = args["after"] as? String
let perPage = args["perPage"] as? Int
let organizationCode = args["organizationCode"] as? String
client.send(BankAPI.CreditCard.GetCreditCards(userId: userId, before: before, after: after, perPage: perPage, organizationCode: organizationCode), handler: self.after)
case "topupWithCreditCardMdkToken":
let env = flutterEnvToSDKEnv(ienv: args["env"] as! Int32)
let accessToken = args["accessToken"] as! String
let client = Pokepay.Client(accessToken:accessToken, env: env)
let userId = args["userId"] as! String
let token = args["token"] as! String
let accountId = args["accountId"] as! String
let amount = args["amount"] as! Int
let organizationCode = args["organizationCode"] as? String
let isCardholderNameSpecified = args["isCardholderNameSpecified"] as? Bool
client.send(BankAPI.CreditCard.TopupWithCreditCardMdkToken(userId: userId, token: token, accountId: accountId, amount: amount, organizationCode: organizationCode, isCardholderNameSpecified: isCardholderNameSpecified), handler: self.after)
case "topupWithCreditCardMembership":
let env = flutterEnvToSDKEnv(ienv: args["env"] as! Int32)
let accessToken = args["accessToken"] as! String
let client = Pokepay.Client(accessToken:accessToken, env: env)
let userId = args["userId"] as! String
let cardRegisteredAt = args["cardRegisteredAt"] as! String
let accountId = args["accountId"] as! String
let amount = args["amount"] as! Int
let deleteCardIfAuthFail = args["deleteCardIfAuthFail"] as? Bool
let organizationCode = args["organizationCode"] as? String
client.send(BankAPI.CreditCard.TopupWithCreditCardMembership(userId: userId, cardRegisteredAt: cardRegisteredAt, accountId: accountId, amount: amount, deleteCardIfAuthFail: deleteCardIfAuthFail, organizationCode: organizationCode), handler: self.after)
case "getVeritransToken":
let veritransClient = Pokepay.VeritransClient()
let cardNumber = args["cardNumber"] as! String
let cardExpiryDate = args["cardExpiryDate"] as! String
let securityCode = args["securityCode"] as! String
let tokenApiKey = args["tokenApiKey"] as! String
let cardholderName = args["cardholderName"] as! String
veritransClient.send(VeritransAPI.Token.GetVeritransToken(cardNumber: cardNumber, cardExpiryDate: cardExpiryDate, securityCode: securityCode, tokenApiKey: tokenApiKey, cardholderName: cardholderName), handler: self.after)
default:
self.result(FlutterMethodNotImplemented)
}
Expand Down
4 changes: 2 additions & 2 deletions ios/pokepay_sdk.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
Pod::Spec.new do |s|
s.name = 'pokepay_sdk'
s.version = '2.0.13'
s.version = '2.0.16'
s.summary = 'Pokepay flutter SDK'
s.description = <<-DESC
Pokepay flutter SDK
Expand All @@ -15,7 +15,7 @@ Pokepay flutter SDK
s.source = { :path => '.' }
s.source_files = 'Classes/**/*'
s.dependency 'Flutter'
s.dependency 'Pokepay', '2.0.13'
s.dependency 'Pokepay', '2.0.16'
s.platform = :ios, '12.0'

# Flutter.framework does not contain a i386 slice. Only x86_64 simulators are supported.
Expand Down
116 changes: 116 additions & 0 deletions lib/bank_api/credit_card.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@

import 'package:pokepay_sdk/responses/credit_card.dart';
import 'package:pokepay_sdk/responses/paginated_credit_cards.dart';

import '../pokepay_sdk.dart';
import '../responses.dart';

extension CreditCardAPI on PokepayAPI {
Future<CreditCard> createCreditCard({
required String token,
bool? isCardholderNameSpecified,
String? organizationCode,
required String userId,
}) async {
return await invokeMethod<CreditCard>(
(j) => CreditCard.fromJson(j),
'createCreditCard',
{
'env': this.env.index,
'accessToken': this.accessToken,
'token': token,
'isCardholderNameSpecified': isCardholderNameSpecified,
'organizationCode': organizationCode,
'userId': userId,
},
);
}

Future<NoContent> deleteCreditCard({
required String cardRegisteredAt,
String? organizationCode,
required String userId,
}) async {
return await invokeMethod<NoContent>(
(j) => NoContent.fromJson(j),
'deleteCreditCard',
{
'env': this.env.index,
'accessToken': this.accessToken,
'cardRegisteredAt': cardRegisteredAt,
'organizationCode': organizationCode,
'userId': userId,
},
);
}

Future<PaginatedCreditCards> getCreditCards({
required String userId,
String? before,
String? after,
int? perPage,
String? organizationCode,
}) async {
return await invokeMethod<PaginatedCreditCards>(
(j) => PaginatedCreditCards.fromJson(j),
'getCreditCards',
{
'env': this.env.index,
'accessToken': this.accessToken,
'userId': userId,
'before': before,
'after': after,
'perPage': perPage,
'organizationCode': organizationCode,
},
);
}

Future<String> TopupWithCreditCardMdkToken({
required String userId,
required String token,
required String accountId,
required int amount,
String? organizationCode,
bool? isCardholderNameSpecified,
}) async {
return await invokeMethod<String>(
(j) => j,
'topupWithCreditCardMdkToken',
{
'env': this.env.index,
'accessToken': this.accessToken,
'userId': userId,
'token': token,
'accountId': accountId,
'amount': amount,
'organizationCode': organizationCode,
'isCardholderNameSpecified': isCardholderNameSpecified,
},
);
}

Future<String> TopupWithCreditCardMembership({
required String userId,
required String cardRegisteredAt,
required String accountId,
required int amount,
bool? deleteCardIfAuthFail,
String? organizationCode,
}) async {
return await invokeMethod<String>(
(j) => j,
'topupWithCreditCardMembership',
{
'env': this.env.index,
'accessToken': this.accessToken,
'userId': userId,
'cardRegisteredAt': cardRegisteredAt,
'accountId': accountId,
'amount': amount,
'deleteCardIfAuthFail': deleteCardIfAuthFail,
'organizationCode': organizationCode,
},
);
}
}
1 change: 1 addition & 0 deletions lib/pokepay_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ Future<T> invokeMethod<T>(T factory(dynamic data),
logger.d("methodName: " + methodName + " args: " + args.toString());
final String json = await channel.invokeMethod(methodName, args);
logger.d("json: " + json);
if (T == String) return factory(json);
return factory(jsonDecode(json));
} on PlatformException catch (e) {
final String code = e.code;
Expand Down
21 changes: 21 additions & 0 deletions lib/responses/credit_card.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'package:json_annotation/json_annotation.dart';

part 'credit_card.g.dart';

@JsonSerializable()
class CreditCard {
final String cardNumber;
final String registeredAt;

CreditCard({
required this.cardNumber,
required this.registeredAt,
});

factory CreditCard.fromJson(Map<String, dynamic> json) => _$CreditCardFromJson(json);

Map<String, dynamic> toJson() => _$CreditCardToJson(this);

@override
String toString() => this.toJson().toString();
}
17 changes: 17 additions & 0 deletions lib/responses/credit_card.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 56505c5

Please sign in to comment.