Why Some QuickBooks Payments deposits weren't automatically recorded? - php

I connect to the online api and to the payment api using the official PHP SDK.
I want to create invoices and pay for them by clients on my website.
I figured out the documentation and already made the connection and all requests, but when I create an invoice and payment, and then charge money from the client's card, this charge transaction is not automatically linked to the payment, as it is said in the documentation. Instead, I get an alert in the quickbooks dashboard.
Below, I will attach examples of my code how I create: invoice, payment for invoice and card charge:
$amount = 0.5;
$invoice_add = Invoice::create([
"Line"=>[
"DetailType"=>"SalesItemLineDetail",
"Amount"=>$amount,
"SalesItemLineDetail"=>[
"ItemRef"=>[
"value"=>4
],
"UnitPrice"=>$amount,
"Qty" => 1
]
],
"CustomerRef"=>[
"value"=>"".$payment_account->profile_id //customer id
],
"BillEmail" => [
"Address" => $pharmacy->email
],
"AllowOnlineCreditCardPayment"=> true,
"AllowOnlineACHPayment"=> true
]);
$res_invoice = $dataService->Add($invoice_add);
//$res_invoice = $dataService->SendEmail($res_invoice,$pharmacy->email);
.
$payment_add = Payment::create([
"TotalAmt"=>$amount,
"UnappliedAmt"=>$amount,
"PaymentMethodRef"=>[
"value"=>"5"
],
"Line"=>[
"LinkedTxn"=>[
"TxnId"=>$res_invoice->Id,
"TxnType"=>"Invoice"
],
"Amount"=>$amount
],
"CustomerRef"=>[
"value"=>"".$payment_account->profile_id //customer id
],
"ProcessPayment"=>"true",
"PaymentType"=>"CreditCard",
"CreditCardPayment"=> [
"CCDetail"=> [
"ProcessPayment"=> "true",
]
],
"TxnSource"=>"IntuitPayment"
]);
$res_payment = $dataService->Add($payment_add);
.
$array0 = [
"amount" => $amount,
"currency" => "USD",
"cardOnFile" => $payment_account->payment_profile_id, //customer default card id
"context" => [
"mobile" => "false",
"isEcommerce" => "false"
]
];
$charge = new Charge($array0);
$response = $client->charge($charge);
if($response->failed()){
$errorMessage = $response->getBody();
$error.= $errorMessage;
dd($errorMessage);
} else {
$charge_res = $response->getBody();
}
Maybe someone faced such a problem, or you will see that I'm doing something wrong?

Related

What am I doing wrong with this Selling Partner API library from github?

