Ejemplo n.º 1
0
        private Transaction createPayoutTransaction(PaySession session, ITransactionContext context, JSONDataMap response, Account to, Amount amount, string description = null)
        {
            var    batchID = response.GetNodeByPath(RESPONSE_BATCH_HEADER, RESPONSE_BATCH_ID);
            object itemID  = null;
            var    items   = response.GetNodeByPath(RESPONSE_ITEMS) as JSONDataArray;

            if (items != null && items.Count > 0)
            {
                // for the moment there is only one possible payment in a batch
                itemID = ((JSONDataMap)items[0]).GetNodeByPath(RESPONSE_ITEMS_ITEMID);
            }

            var processorToken  = new { batchID = batchID.AsString(), itemID = itemID.AsString() };
            var transactionDate = response.GetNodeByPath(RESPONSE_BATCH_HEADER, RESPONSE_TIME_COMPLETED)
                                  .AsDateTime(App.TimeSource.UTCNow);

            var transactionID = PaySystemHost.GenerateTransactionID(session, context, TransactionType.Transfer);

            return(Transaction.Transfer(transactionID,
                                        this.Name, processorToken,
                                        Account.EmptyInstance,
                                        to,
                                        amount,
                                        transactionDate,
                                        description));
        }
Ejemplo n.º 2
0
        private static void checkPayoutStatus(JSONDataMap response)
        {
            var batchStatus = response.GetNodeByPath(RESPONSE_BATCH_HEADER, RESPONSE_BATCH_STATUS);

            if (batchStatus.AsString() != RESPONSE_SUCCESS)
            {
                var errorName        = response.GetNodeByPath(RESPONSE_ERRORS, RESPONSE_ERRORS_NAME);
                var errorMessage     = response.GetNodeByPath(RESPONSE_ERRORS, RESPONSE_ERRORS_MESSAGE);
                var errorDescription = response.GetNodeByPath(RESPONSE_ERRORS, RESPONSE_ERRORS_DETAILS);
                var message          = StringConsts.PAYPAL_PAYOUT_DENIED_MESSAGE.Args(errorName ?? EMPTY,
                                                                                      errorMessage ?? EMPTY,
                                                                                      errorDescription ?? EMPTY);

                throw new PayPalPaymentException(message);
            }
        }
Ejemplo n.º 3
0
        private void checkPayoutStatus(JSONDataMap response, PayPalSession payPalSession)
        {
            var batchStatus = response.GetNodeByPath(RESPONSE_BATCH_HEADER, RESPONSE_BATCH_STATUS).AsString();

            if (!batchStatus.EqualsIgnoreCase(RESPONSE_SUCCESS))
            {
                throwPaymentException(response.GetNodeByPath(RESPONSE_ERRORS, RESPONSE_ERRORS_NAME).AsString(),
                                      response.GetNodeByPath(RESPONSE_ERRORS, RESPONSE_ERRORS_MESSAGE).AsString(),
                                      response.GetNodeByPath(RESPONSE_ERRORS, RESPONSE_ERRORS_DETAILS).AsString());
            }

            var items = response[RESPONSE_ITEMS] as JSONDataArray;

            if (items == null || items.Count <= 0)
            {
                return;
            }

            // for the moment there is only one possible payment in a batch
            var item   = (JSONDataMap)items[0];
            var status = item[RESPONSE_ITEM_TRAN_STATUS].AsString();

            //todo: cancel unclaimed transaction?
            if (status.EqualsIgnoreCase(RESPONSE_ITEM_UNCLAIMED))
            {
                var itemID = item[RESPONSE_ITEMS_ITEMID].AsString();
                cancelUnclaimedPayout(itemID, payPalSession);

                throwPaymentException(item.GetNodeByPath(RESPONSE_ITEM_ERRORS, RESPONSE_ITEM_ERRORS_NAME).AsString(),
                                      item.GetNodeByPath(RESPONSE_ITEM_ERRORS, RESPONSE_ITEM_ERRORS_MESSAGE).AsString(),
                                      EMPTY);
            }

            //todo: other statuses https://developer.paypal.com/docs/api/payments.payouts-batch#payouts_get
            if (!status.EqualsIgnoreCase(RESPONSE_ITEM_SUCCESS))
            {
                throwPaymentException(item.GetNodeByPath(RESPONSE_ITEM_ERRORS, RESPONSE_ITEM_ERRORS_NAME).AsString(),
                                      item.GetNodeByPath(RESPONSE_ITEM_ERRORS, RESPONSE_ITEM_ERRORS_MESSAGE).AsString(),
                                      status);
            }
        }
