I'm trying to:
1. Create Customer
2. Create Customer Card
3. Make Transaction
This code works live but fails in sandbox. Is it possible to store cards in sandbox mode?
my code:
// NOTE: $access_token is my sandbox token
// create customer $customer = $customer_api->createCustomer($access_token, $cust_obj)->getCustomer(); // store card $body = array( 'card_nonce' => $nonce, 'cardholder_name' => $cust_obj['given_name'].' '.$cust_obj['family_name'] ); $customerCard = $customerCard_api->createCustomerCard($access_token, $customer->getId(), $body)->getCard(); // make the transaction with the stored card $request_body = array( 'customer_id' => $customer->getId(), 'customer_card_id' => $customerCard->getId(), 'amount_money' => array( 'amount' => (int)$_POST['amount'], 'currency' => 'USD' ), # Every payment you process with the SDK must have a unique idempotency key. # If you're unsure whether a particular payment succeeded, you can reattempt # it with the same idempotency key without worrying about double charging # the buyer. 'idempotency_key' => uniqid() ); $result = $transaction_api->charge($access_token, $location_id, $request_body);
my error:
Caught exception! Response body: object(stdClass)#46 (1) { ["errors"]=> array(1) { [0]=> object(stdClass)#43 (4) { ["category"]=> string(21) "INVALID_REQUEST_ERROR" ["code"]=> string(9) "NOT_FOUND" ["detail"]=> string(19) "Resource not found." ["field"]=> string(10) "card_nonce" } } }
Investigating this issue a little more, it looks like this error comes up for a few different reasons. Are you sure you aren't mixing up your sandbox credentials?
The error you are getting is related to not supplying the card nonce. Are you sure you setting `$nonce` correctly?
Yes, it's coming from the square form on previous page:
<input type="hidden" id="card-nonce" name="nonce" value="">
--- next page
$nonce = $_POST['nonce'];
-- I echo out the $nonce on the page that throws the error:
Nonce: CBASEKrzEbnfCZ1mo1eqTeLTqPw
This works in live mode, fails in sandbox. I'm sure I'm missing something but I can't find it
It creates the customer ok, but fails when trying to create the card. After I create the customer I populate the $body array with the $nonce. I var_dump() the $body array and I see the $nonce is there, however it fails on creating card:
// create customer $customer = $customer_api->createCustomer($access_token, $cust_obj)->getCustomer(); // store card $body = array( 'card_nonce' => $nonce, 'cardholder_name' => $cust_obj['given_name'].' '.$cust_obj['family_name'] ); echo '<pre>'; var_dump($body); echo '</pre>'; $customerCard = $customerCard_api->createCustomerCard($access_token, $customer->getId(), $body)->getCard();
var_dump($body);
Nonce: CBASEFIptxpy2UEOLf3RgsX3o6k array(2) { ["card_nonce"]=> string(27) "CBASEFIptxpy2UEOLf3RgsX3o6k" ["cardholder_name"]=> string(11) "Tommy Smith" } Caught exception!
Investigating this issue a little more, it looks like this error comes up for a few different reasons. Are you sure you aren't mixing up your sandbox credentials?
Ah, I just found the culprit. It was in the .js I hadn't checked. Thanks
Square Community