1

This is how I work right now to build up membership on the website via paypal.

I would like to get done like that here:

   "plan": {
        "id": "P-rtfhfedh",
        "state": "ACTIVE",
        "name": "T-Shirt of the Month Club Plan",
        "description": "Template creation.",
        "type": "FIXED",
        "payment_definitions": [
          {
            "id": "PD-50606817NF8063316RWBZEUA",
            "name": "Regular Payments",
            "type": "REGULAR",
            "frequency": "Month",
            "amount": {
              "currency": "USD",
              "value": "100"
            }
          }
        ]

What I have done than to now in my MVC site it is like this:

int orderid = Convert.ToInt32(HelperClass.Helper.Settings.NyTal(8));

        JsonPaypal jsonpaypal = new JsonPaypal();
        jsonpaypal.IdValue = id + orderid;
        jsonpaypal.Name = "Medlemskab";
        jsonpaypal.description = "Medlemskab - Orderid: " + orderid;
        jsonpaypal.start_date = DateTime.Now;
        jsonpaypal.Plan = new string[] {
            "id:" Convert.ToString(id + orderid),
            "State": "ACTIVE",

        };

Class to JsonPaypal

public class JsonPaypal
{
    public int IdValue
    {
        get; set;
    }

    public string Name
    {
        get; set;
    }

    public string description
    {
        get; set;
    }

    public DateTime start_date
    {
        get; set;
    }

    public string payerURL
    {
        get; set;
    }
    public string Plan
    {
        get; set;
    }

    public string URL
    {
        get; set;
    }

    public string Obj
    {
        get; set;
    }
}

The problem is when I go into my plan and make multiple object which will also be shown from the code paypal made.

The fault lies as said by Plan.

enter image description here

J. Petersen
  • 101
  • 1
  • 9
  • "id:" Convert.ToString(id + orderid) -> "id": Convert.ToString(id + orderid) – Dmitriy Zapevalov May 06 '16 at 22:04
  • It gives me still red bugs and writes "Syntax error, '' Expected". It make it when I care about, and convert. @DmitriyZapevalov – J. Petersen May 06 '16 at 22:07
  • It was just from first glance. At second glance: JsonPaypal.Plan is string and you are trying to assign `array` of string. Also `array` initialization values are splited with `;` there must not be `:`. I recomend you to create subclass JsonPaypal.Plan and with all fields and fill it. – Dmitriy Zapevalov May 06 '16 at 22:14
  • @DmitriyZapevalov so you want a class action against the class I've created? – J. Petersen May 06 '16 at 22:19
  • I suggest to represent whole `JSON` class hierarchy. So the `field` of top-level `JsonPaypal` whould by not simply string but instance of neasted class JsonPaypal.Plan. – Dmitriy Zapevalov May 06 '16 at 22:29

1 Answers1

1

You need to set your public string Plan { get; set; } object to be a string[] string array.

Like this: public string[] Plan { get; set; }

This is why you are getting this red squiggly, as your code is trying to set a normal string to an array of strings.

Hope this helps!

EDIT Also, after more looking, I realised you are trying to add strings to your string array incorrectly.

Syntax for adding strings is like this:

string[] array = new string[] { "string 1", "string 2" };

Where you are creating your strings, and using other properties/variables to create them, ensure you are creating the string itself correctly. Close off your string and add + to append strings from methods or properties. Likewise, to add to a string from a method or property, add + " extra string stuff".

Like this

string[] array = new string[] {
                      "id: " + YourClass.Id,
                      "another string: " + myLocalVariable,  
                      "yet another " + AClass.Property + " class" };

Your code where setting jsonpaypal.Plan should be...

jsonpaypal.Plan = new string[] {
                       "id: " + Convert.ToString(id + orderid),
                       "State: ACTIVE" };

Hope this helps!

Geoff James
  • 3,122
  • 1
  • 17
  • 36
  • I've just re-looked at your code and edited my answer above. It will help, trust me. It was also failing before, because you had malformed strings to make up your `string[]`. Have a look; I've included some examples. – Geoff James May 06 '16 at 22:22
  • Your code `{ "id:" Convert.ToString(id + orderid), "State": "ACTIVE", }` is wrong. It must be written like this: `{ "id: " + Convert.ToString(id + orderid), "State: ACTIVE" };` to work properly. I've added this code to my answer for you. – Geoff James May 06 '16 at 22:24
  • Glad to be of help xD – Geoff James May 06 '16 at 22:30
  • A small last page of questions it's like in the example. from paypal how do I sort of like the "payment_definitions" coming into the plan? – J. Petersen May 06 '16 at 22:35
  • Create a `PaymentDefinitions` class that maps to the same properties in the Json object (like you've done with the 'JsonPaypal' object). Then, in your `JsonPaypal` object, add a new propery called `PaymentDefinitions` of type `List`. Wherever you're converting from (I use `Newtonsoft.Json`'s `ConvertToObject` method) will then translate it directly how you want it. – Geoff James May 06 '16 at 22:57
  • Thanks. i hope u will giv me +1 for my ask. – J. Petersen May 06 '16 at 23:11