Skip to content

Commit e026387

Browse files
authoredFeb 18, 2022
Merge pull request pikaju#103 from nabinadhikari/master
Custom PayPalPaymentIntent and PayPalPaymentUserAction
2 parents e5f5acf + a653966 commit e026387

File tree

5 files changed

+89
-3
lines changed

5 files changed

+89
-3
lines changed
 

‎android/src/main/java/com/example/flutter_braintree/FlutterBraintreeCustom.java

+16-2
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,31 @@ protected void tokenizeCreditCard() {
5252
.cardNumber(intent.getStringExtra("cardNumber"))
5353
.expirationMonth(intent.getStringExtra("expirationMonth"))
5454
.expirationYear(intent.getStringExtra("expirationYear"))
55-
.cvv(intent.getStringExtra("cvv"));
55+
.cvv(intent.getStringExtra("cvv"))
56+
.validate(false)
57+
.cardholderName(intent.getStringExtra("cardholderName"));
5658
Card.tokenize(braintreeFragment, builder);
5759
}
5860

5961
protected void requestPaypalNonce() {
6062
Intent intent = getIntent();
63+
String paypalIntent;
64+
switch (intent.getStringExtra("payPalPaymentIntent")){
65+
case PayPalRequest.INTENT_ORDER: paypalIntent = PayPalRequest.INTENT_ORDER; break;
66+
case PayPalRequest.INTENT_SALE: paypalIntent = PayPalRequest.INTENT_SALE; break;
67+
default: paypalIntent = PayPalRequest.INTENT_AUTHORIZE; break;
68+
}
69+
String payPalPaymentUserAction = PayPalRequest.USER_ACTION_DEFAULT;
70+
if (PayPalRequest.USER_ACTION_COMMIT.equals(intent.getStringExtra("payPalPaymentUserAction"))) {
71+
payPalPaymentUserAction = PayPalRequest.USER_ACTION_COMMIT;
72+
}
6173
PayPalRequest request = new PayPalRequest(intent.getStringExtra("amount"))
6274
.currencyCode(intent.getStringExtra("currencyCode"))
6375
.displayName(intent.getStringExtra("displayName"))
6476
.billingAgreementDescription(intent.getStringExtra("billingAgreementDescription"))
65-
.intent(PayPalRequest.INTENT_AUTHORIZE);
77+
.intent(paypalIntent)
78+
.userAction(payPalPaymentUserAction);
79+
6680

6781
if (intent.getStringExtra("amount") == null) {
6882
// Vault flow

‎android/src/main/java/com/example/flutter_braintree/FlutterBraintreePlugin.java

+3
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public void onMethodCall(MethodCall call, Result result) {
9898
intent.putExtra("expirationMonth", (String) request.get("expirationMonth"));
9999
intent.putExtra("expirationYear", (String) request.get("expirationYear"));
100100
intent.putExtra("cvv", (String) request.get("cvv"));
101+
intent.putExtra("cardholderName", (String) request.get("cardholderName"));
101102
activity.startActivityForResult(intent, CUSTOM_ACTIVITY_REQUEST_CODE);
102103
} else if (call.method.equals("requestPaypalNonce")) {
103104
String authorization = call.argument("authorization");
@@ -109,6 +110,8 @@ public void onMethodCall(MethodCall call, Result result) {
109110
intent.putExtra("amount", (String) request.get("amount"));
110111
intent.putExtra("currencyCode", (String) request.get("currencyCode"));
111112
intent.putExtra("displayName", (String) request.get("displayName"));
113+
intent.putExtra("payPalPaymentIntent", (String) request.get("payPalPaymentIntent"));
114+
intent.putExtra("payPalPaymentUserAction", (String) request.get("payPalPaymentUserAction"));
112115
intent.putExtra("billingAgreementDescription", (String) request.get("billingAgreementDescription"));
113116
activity.startActivityForResult(intent, CUSTOM_ACTIVITY_REQUEST_CODE);
114117
} else {

‎ios/Classes/BaseFlutterBraintreePlugin.swift

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ open class BaseFlutterBraintreePlugin: NSObject {
3232
dict["isDefault"] = nonce?.isDefault
3333
if let paypalNonce = nonce as? BTPayPalAccountNonce {
3434
dict["paypalPayerId"] = paypalNonce.payerID
35+
dict["description"] = paypalNonce.email
3536
}
3637
return dict
3738
}

‎ios/Classes/FlutterBraintreeCustomPlugin.swift

+19-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,24 @@ public class FlutterBraintreeCustomPlugin: BaseFlutterBraintreePlugin, FlutterPl
4040
paypalRequest.currencyCode = requestInfo["currencyCode"] as? String
4141
paypalRequest.displayName = requestInfo["displayName"] as? String
4242
paypalRequest.billingAgreementDescription = requestInfo["billingAgreementDescription"] as? String
43-
43+
if let intent = requestInfo["payPalPaymentIntent"] as? String {
44+
switch intent {
45+
case "order":
46+
paypalRequest.intent = BTPayPalRequestIntent.order
47+
case "sale":
48+
paypalRequest.intent = BTPayPalRequestIntent.sale
49+
default:
50+
paypalRequest.intent = BTPayPalRequestIntent.authorize
51+
}
52+
}
53+
if let userAction = requestInfo["payPalPaymentUserAction"] as? String {
54+
switch userAction {
55+
case "commit":
56+
paypalRequest.userAction = BTPayPalRequestUserAction.commit
57+
default:
58+
paypalRequest.userAction = BTPayPalRequestUserAction.default
59+
}
60+
}
4461
driver.tokenizePayPalAccount(with: paypalRequest) { (nonce, error) in
4562
self.handleResult(nonce: nonce, error: error, flutterResult: result)
4663
self.isHandlingResult = false
@@ -66,6 +83,7 @@ public class FlutterBraintreeCustomPlugin: BaseFlutterBraintreePlugin, FlutterPl
6683
card.expirationMonth = cardRequestInfo["expirationMonth"] as? String
6784
card.expirationYear = cardRequestInfo["expirationYear"] as? String
6885
card.cvv = cardRequestInfo["cvv"] as? String
86+
card.cardholderName = cardRequestInfo["cardholderName"] as? String
6987

7088
cardClient.tokenizeCard(card) { (nonce, error) in
7189
self.handleResult(nonce: nonce, error: error, flutterResult: result)

‎lib/src/request.dart

+50
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class BraintreeCreditCardRequest {
9090
required this.expirationMonth,
9191
required this.expirationYear,
9292
required this.cvv,
93+
this.cardholderName,
9394
});
9495

9596
/// Number shown on the credit card.
@@ -104,11 +105,15 @@ class BraintreeCreditCardRequest {
104105
/// A 3 or 4 digit card verification value assigned to credit cards.
105106
String cvv;
106107

108+
/// Cardholder name
109+
String? cardholderName;
110+
107111
Map<String, dynamic> toJson() => {
108112
'cardNumber': cardNumber,
109113
'expirationMonth': expirationMonth,
110114
'expirationYear': expirationYear,
111115
'cvv': cvv,
116+
'cardholderName': cardholderName
112117
};
113118
}
114119

@@ -147,6 +152,8 @@ class BraintreePayPalRequest {
147152
this.currencyCode,
148153
this.displayName,
149154
this.billingAgreementDescription,
155+
this.payPalPaymentIntent,
156+
this.payPalPaymentUserAction,
150157
});
151158

152159
/// Amount of the transaction. If [amount] is `null`, PayPal will use the billing agreement (Vault) flow.
@@ -162,16 +169,59 @@ class BraintreePayPalRequest {
162169
/// Description for the billing agreement for the Vault flow.
163170
String? billingAgreementDescription;
164171

172+
/// PayPalPaymentIntent. Options are INTENT_AUTHORIZE,INTENT_SALE,INTENT_ORDER
173+
PayPalPaymentIntent? payPalPaymentIntent;
174+
175+
///PayPalPaymentUserAction. Options are USER_ACTION_DEFAULT, USER_ACTION_COMMIT
176+
PayPalPaymentUserAction? payPalPaymentUserAction;
177+
165178
/// Converts this request object into a JSON-encodable format.
166179
Map<String, dynamic> toJson() => {
167180
if (amount != null) 'amount': amount,
168181
if (currencyCode != null) 'currencyCode': currencyCode,
169182
if (displayName != null) 'displayName': displayName,
170183
if (billingAgreementDescription != null)
171184
'billingAgreementDescription': billingAgreementDescription,
185+
'payPalPaymentIntent': payPalPaymentIntent == null
186+
? PayPalPaymentIntent.INTENT_AUTHORIZE.rawValue
187+
: payPalPaymentIntent?.rawValue,
188+
if (payPalPaymentUserAction != null)
189+
'payPalPaymentUserAction': payPalPaymentUserAction?.rawValue,
172190
};
173191
}
174192

193+
enum PayPalPaymentUserAction { USER_ACTION_DEFAULT, USER_ACTION_COMMIT }
194+
195+
extension PayPalPaymentUserActionExtension on PayPalPaymentUserAction {
196+
String? get rawValue {
197+
switch (this) {
198+
case PayPalPaymentUserAction.USER_ACTION_DEFAULT:
199+
return '';
200+
case PayPalPaymentUserAction.USER_ACTION_COMMIT:
201+
return 'commit';
202+
default:
203+
return null;
204+
}
205+
}
206+
}
207+
208+
enum PayPalPaymentIntent { INTENT_ORDER, INTENT_SALE, INTENT_AUTHORIZE }
209+
210+
extension PayPalPaymentIntentExtension on PayPalPaymentIntent {
211+
String? get rawValue {
212+
switch (this) {
213+
case PayPalPaymentIntent.INTENT_AUTHORIZE:
214+
return 'authorize';
215+
case PayPalPaymentIntent.INTENT_SALE:
216+
return 'sale';
217+
case PayPalPaymentIntent.INTENT_ORDER:
218+
return 'order';
219+
default:
220+
return null;
221+
}
222+
}
223+
}
224+
175225
enum ApplePaySummaryItemType {
176226
Final,
177227
Pending,

0 commit comments

Comments
 (0)