I'm using the Merchant Fulfillment portion of the Amazon Selling Partner API found at https://github.com/jlevers/selling-partner-api/
I have other portions working... namely orders coming down and reports going up. But I am using the same techniques and the Merchant Fulfillment API is not working. The response I get back indicates that it's not received the data I am sending it.
What am I doing wrong?
// North America Live
$NA = [
'url' => 'https://sellingpartnerapi-na.amazon.com',
'region' => 'us-east-1',
];
// North America Sandbox
// $NA = [
// 'url' => 'https://sandbox.sellingpartnerapi-na.amazon.com',
// 'region' => 'us-east-1',
// ];
$config = new SellingPartnerApi\Configuration([
"lwaClientId" => $lwaClientId,
"lwaClientSecret" => $lwaClientSecret,
"lwaRefreshToken" => $lwaRefreshToken,
"awsAccessKeyId" => $awsAccessKeyId,
"awsSecretAccessKey" => $awsSecretAccessKey,
"endpoint" => $NA // or another endpoint from lib/Endpoint.php
]);
$apiInstance = new SellingPartnerApi\Api\MerchantFulfillmentApi($config);
$body = new \SellingPartnerApi\Model\MerchantFulfillment\GetEligibleShipmentServicesRequest(
[
"shipment_request_details" =>
[
"amazon_order_id" => "XXX-XXXXXXXX-XXXXXXXX",
"item_list" =>
[
"order_item_id" => "XXXXXXXXXXXXXXX",
"quantity" => 1,
],
"ship_from_address" =>
[
"name" => "XXXXXXX",
"address_line1" => "XXXXXXXXXX",
"email" => "XXXXX#XXXXX.COM",
"city" => "XXXXXXXXX",
"postal_code" => "XXXXXX",
"country_code" => "US",
"phone" => "XXXXXXXXXXXX",
],
"weight" =>
[
"value" => 7,
"unit" => "oz",
],
"shipping_service_options" =>
[
"delivery_experience" => "DeliveryConfirmationWithSignature",
"carrier_will_pick_up" => true,
]
]
]
);
try {
$result = $apiInstance->getEligibleShipmentServices($body);
d($result);
} catch (Exception $e) {
echo "<PRE>";
echo 'Exception when calling MerchantFulfillmentV0Api->getEligibleShipmentServices: <BR>', wordwrap($e->getMessage(),80,"<br>\n",TRUE), PHP_EOL;
echo "</PRE>";
}
The $response I get back is:
Exception when calling MerchantFulfillmentV0Api->getEligibleShipmentServices:
[400] {
"errors": [
{
"code": "InvalidInput",
"message": "5
validation errors detected: Value \u0027\u0027 at
\u0027shipmentRequestDetails.shipFromAddress.email\u0027 failed to satisfy
constraint: Member must satisfy regular expression pattern: .+#.+; Value
\u0027\u0027 at \u0027shipmentRequestDetails.amazonOrderId\u0027 failed to
satisfy constraint: Member must satisfy regular expression pattern:
[0-9A-Z]{3}-[0-9]{7}-[0-9]{7}; Value \u0027\u0027 at
\u0027shipmentRequestDetails.weight.unit\u0027 failed to satisfy constraint:
Member must satisfy enum value set: [g, ounces, oz, grams]; Value null at
\u0027shipmentRequestDetails.weight.value\u0027 failed to satisfy constraint:
Member must not be null; Value \u0027[]\u0027 at
\u0027shipmentRequestDetails.itemList\u0027 failed to satisfy constraint: Member
must have length greater than or equal to 1",
"details": ""
}
]
}
In the Shipping Service options.... this needs to be set false.
"carrier_will_pick_up" => true,
If its set to true then it will not work. I think it has something to do with sending a request for pickup to the carrier.... and it seems counter-intuitive to set it to false... but thats what made it work!

Can't save credit card using Square's Cards API - Error: Invalid Source-id

