Search in sources :

Example 1 with Payments

use of org.thoughtcrime.securesms.payments.Payments in project Signal-Android by WhisperSystems.

the class PaymentTransactionCheckJob method onRun.

@Override
protected void onRun() throws Exception {
    PaymentDatabase paymentDatabase = SignalDatabase.payments();
    PaymentDatabase.PaymentTransaction payment = paymentDatabase.getPayment(uuid);
    if (payment == null) {
        Log.w(TAG, "No payment found for UUID " + uuid);
        return;
    }
    Payments payments = ApplicationDependencies.getPayments();
    switch(payment.getDirection()) {
        case SENT:
            {
                Log.i(TAG, "Checking sent status of " + uuid);
                PaymentTransactionId paymentTransactionId = new PaymentTransactionId.MobileCoin(Objects.requireNonNull(payment.getTransaction()), Objects.requireNonNull(payment.getReceipt()), payment.getFee().requireMobileCoin());
                Wallet.TransactionStatusResult status = payments.getWallet().getSentTransactionStatus(paymentTransactionId);
                switch(status.getTransactionStatus()) {
                    case COMPLETE:
                        paymentDatabase.markPaymentSuccessful(uuid, status.getBlockIndex());
                        Log.i(TAG, "Marked sent payment successful " + uuid);
                        break;
                    case FAILED:
                        paymentDatabase.markPaymentFailed(uuid, FailureReason.UNKNOWN);
                        Log.i(TAG, "Marked sent payment failed " + uuid);
                        break;
                    case IN_PROGRESS:
                        Log.i(TAG, "Sent payment still in progress " + uuid);
                        throw new IncompleteTransactionException();
                    default:
                        throw new AssertionError();
                }
                break;
            }
        case RECEIVED:
            {
                Log.i(TAG, "Checking received status of " + uuid);
                Wallet.ReceivedTransactionStatus transactionStatus = payments.getWallet().getReceivedTransactionStatus(Objects.requireNonNull(payment.getReceipt()));
                switch(transactionStatus.getStatus()) {
                    case COMPLETE:
                        paymentDatabase.markReceivedPaymentSuccessful(uuid, transactionStatus.getAmount(), transactionStatus.getBlockIndex());
                        Log.i(TAG, "Marked received payment successful " + uuid);
                        break;
                    case FAILED:
                        paymentDatabase.markPaymentFailed(uuid, FailureReason.UNKNOWN);
                        Log.i(TAG, "Marked received payment failed " + uuid);
                        break;
                    case IN_PROGRESS:
                        Log.i(TAG, "Received payment still in progress " + uuid);
                        throw new IncompleteTransactionException();
                    default:
                        throw new AssertionError();
                }
                break;
            }
        default:
            {
                throw new AssertionError();
            }
    }
}
Also used : PaymentTransactionId(org.thoughtcrime.securesms.payments.PaymentTransactionId) Payments(org.thoughtcrime.securesms.payments.Payments) PaymentDatabase(org.thoughtcrime.securesms.database.PaymentDatabase)

Example 2 with Payments

use of org.thoughtcrime.securesms.payments.Payments in project Signal-Android by signalapp.

the class PaymentTransactionCheckJob method onRun.

@Override
protected void onRun() throws Exception {
    PaymentDatabase paymentDatabase = SignalDatabase.payments();
    PaymentDatabase.PaymentTransaction payment = paymentDatabase.getPayment(uuid);
    if (payment == null) {
        Log.w(TAG, "No payment found for UUID " + uuid);
        return;
    }
    Payments payments = ApplicationDependencies.getPayments();
    switch(payment.getDirection()) {
        case SENT:
            {
                Log.i(TAG, "Checking sent status of " + uuid);
                PaymentTransactionId paymentTransactionId = new PaymentTransactionId.MobileCoin(Objects.requireNonNull(payment.getTransaction()), Objects.requireNonNull(payment.getReceipt()), payment.getFee().requireMobileCoin());
                Wallet.TransactionStatusResult status = payments.getWallet().getSentTransactionStatus(paymentTransactionId);
                switch(status.getTransactionStatus()) {
                    case COMPLETE:
                        paymentDatabase.markPaymentSuccessful(uuid, status.getBlockIndex());
                        Log.i(TAG, "Marked sent payment successful " + uuid);
                        break;
                    case FAILED:
                        paymentDatabase.markPaymentFailed(uuid, FailureReason.UNKNOWN);
                        Log.i(TAG, "Marked sent payment failed " + uuid);
                        break;
                    case IN_PROGRESS:
                        Log.i(TAG, "Sent payment still in progress " + uuid);
                        throw new IncompleteTransactionException();
                    default:
                        throw new AssertionError();
                }
                break;
            }
        case RECEIVED:
            {
                Log.i(TAG, "Checking received status of " + uuid);
                Wallet.ReceivedTransactionStatus transactionStatus = payments.getWallet().getReceivedTransactionStatus(Objects.requireNonNull(payment.getReceipt()));
                switch(transactionStatus.getStatus()) {
                    case COMPLETE:
                        paymentDatabase.markReceivedPaymentSuccessful(uuid, transactionStatus.getAmount(), transactionStatus.getBlockIndex());
                        Log.i(TAG, "Marked received payment successful " + uuid);
                        break;
                    case FAILED:
                        paymentDatabase.markPaymentFailed(uuid, FailureReason.UNKNOWN);
                        Log.i(TAG, "Marked received payment failed " + uuid);
                        break;
                    case IN_PROGRESS:
                        Log.i(TAG, "Received payment still in progress " + uuid);
                        throw new IncompleteTransactionException();
                    default:
                        throw new AssertionError();
                }
                break;
            }
        default:
            {
                throw new AssertionError();
            }
    }
}
Also used : PaymentTransactionId(org.thoughtcrime.securesms.payments.PaymentTransactionId) Payments(org.thoughtcrime.securesms.payments.Payments) PaymentDatabase(org.thoughtcrime.securesms.database.PaymentDatabase)

Aggregations

PaymentDatabase (org.thoughtcrime.securesms.database.PaymentDatabase)2 PaymentTransactionId (org.thoughtcrime.securesms.payments.PaymentTransactionId)2 Payments (org.thoughtcrime.securesms.payments.Payments)2