Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --cc appserver/export/UPM.pm
- index 6d25185,16b603f..0000000
- --- a/appserver/export/UPM.pm
- diff --cc appserver/export/UPM.pm
- index 6d25185,16b603f..0000000
- --- a/appserver/export/UPM.pm
- +++ b/appserver/export/UPM.pm
- @@@ -7379,162 -7214,65 +7392,224 @@@ sub SetNameReviewStatus
- return rpc('QB::UpdateUserPaymentMethod', $upm_recno, {'Name Review Status' => $status});
- }
- ++<<<<<<< HEAD
- +=item BillingAgreementCanceled($upm_recno)
- +
- +Clone specified UPM (reset Billing Agreement, Verification Completed date columns).
- +Keep cloned UPM primary/backup if it was such. If specified UPM is primary and
- +backup UPM is ACTIVE then set it as new primary UPM.
- +
- +If cloned UPM becomes primary then queue OQS job to suspend user in 24 hours
- +if required (See B<SuspendCompaniesIfNonBillablePrimaryUPM>). Send email
- +notification about possible suspension.
- +
- +B<Parameters>
- +
- +$upm_recno
- +
- + UPM recno.
- +
- +B<Return value>
- +
- + None. Exception is thrown on error.
- +
- +=cut
- +
- +sub BillingAgreementCanceled {
- + my ($upm_recno) = @_;
- +
- + my $t_begin = Time::HiRes::time;
- +
- + # to keep BPA history
- + my ($ace_recno, $history_comment, $metadata);
- +
- + try {
- +
- + # get all non system UPM fields of type 'value'
- + my @fields = map { $_->{'Name'} } grep (
- + $_->{'Class'} eq 'value' && !$_->{'IsSystem'},
- + @{rpc('QB::GetFieldProperties', 'UserPaymentMethods')}
- + );
- + my $upm = rpc('QB::GetUserPaymentMethod', $upm_recno, \@fields);
- + $ace_recno = $upm->{'Related AccountingEntity'};
- +
- + _error("UPM $upm_recno is deleted") if $upm->{'ValidUntil'};
- + _error("UPM $upm_recno is of unexpected type $upm->{'Related PaymentMethod'}")
- + unless $upm->{'Related PaymentMethod'} eq 'PAYPAL_DEPOSIT';
- + _error("Billing agreement is not set for UPM $upm_recno")
- + unless $upm->{'Billing Agreement ID'};
- +
- + my $ba = rpc('BillingAgreement::Get', $upm->{'Billing Agreement ID'});
- + _error("Billing agreement $ba->{rec_id} is not canceled ($ba->{status})")
- + unless $ba->{status} eq 'CANCELED';
- +
- + # prevent some concurrent actions on the same ACE
- + write_log("set lock lock_ace_$ace_recno");
- + execute_critical_section {
- + my $upms = GetUPMsByAccountingEntity($ace_recno);
- + $metadata = {primary_upm => $upms->{primary}, backup_upm => $upms->{backup}};
- +
- + execute_transactional {
- + # Clone UPM, set Date Entered to now.
- + # Don't clone billing agreement column.
- + delete $upm->{'Billing Agreement ID'};
- + $upm->{'Date Entered'} = any_to_msec(my_time());
- + my $new_recno = rpc('QB::AddUserPaymentMethod', $upm);
- + $metadata->{cloned_upm} = $new_recno;
- + $history_comment = "Clone of UPM #$upm_recno is #$new_recno";
- + write_log($history_comment);
- +
- + if (defined $upms->{primary} && $upms->{primary} == $upm_recno) {
- + # BillingAgreement is canceled on PrimaryUPM
- + if ($upms->{backup} && $upms->{backup_rec}{upm_status} eq 'ACTIVE') {
- + $history_comment = "Set BackupUPM $upms->{backup} as new PrimaryUPM";
- + try {
- + SetPrimary($upms->{backup});
- + $metadata->{new_primary_upm} = $upms->{backup};
- + # notify user that primary UPM has been changed due to BA cancellation
- + qrpc('orpc-notifications-queue',
- + 'NotifyUser::BillingAgreementCanceled',
- + [$upm_recno, $upms->{backup}]
- + );
- + } catch Error with {
- + my $err = shift;
- + $history_comment .= ": $err->{-text}";
- + $metadata->{set_backup_as_primary_err} = $history_comment;
- + };
- + write_log($history_comment);
- + }
- +
- + # check if backup UPM has been set as primary
- + if (!$metadata->{new_primary_upm}) {
- + $history_comment = "Set cloned UPM $new_recno as new PrimaryUPM";
- + try {
- + SetPrimary($new_recno, 1); # '1' means to allow primary UPM without BA
- + $metadata->{new_primary_upm} = $new_recno;
- + } catch Error with {
- + my $err = shift;
- + $history_comment .= ": $err->{-text}";
- + };
- + write_log($history_comment);
- +
- + # notify user about upcoming suspension due to BA cancellation
- + qrpc('orpc-notifications-queue', 'NotifyUser::BillingAgreementCanceled', [$upm_recno]);
- + }
- +
- + # schedule job to suspend AE if primary UPM will stay unbillable,
- + # note that we schedule this job even if backup UPM became primary
- + $metadata->{job_to_suspend} = qrpc(
- + 'orpc-bpa-emails-misc-queue',
- + 'UPM::SuspendCompaniesIfNonBillablePrimaryUPM',
- + [$ace_recno, 'no'],
- + 'Billing Agreement canceled',
- + $ace_recno, # unique key
- + 5, # priority
- + time + 86400, # visible in 24h,
- + undef, undef, # out_of_transaction, batch
- + 'yes', # do not raise error if same AE job is already in the queue
- + );
- + write_log("Suspend OQS job created $metadata->{job_to_suspend}");
- +
- + } elsif (defined $upms->{backup} && $upms->{backup} == $upm_recno) {
- + # BillingAgreement is canceled on BackupUPM (should)
- + $history_comment = "Set cloned UPM $new_recno as new BackupUPM";
- + try {
- + SetBackup($new_recno);
- + $metadata->{new_backup_upm} = $new_recno;
- + } catch Error with {
- + my $err = shift;
- + $history_comment .= ": $err->{-text}";
- + };
- + write_log($history_comment);
- +
- + } else {
- + $history_comment = "Billing agreement is canceled on non-primary UPM $upm_recno, ace=$ace_recno, cloned_upm=$new_recno";
- + write_log($history_comment);
- + }
- +
- + # mark original UPM as deleted
- + rpc('QB::UpdateUserPaymentMethod', $upm_recno, {'ValidUntil' => any_to_msec(my_time())});
- + };
- + } "lock_ace_$ace_recno"; # execute_critical_section
- + write_log("released lock lock_ace_$ace_recno");
- +
- + } catch Error with {
- + my $e = shift;
- + $history_comment = bpa_history_error_comment($e);
- + $e->throw();
- +
- + } finally {
- + insert_to_bpa_history({
- + 'Start Time' => $t_begin,
- + 'Related AccountingEntity' => $ace_recno,
- + 'Related UserPaymentMethod' => $upm_recno,
- + 'Comment' => $history_comment,
- + 'Metadata' => $metadata,
- + });
- + };
- +
- + return undef;
- ++=======
- + =item TmpB39561FindInvalidCcUpms()
- +
- + Find non-deleted CC UPMs that cannot pass current
- + validation rules.
- +
- + B<Parameters>
- +
- + None.
- +
- + B<Return value>
- +
- + CSV:
- +
- + "upm", "field", "value", "error"
- + ...
- +
- + =cut
- +
- + sub TmpB39561FindInvalidCcUpms {
- + my ($csv, $cnt);
- +
- + # use slave
- + local $CTX{RPC_ODB_SLAVE} = 1;
- +
- + # fetch non-deleted CC UPMs
- + my @upms = osql_select(q|
- + SELECT "Record ID#", "CC First Name", "CC Last Name", "CC Address 1",
- + "CC Address 2", "CC City", "CC Country", "CC State", "CC Postal Code",
- + "CC Phone", "CC Email", "CC FirstSixDigits", "CC LastFourDigits",
- + "CC Expiration Date"
- + FROM "UserPaymentMethods"
- + WHERE "ValidUntil" IS NULL
- + AND "Related PaymentMethod" = 'CC'
- + ORDER BY "Record ID#"
- + |);
- +
- + write_log(scalar(@upms).' to go');
- +
- + # header
- + $csv = qq|"upm","field","value","error"\n|;
- +
- + # check all UPMS
- + foreach my $upm (@upms) {
- +
- + # timestamp to MDY
- + $upm->{'CC Expiration Date'} = any_to_mdy($upm->{'CC Expiration Date'});
- +
- + # check fields
- + my $err = _check_cc_fields($upm, 0);
- +
- + # add errors to output
- + foreach my $fld (keys %$err) {
- + $csv .= join(',', map {qq|"$_"|} ($upm->{'Record ID#'}, $fld, $upm->{$fld}, $err->{$fld}))."\n";
- + }
- +
- + write_log("$cnt UPMs have been processed") unless ++$cnt % 1000;
- + }
- +
- + return $csv;
- ++>>>>>>> origin/master
- }
- sub _name_breakdown {
Add Comment
Please, Sign In to add comment