I am trying to allow users to create monthly subscriptions via my website.
To achieve the above, I've followed Square's suggested flow:
Use Payments SDK to collect users card information client side and generate a token and source_id for the credit card in question. This worked successfully.
1.5 Create a customer and obtain a customer_id. success!
Use source_id from step 1 to create a payment and obtain a payment_id. This was successfully.
Use payment_id returned from step 2 to save the card on file. This calls results in in an error:
This is the request sent in step 2:
public function createPayment($request)
{
$response = Http::withHeaders(
[
'Authorization' => "Bearer " . $this->config['square']['access_token'],
'Content-Type' => 'application/json',
'Square-Version' => "2022-01-20",
]
)->post($this->config['square']['paymentsEndpoint'], [
"idempotency_key" => $request['source_id'],
"amount_money" => [
"amount" => $request['amount'],
"currency" => "USD",
],
"source_id" => $request['source_id'],
"autocomplete" => true,
"location_id" => $this->config['square']['locationId'],
"reference_id" => "creator-id-" . $request['id'],
]);
$created = json_decode($response);
if (isset($created->payment->id)) {
return $created->payment->id;
}
}
The above returns:
{#1522
+"payment": {#1485
+"id": "xmhTZnkyo9oZ9PH0eKdVfWwfvSJZY"
+"created_at": "2022-02-11T14:20:08.746Z"
+"updated_at": "2022-02-11T14:20:08.982Z"
+"amount_money": {#1513
+"amount": 100
+"currency": "USD"
}
+"status": "COMPLETED"
+"delay_duration": "PT168H"
+"source_type": "CARD"
+"card_details": {#1483
+"status": "CAPTURED"
+"card": {#1529
+"card_brand": "VISA"
+"last_4": "1111"
+"exp_month": 11
+"exp_year": 2023
+"fingerprint": "sq-1-up5lr5N9rhqnx9-2Ho9ZGmb-6_ldGkuEsjOhgzaJ5Xhuv7Qqv0wCBhms-hMLTh-y0Q"
+"card_type": "CREDIT"
+"prepaid_type": "NOT_PREPAID"
+"bin": "411111"
}
+"entry_method": "KEYED"
+"cvv_status": "CVV_ACCEPTED"
+"avs_status": "AVS_ACCEPTED"
+"statement_description": "SQ *DEFAULT TEST ACCOUNT"
+"card_payment_timeline": {#1528
+"authorized_at": "2022-02-11T14:20:08.856Z"
+"captured_at": "2022-02-11T14:20:08.982Z"
}
}
+"location_id": "LABQBPRYSFTE8"
+"order_id": "StJEDwNo1Q7eXeF0l8vD9Iaeac4F"
+"reference_id": "creator-id-1"
+"risk_evaluation": {#1527
+"created_at": "2022-02-11T14:20:08.856Z"
+"risk_level": "NORMAL"
}
+"total_money": {#1526
+"amount": 100
+"currency": "USD"
}
+"approved_money": {#1525
+"amount": 100
+"currency": "USD"
}
+"receipt_number": "xmhT"
+"receipt_url": "https://squareupsandbox.com/receipt/preview/xmhTZnkyo9oZ9PH0eKdVfWwfvSJZY"
+"delay_action": "CANCEL"
+"delayed_until": "2022-02-18T14:20:08.746Z"
+"application_details": {#1524
+"square_product": "ECOMMERCE_API"
+"application_id": "sandbox-sq0idb-FrLggaZMvpJBc2UDN3zKlg"
}
+"version_token": "mzLRfLZlX4n0M6DyXqkDeWqDx4nKy9zZM4Mz2UBlr9v6o"
}
}
Then this code calls the Cards endpoint to create a card:
public function createCard($request)
{
$id = auth()->user()->id;
$user = User::find($id);
$subscription = Subscription::where('user_id', '=', $id)->get();
$response = Http::withHeaders(
[
'Authorization' => "Bearer " . $this->config['square']['access_token'],
'Content-Type' => 'application/json',
'Square-Version' => "2022-01-20",
]
)->post($this->config['square']['cardsEndpoint'], [
"idempotency_key" => $request['source_id'],
"source_id" => $request['source_id'],
"card" => [
"billing_address" => [
"address_line_1" => $subscription[0]['address_line_1'],
"address_line_2" => $subscription[0]['address_line_2'] ?? "",
"locality" => $subscription[0]['admin_area_2'],
"administrative_district_level_1" => $subscription[0]['admin_area_1'],
"postal_code" => $subscription[0]['postal_code'],
"country" => $subscription[0]['country_code'],
],
"cardholder_name" => $request['fullname'],
"customer_id" => $request['customer_id'],
"reference_id" => "creator-id-" . $request['id'],
],
]);
return json_decode($response);
}
This call returns:
{"errors":[{"category":"INVALID_REQUEST_ERROR","code":"INVALID_CARD_DATA","detail":"Invalid card data.","field":"source_id"}]}
I tried running this in both sandbox and production environment and receive the same results.
The card data used on the client side is as follows:
Number: 4111 1111 1111 1111
CVV: 111
Postal code: 10003
Alternatively, in regards to the card number, I have follow the following recommendation from the Subscription API and got the same result:
Call CreateCard to add a card on file using the payment token ("cnon:card-nonce-ok") that Square provides for Sandbox testing.
Can someone please help me figure this out?
I was facing the same issue and seem like the billing_address causing issue while binding with card. It work If I remove the billing_address and keep it simple :)
Square PHP SDK
$card = new \Square\Models\Card();
$card->setCustomerId($customer_id);
$body = new \Square\Models\CreateCardRequest(
uniqid(), // perfer version 5
$request->payment_token,
$card
);
return $this->client->getCardsApi()->createCard($body);
You can also try it via API.
Endpoint:https://connect.squareupsandbox.com/v2/cards
{
"idempotency_key": "62d683de53df21",
"source_id": "cnon:XYZ...", //one time payment use payment token
"card": {
"customer_id": "123213...",
}

Stripe Charge after service complete

I am creating project using angular and larval. In my project i am integrating stripe for payment.My requirements are:
User fill their card details but not charged.User is charged after technician completes their service.I don't know how this flow will work.I already setup stripe in my project:
$charge = Stripe\Charge::create ([
"amount" => 10000,
"currency" => "gbp",
"source" => $token,
"description" => "payment",
"receipt_email"=>$email
]);
$charge = Stripe\Charge::create ([
"amount" => 10000,
"currency" => "gbp",
"source" => $token,
"description" => "payment",
"receipt_email"=>$email,
**"capture" => false**
]);
Notice the capture => false option here. This is what you need.
You will have to store the charge id some which you will find in your $charge variable.
When you want to charge actually charge do this,
$charge = \Stripe\Charge::retrieve($stripe_charge_id);
$charge->capture();
$stripe_charge_id will be the charge id that you stored earlier.
Also keep in mind that the uncaptured charge expires in 7 days.
you should check the documentation https://stripe.com/docs/api/charges/capture

I'm using Stripe API in my code and I have an error : You cannot use a Stripe token more than once: tok_1EIw1gKIAV9zC39qQnFXKzi6

I got an error saying :
Customer cus_EmVoBWWrqnWw4W does not have a linked source with ID tok_1EIw1gKIAV9zC39qQnFXKzi6.
here is my code :
\Stripe\Stripe::setApiKey("sk_test_rUFQ9fpJoK9TlRVJs1nSYd6C");
$user = new User();
$email = $user->getEmail();
//creation du client
$customer = \Stripe\Customer::create(array(
"email" => $email,
));
$charge = \Stripe\Charge::create(array(
"amount" => 2000,
"currency" => "eur",
"source" => $request ->request->get('stripeToken'),
"description" => "Stripe connect - Order 36",
"customer" => $customer->id
));
\Stripe\Stripe::setApiKey("sk_test_rUFQ9fpJoK9TlRVJs1nSYd6C");
$refund = \Stripe\Refund::create([
'charge' => $charge,
'amount' => 1000,
]);
You need to save the card to the customer and then charge the customer. After that, unless the customer has multiple sources and you want to use a specific one, you won't need to pass source to Charge::create.

How to send extra parameter in stripe charge.

I am integrating stripe payment gateway. i have integrated it successfully. but the problem is that i want to send exptra parameter for stripe one time and get that in response.
Now i using
Stripe_Charge::create(array(
"amount" => number_format($amount,2,".","")*100,
"currency" => AccountCurrency,
"card" => $_POST['stripeToken'],
"description" => "Desc: " . $custom
));
I want to send extra partameter like order_id and want that from response as stripe give customer id for recurring charge.
Stripe_Charge::create(array(
"amount" => number_format($amount,2,".","")*100,
"currency" => AccountCurrency,
"card" => $_POST['stripeToken'],
"description" => "Desc: " . $custom,
"Order_id => $order // Is there any method to send paramerte like this.
));
Thank you.
You can use the metadata attribute. See below -
Stripe_Charge::create(array(
"amount" => number_format($amount, 2, ".", "")*100,
"currency" => AccountCurrency,
"card" => $_POST['stripeToken'],
"description" => "Desc: " . $custom,
"metadata" => array("order_id" => $order)
));
Check the documentation here
// Get Logged Customer Id using Logged User's Email
Dictionary<string, string> Extra = new Dictionary<string, string>();
Extra.Add("email", ByEmail);
StripeCustomer customer = customerService.List(new StripeCustomerListOptions() { Limit = 1, ExtraParams = Extra }).SingleOrDefault();

Categories