Forum Replies Created

Viewing 15 replies - 1 through 15 (of 15 total)
  • Thread Starter fermenator

    (@fermenator)

    That makes sense, but how do you combine both a per_page= and page= using your API? I tried per_page=100&page=2, but it complains about the use of the &

    Thread Starter fermenator

    (@fermenator)

    I got past the issue. The issue was I was not actually getting the JSON object, but instead a string. My loop wasn’t working as expected because of that. I am now able to POST the update, and it works. I am now hitting an occasional issue when the post_category is more than one value.

    Thread Starter fermenator

    (@fermenator)

    As I really only want to update the content field, perhaps I need to just build the array as you showed me. What I need to know is the minimal set of array elements I need to define. I can pull the fields out of the json to set the elements of the array, and then post the array as the body back through the API. Can you tell me the minimal set of elements I need to set?

    Thread Starter fermenator

    (@fermenator)

    Looking at the raw json for $place, can see it is set to

        "post_category": [
            {
                "id": 389,
                "name": "Individual Member",
                "slug": "individual-member"
            }
        ],
    
    And member_type is:
    
    		"member_type": {
    			"raw": "Individual",
    			"rendered": "Individual"
    		},
    
    It is almost certainly an issue in attempting to send the body as json.
    Thread Starter fermenator

    (@fermenator)

    I’ll have to translate this into powershell, but I’ll give it a whirl. I suspect the issue is that I am pulling the place out using the API, and using it as a json object. What you have is an array, so what I am trying to do may not work.

    I did turn on some debugging, and can see that it is complaining about the post_category and member_type.

    {“code”:”rest_invalid_param”,”message”:”Invalid parameter(s): post_category,
    member_type”,”data”:{“status”:400,”params”:{“post_category”:”post_category[0] is not of type
    integer.”,”member_type”:”member_type is not one of Individual,
    Business.”},”details”:{“post_category”:{“code”:”rest_invalid_param”,”message”:”post_category[0] is not of type
    integer.”,”data”:null},”member_type”:{“code”:”rest_invalid_param”,”message”:”member_type is not one of Individual,
    Business.”,”data”:null}}}}

    Thread Starter fermenator

    (@fermenator)

    I have tried adding $key to $uri, but that doesn't work either.  I stripped out the identifying pieces of the code, but the nuts and bolts of what I am trying to do is below.  If I can get this to work, where we see an email or phone pattern in the text of the content I'll add a [content_control] to hide the values unless the user is logged in (has an valid account).  I have added some breaks in there to keep it from running against all records while troubleshooting.
    
    $userID = 'xxxxxx'
    $userPassword = 'xxxxxx'
    $Bytes = [System.Text.Encoding]::utf8.GetBytes("$($userID):$($userPassword)")
    $encodedAuth = [Convert]::ToBase64String($Bytes)
    $header = @{Authorization = "Basic $($encodedAuth)" }
    
    $userID2 = 'yyyyy'
    $userPassword2 = 'yyyyyy'
    $Bytes = [System.Text.Encoding]::utf8.GetBytes("$($userID2):$($userPassword2)")
    $encodedAuth = [Convert]::ToBase64String($Bytes)
    $header2 = @{Authorization = "Basic $($encodedAuth)" }
    
    $email_regex = '([a-zA-Z0-9_-.]+)@([a-zA-Z0-9_-.]+).([a-zA-Z]{2,5})'
    $not_email_regex = '(content_control status="logged_in"[a-zA-Z0-9_-.]+)@([a-zA-Z0-9_-.]+).([a-zA-Z]{2,5})'
    $phone_regex = '([1-9][0-9][0-9]-[1-9][0-9][0-9]-[0-9][0-9][0-9][0-9])'
    $not_phone_regex = '(content_control status="logged_in"[1-9][0-9][0-9]-[1-9][0-9][0-9]-[0-9][0-9][0-9][0-9])'
    
    $places = Invoke-RestMethod -method get -uri https://mysite.com/wp-json/geodir/v2/places -headers $header
    
    foreach ($place in $places){
    $jsonPlace = $place | ConvertTo-Json
    $email = ($place.content.raw | Select-String $email_regex -AllMatches).Matches
    $not_email = ($place.content.raw | Select-String $not_email_regex -AllMatches).Matches
    if ($email -and ! $not_email) {
    $place.content.raw = $place.content.raw.replace($email,'[content_control status="logged_in"]$email[/content_control]').replace('$email',$email)
    $place.content.rendered = $place.content.rendered.replace($email,'[content_control status="logged_in"]$email[/content_control]').replace('$email',$email)
    }
    $phone = ($place.content.raw | Select-String $phone_regex -AllMatches).Matches
    $not_phone = ($place.content.raw | Select-String $not_phone_regex -AllMatches).Matches
    if ($phone -and ! $not_phone) {
    $place.content.raw = $place.content.raw.replace($phone,'[content_control status="logged_in"]$phone[/content_control]').replace('$phone',$phone)
    $place.content.rendered = $place.content.rendered.replace($phone,'[content_control status="logged_in"]$phone[/content_control]').replace('$phone',$phone)
    }
    $place_id = $place.id
    $jsonPlace = $place | ConvertTo-Json
    $key = "consumer_key=yyyyyy&consumer_secret=yyyyyyy".ToUpper()
    $uri = "https://mysite.com/wp-json/geodir/v2/places/$place_id"
    $result = Invoke-RestMethod -method POST -uri $uri -headers $header2 -body $jsonPlace
    write-output $header2
    break
    }
    
    break
    Thread Starter fermenator

    (@fermenator)

    I tried using the header method too, but it doesn’t seem to work either. I don’t get an error message.

    Thread Starter fermenator

    (@fermenator)

    I tried appending to the URI, but that doesn’t seem to work either. I think I might not be sending the right information. What I do is pull the full “place” from the API to manipulate the raw json. I am marking up things like emails and phone numbers to add a content filter so that only members who are logged in can see the “private” data. I can tell from my script that the json is getting updated, but when I attempt a POST back through the API I am not seeing the updates. I am attempting to POST the entire json body. If I just want to update the content, would I just need to send that element by itself?

    Thread Starter fermenator

    (@fermenator)

    This begs one parting question. Is there a way to accept an order without authorization up front? I could then make necessary updates, and submit for authorization then.

    Thread Starter fermenator

    (@fermenator)

    It would look like the value of amount_money must not be getting updated.

    public function getAmountMoney()
    { return $this->amount_money;
    }

    /**
    * Sets amount_money
    * @param \SquareConnect\Model\Money $amount_money The amount of money to charge. Note that you specify the amount in the __smallest denomination of the applicable currency__. For example, US dollar amounts are specified in cents. See [Working with monetary amounts](#workingwithmonetaryamounts) for details. The value of currency must match the currency associated with the business that is charging the card.

    Thread Starter fermenator

    (@fermenator)

    This might be helpful, but I can see that message sent by WooCommerce to Square included this. On this order, I had increased the quantity from 1 widget to 12 widgets, but WooCommerce Square still only sent one widget. The cost of one widget is 507.

    05-15-2020 @ 19:16:20 – Request
    method:
    uri: chargeWithHttpInfo/3JV5D0CFC3WRV
    user-agent: WooCommerce-Square/2.1.5 (WooCommerce/4.1.0; WordPress/5.4.1)
    headers: Array
    (
    )
    body: {
    “idempotency_key”: “XXXXXXXXXXXXXXXXXX:236”,
    “amount_money”: {
    “amount”: 507,
    “currency”: “USD”
    },
    “card_nonce”: “cnon:XXXXXXXXXXXXXXXXXX”,
    “delay_capture”: true,
    “reference_id”: “236”,
    “note”: “XXXXXXXXXXXXXXXXXX – Order 236”,
    “customer_id”: “XXXXXXXXXXXXXXXXXX”,
    “billing_address”: {
    “address_line_1”: “XXXXXXXXXXXXXXXXXX”,
    “address_line_2”: “”,
    “locality”: “XXXXXXXXXXXXXXXXXX”,
    “administrative_district_level_1”: “XXXXXXXXXXXXXXXXXX”,
    “postal_code”: “XXXXXXXXXXXXXXXXXX”,
    “country”: “US”,
    “first_name”: “XXXXXXXXXXXXXXXXXX”,
    “last_name”: “XXXXXXXXXXXXXXXXXX”,
    “organization”: “”
    },
    “shipping_address”: {
    “address_line_1”: “XXXXXXXXXXXXXXXXXX”,
    “address_line_2”: “”,
    “locality”: “XXXXXXXXXXXXXXXXXX”,
    “administrative_district_level_1”: “XXXXXXXXXXXXXXXXXX”,
    “postal_code”: “XXXXXXXXXXXXXXXXXX”,
    “country”: “US”,
    “first_name”: “XXXXXXXXXXXXXXXXXX”,
    “last_name”: “XXXXXXXXXXXXXXXXXX”
    },
    “buyer_email_address”: “XXXXXXXXXXXXXXXXXX”,
    “order_id”: “XXXXXXXXXXXXXXXXXX”,
    “verification_token”: “verf:XXXXXXXXXXXXXXXXXX”
    }
    duration: 0.68656s

    Thread Starter fermenator

    (@fermenator)

    … and I am running 2.1.5

    Thread Starter fermenator

    (@fermenator)

    I just tested it again. I enabled the woocommerce square plugin, turned on the sandbox mode and submitted an order. I ordered two widgets. I have the site setup to capture authorization only. I reviewed the order, and “corrected” the order by removing one of the widgets from the order. I saved the order, and then captured the charges. The Woocommerce screen correctly indicate a charge for ONE widget. However, when I went to the Square sandbox, I can see that the original charge for TWO widgets was submitted. Something is still wrong.

    The basic use case is this:
    1. Authorization only
    2. Apply update to order
    a. Add an item
    b. Remove an item
    c. Add a Fee
    d. Add a Discount (Coupon)
    3. Capture payment

    So far, I haven’t been able to get these to work. I can’t enable this plugin until I have rock-solid assurances that the charges submitted over the payment gateway matches that of the order at the time the capture was done. Something is clearly not getting updated, so the amended charges are not being sent over the gateway.

    Thread Starter fermenator

    (@fermenator)

    I calculate the amount to increase or decrease the order manually, so it isn’t in a plug-in. If I owed the customer a credit, I would issue a coupon code for the delta, and apply it to the order. If the customer owed me more, I would add a “fee”.

    This being said, I found a new plugin that allows for float quantities, so I can update the quantity directly without calculating the delta anymore. I haven’t tested the payment process yet, but I would expect that it should process fine now. I have a dev account on squares site, so when I get a chance to test I’ll report back my findings.

    So, the coupon and fee were native woocommerce objects, not the result of a plugin. Switching to float quantities negates the need to manually adjust the order at all using coupons and fees.

    Thread Starter fermenator

    (@fermenator)

    Also, what is odd is Order Notes indicate the correct total was submitted.

    “Square Capture of $17.55 Approved”

    https://willowpondbakery.com

Viewing 15 replies - 1 through 15 (of 15 total)