在PaymentRails Firebase中验证PayPal电子邮件地址

时间:2020-08-11 15:14:33

标签: node.js firebase flutter paypal paypal-rest-sdk

我已将PaymentRails集成到我的Firebase项目中以进行支付。这将启用使用PayPal的付款。我使用以下代码创建了一个“ PaymentrailsPayoutMethodModel”类:

class PaymentrailsPayoutMethodModel {
  String id;
  bool primary;
  String currency;
  String status;
  String type;
  String recipientId;
  String recipientReferenceId;
  String recipientAccountId;
  Null disabledAt;
  String country;
  String iban;
  String accountNum;
  String accountHolderName;
  String swiftBic;
  String branchId;
  String bankId;
  String bankName;
  String bankAddress;
  String bankCity;
  String bankRegionCode;
  String bankPostalCode;
  String routeType;
  String recipientFees;
  String emailAddress;

  PaymentrailsPayoutMethodModel(
      {this.id,
      this.primary,
      this.currency,
      this.status,
      this.type,
      this.recipientId,
      this.recipientReferenceId,
      this.recipientAccountId,
      this.disabledAt,
      this.country,
      this.iban,
      this.accountNum,
      this.accountHolderName,
      this.swiftBic,
      this.branchId,
      this.bankId,
      this.bankName,
      this.bankAddress,
      this.bankCity,
      this.bankRegionCode,
      this.bankPostalCode,
      this.routeType,
      this.recipientFees,
      this.emailAddress});

  PaymentrailsPayoutMethodModel.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    primary = json['primary'];
    currency = json['currency'];
    status = json['status'];
    type = json['type'];
    recipientId = json['recipientId'];
    recipientReferenceId = json['recipientReferenceId'];
    recipientAccountId = json['recipientAccountId'];
    disabledAt = json['disabledAt'];
    country = json['country'];
    iban = json['iban'];
    accountNum = json['accountNum'];
    accountHolderName = json['accountHolderName'];
    swiftBic = json['swiftBic'];
    branchId = json['branchId'];
    bankId = json['bankId'];
    bankName = json['bankName'];
    bankAddress = json['bankAddress'];
    bankCity = json['bankCity'];
    bankRegionCode = json['bankRegionCode'];
    bankPostalCode = json['bankPostalCode'];
    routeType = json['routeType'];
    recipientFees = json['recipientFees'];
    emailAddress = json['emailAddress'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['primary'] = this.primary;
    data['currency'] = this.currency;
    data['status'] = this.status;
    data['type'] = this.type;
    data['recipientId'] = this.recipientId;
    data['recipientReferenceId'] = this.recipientReferenceId;
    data['recipientAccountId'] = this.recipientAccountId;
    data['disabledAt'] = this.disabledAt;
    data['country'] = this.country;
    data['iban'] = this.iban;
    data['accountNum'] = this.accountNum;
    data['accountHolderName'] = this.accountHolderName;
    data['swiftBic'] = this.swiftBic;
    data['branchId'] = this.branchId;
    data['bankId'] = this.bankId;
    data['bankName'] = this.bankName;
    data['bankAddress'] = this.bankAddress;
    data['bankCity'] = this.bankCity;
    data['bankRegionCode'] = this.bankRegionCode;
    data['bankPostalCode'] = this.bankPostalCode;
    data['routeType'] = this.routeType;
    data['recipientFees'] = this.recipientFees;
    data['emailAddress'] = this.emailAddress;
    return data;
  }
}

此类将接受所有必需的信息,并将其转换为json,以将其存储到firebase中。 这是我用来让用户添加其Paypal帐户的云功能。

export const activePaymentrailsPayoutMethod = async(data:any,context:functions.https.CallableContext,database:admin.database.Database)=>{
    console.log('activePaymentrailsPayoutMethod Entry2');
    if(!context.auth || !data.PayoutMethodId){
        return false;
    }
    return new Promise((resolve,reject)=>{
        database.app.firestore().collection("Users").where("databaseID", "==", context.auth?.uid).get()
        .then(querySnapshot => {
            querySnapshot.forEach(async user => {
                if(user.data().pRailsPayoutID==="" || user.data().pRailsPayoutID===null)
                {
                    resolve(false);
                }
                else
                {
                      var body = { primary: true };
                      await client.recipientAccount.update(
                        user.data().pRailsPayoutID,
                        data.PayoutMethodId,
                        body
                      );
                    resolve(true);
                }
         });
      }).catch(err=>{
            console.error(err);
            reject(err);
        });
    });
}

例如,问题出在我输入与任何PayPal帐户无关的电子邮件ID时,它仍然接受该电子邮件ID并添加Paypal帐户。有什么方法可以首先验证电子邮件是否有效,然后让用户添加帐户?我可以编写的任何可以首先验证电子邮件地址的功能吗?

0 个答案:

没有答案