public PayPalPaymentInstruction ParsePaymentInstruction(dynamic json)
        {
            if (json == null)
            {
                return(null);
            }

            DateTime dt;
            var      result = new PayPalPaymentInstruction();

            try
            {
                result.ReferenceNumber = (string)json.reference_number;
                result.Type            = (string)json.instruction_type;
                result.Note            = (string)json.note;

                if (DateTime.TryParse((string)json.payment_due_date, CultureInfo.InvariantCulture, DateTimeStyles.None, out dt))
                {
                    result.DueDate = dt;
                }

                if (json.amount != null)
                {
                    result.AmountCurrencyCode = (string)json.amount.currency;
                    result.Amount             = decimal.Parse((string)json.amount.value, CultureInfo.InvariantCulture);
                }

                var rbi = json.recipient_banking_instruction;

                if (rbi != null)
                {
                    result.RecipientBanking                   = new PayPalPaymentInstruction.RecipientBankingInstruction();
                    result.RecipientBanking.BankName          = (string)rbi.bank_name;
                    result.RecipientBanking.AccountHolderName = (string)rbi.account_holder_name;
                    result.RecipientBanking.AccountNumber     = (string)rbi.account_number;
                    result.RecipientBanking.RoutingNumber     = (string)rbi.routing_number;
                    result.RecipientBanking.Iban              = (string)rbi.international_bank_account_number;
                    result.RecipientBanking.Bic               = (string)rbi.bank_identifier_code;
                }

                if (json.links != null)
                {
                    result.Link = (string)json.links[0].href;
                }
            }
            catch { }

            return(result);
        }
        public string CreatePaymentInstruction(PayPalPaymentInstruction instruct)
        {
            if (instruct == null || instruct.RecipientBanking == null)
            {
                return(null);
            }

            if (!instruct.IsManualBankTransfer && !instruct.IsPayUponInvoice)
            {
                return(null);
            }

            var sb = new StringBuilder("<div style='text-align:left;'>");
            var paragraphTemplate = "<div style='margin-bottom:10px;'>{0}</div>";
            var rowTemplate       = "<span style='min-width:120px;'>{0}</span>: {1}<br />";
            var instructStrings   = T("Plugins.cloudCommerce.PayPal.PaymentInstructionStrings").Text.SplitSafe(";");

            if (instruct.IsManualBankTransfer)
            {
                sb.AppendFormat(paragraphTemplate, T("Plugins.cloudCommerce.PayPal.ManualBankTransferNote"));

                sb.AppendFormat(rowTemplate, instructStrings.SafeGet((int)PayPalPaymentInstructionItem.Reference), instruct.ReferenceNumber);
                sb.AppendFormat(rowTemplate, instructStrings.SafeGet((int)PayPalPaymentInstructionItem.AccountNumber), instruct.RecipientBanking.AccountNumber);
                sb.AppendFormat(rowTemplate, instructStrings.SafeGet((int)PayPalPaymentInstructionItem.AccountHolder), instruct.RecipientBanking.AccountHolderName);

                sb.AppendFormat(rowTemplate, instructStrings.SafeGet((int)PayPalPaymentInstructionItem.Bank), instruct.RecipientBanking.BankName);
                sb.AppendFormat(rowTemplate, instructStrings.SafeGet((int)PayPalPaymentInstructionItem.Iban), instruct.RecipientBanking.Iban);
                sb.AppendFormat(rowTemplate, instructStrings.SafeGet((int)PayPalPaymentInstructionItem.Bic), instruct.RecipientBanking.Bic);
            }
            else if (instruct.IsPayUponInvoice)
            {
                string amount  = null;
                var    culture = new CultureInfo(_services.WorkContext.WorkingLanguage.LanguageCulture ?? "de-DE");

                try
                {
                    var currency = _currencyService.Value.GetCurrencyByCode(instruct.AmountCurrencyCode);
                    var format   = (currency != null && currency.CustomFormatting.HasValue() ? currency.CustomFormatting : "C");

                    amount = instruct.Amount.ToString(format, culture);
                }
                catch { }

                if (amount.IsEmpty())
                {
                    amount = string.Concat(instruct.Amount.ToString("N"), " ", instruct.AmountCurrencyCode);
                }

                var intro = T("Plugins.cloudCommerce.PayPal.PayUponInvoiceLegalNote", _companyInfoSettings.Value.CompanyName.NaIfEmpty());

                if (instruct.Link.HasValue())
                {
                    intro = "{0} <a href='{1}'>{2}</a>.".FormatInvariant(intro, instruct.Link, instructStrings.SafeGet((int)PayPalPaymentInstructionItem.Details));
                }

                sb.AppendFormat(paragraphTemplate, intro);

                sb.AppendFormat(rowTemplate, instructStrings.SafeGet((int)PayPalPaymentInstructionItem.Bank), instruct.RecipientBanking.BankName);
                sb.AppendFormat(rowTemplate, instructStrings.SafeGet((int)PayPalPaymentInstructionItem.AccountHolder), instruct.RecipientBanking.AccountHolderName);
                sb.AppendFormat(rowTemplate, instructStrings.SafeGet((int)PayPalPaymentInstructionItem.Iban), instruct.RecipientBanking.Iban);
                sb.AppendFormat(rowTemplate, instructStrings.SafeGet((int)PayPalPaymentInstructionItem.Bic), instruct.RecipientBanking.Bic);
                sb.Append("<br />");
                sb.AppendFormat(rowTemplate, instructStrings.SafeGet((int)PayPalPaymentInstructionItem.Amount), amount);
                if (instruct.DueDate.HasValue)
                {
                    sb.AppendFormat(rowTemplate, instructStrings.SafeGet((int)PayPalPaymentInstructionItem.PaymentDueDate), instruct.DueDate.Value.ToString("d", culture));
                }
                sb.AppendFormat(rowTemplate, instructStrings.SafeGet((int)PayPalPaymentInstructionItem.Reference), instruct.ReferenceNumber);
            }

            sb.Append("</div>");

            return(sb.ToString());
        }