Ejemplo n.º 4
0
          private Transaction createPayoutTransaction(PaySession session, ITransactionContext context, JSONDataMap response, Account to, Amount amount, string description = null)
          {                                                             
              var batchID = response.GetNodeByPath(RESPONSE_BATCH_HEADER, RESPONSE_BATCH_ID);
              object itemID = null;
              var items = response.GetNodeByPath(RESPONSE_ITEMS) as JSONDataArray;
              if (items != null && items.Count > 0)
              {
                  // for the moment there is only one possible payment in a batch
                  itemID = ((JSONDataMap)items[0]).GetNodeByPath(RESPONSE_ITEMS_ITEMID);
              }

              var processorToken = new { batchID = batchID.AsString(), itemID = itemID.AsString() };
              var transactionDate = response.GetNodeByPath(RESPONSE_BATCH_HEADER, RESPONSE_TIME_COMPLETED)
                                            .AsDateTime(App.TimeSource.UTCNow);

              var transactionID = PaySystemHost.GenerateTransactionID(session, context, TransactionType.Transfer);
              
              return new Transaction(transactionID, 
                                     TransactionType.Transfer, 
                                     this.Name, processorToken, 
                                     Account.EmptyInstance, 
                                     to, 
                                     amount, 
                                     transactionDate, 
                                     description);
          }
Ejemplo n.º 5
0
 private static void checkPayoutStatus(JSONDataMap response)
 {
     var batchStatus = response.GetNodeByPath(RESPONSE_BATCH_HEADER, RESPONSE_BATCH_STATUS);
     if (batchStatus.AsString() != RESPONSE_SUCCESS)
     {
         var errorName = response.GetNodeByPath(RESPONSE_ERRORS, RESPONSE_ERRORS_NAME);
         var errorMessage = response.GetNodeByPath(RESPONSE_ERRORS, RESPONSE_ERRORS_MESSAGE);
         var errorDescription = response.GetNodeByPath(RESPONSE_ERRORS, RESPONSE_ERRORS_DETAILS);
         var message = StringConsts.PAYPAL_PAYOUT_DENIED_MESSAGE.Args(errorName ?? EMPTY, 
                                                                      errorMessage ?? EMPTY, 
                                                                      errorDescription ?? EMPTY);
     
         throw new PayPalPaymentException(message);      
     }
 }
Ejemplo n.º 6
0
        private void checkPayoutStatus(JSONDataMap response, PayPalSession payPalSession)
        {
            var batchStatus = response.GetNodeByPath(RESPONSE_BATCH_HEADER, RESPONSE_BATCH_STATUS).AsString();
              if (!batchStatus.EqualsIgnoreCase(RESPONSE_SUCCESS))
              {
                throwPaymentException(response.GetNodeByPath(RESPONSE_ERRORS, RESPONSE_ERRORS_NAME).AsString(),
                                      response.GetNodeByPath(RESPONSE_ERRORS, RESPONSE_ERRORS_MESSAGE).AsString(),
                                      response.GetNodeByPath(RESPONSE_ERRORS, RESPONSE_ERRORS_DETAILS).AsString());
              }

              var items = response[RESPONSE_ITEMS] as JSONDataArray;
              if (items == null || items.Count<=0) return;

              // for the moment there is only one possible payment in a batch
              var item = (JSONDataMap)items[0];
              var status = item[RESPONSE_ITEM_TRAN_STATUS].AsString();

              //todo: cancel unclaimed transaction?
              if (status.EqualsIgnoreCase(RESPONSE_ITEM_UNCLAIMED))
              {
                var itemID = item[RESPONSE_ITEMS_ITEMID].AsString();
                cancelUnclaimedPayout(itemID, payPalSession);

                throwPaymentException(item.GetNodeByPath(RESPONSE_ITEM_ERRORS, RESPONSE_ITEM_ERRORS_NAME).AsString(),
                                      item.GetNodeByPath(RESPONSE_ITEM_ERRORS, RESPONSE_ITEM_ERRORS_MESSAGE).AsString(),
                                      EMPTY);
              }

              //todo: other statuses https://developer.paypal.com/docs/api/payments.payouts-batch#payouts_get
              if (!status.EqualsIgnoreCase(RESPONSE_ITEM_SUCCESS))
              {
                throwPaymentException(item.GetNodeByPath(RESPONSE_ITEM_ERRORS, RESPONSE_ITEM_ERRORS_NAME).AsString(),
                                      item.GetNodeByPath(RESPONSE_ITEM_ERRORS, RESPONSE_ITEM_ERRORS_MESSAGE).AsString(),
                                      status);
              }
        }