I'm creating a custom function in zoho books that will create a record in zoho creator using payment record information from zoho books. I've been able to successfully create a record in zoho creator but I'm unable to get the invoice_id from the customer_payment map.
Unfortunately, there's no error being thrown.
Below is the code:
paymentMap = Map();
//set order to payment invoice id - this is not working
paymentMap.put("Order",customer_payment.get("invoices[0].invoice_id"));
paymentMap.put("Description",customer_payment.get("card_type"));
paymentMap.put("Payment_ZB_ID",customer_payment.get("payment_id"));
response = zoho.creator.createRecord("XXXXX","XX","Payment",paymentMap);
info response;
Below is the map that is available:
customer_payment
{
"payment_id": "11111111111111111",
"payment_number": "1",
"payment_number_prefix": "",
"payment_number_suffix": "1",
"documents": [],
"customer_id": "11111111111111111",
"customer_name": "John Doe",
"payment_mode": "Stripe",
"card_type": "visa",
"card_type_formatted": "Visa",
"date": "2019-03-04",
"date_formatted": "03/04/2019",
"account_id": "11111111111111111",
"account_name": "Stripe Clearing",
"account_type": "payment_clearing",
"account_type_formatted": "Payment Clearing Account",
"currency_id": "11111111111111111",
"currency_code": "USD",
"exchange_rate": 1,
"exchange_rate_formatted": "$1.00",
"amount": 1,
"amount_formatted": "$1.00",
"unused_amount": 0,
"unused_amount_formatted": "$0.00",
"bank_charges": 0.33,
"bank_charges_formatted": "$0.33",
"tax_account_id": "",
"is_client_review_settings_enabled": false,
"tax_account_name": "",
"tax_amount_withheld": 0,
"tax_amount_withheld_formatted": "$0.00",
"discount_amount": 0,
"discount_amount_formatted": "$0.00",
"description": "Stripe processing fees : $0.33 ",
"reference_number": "12345",
"online_transaction_id": "12345",
"settlement_status": "",
"settlement_status_formatted": "",
"invoices": [
{
"invoice_number": "11111111111111111",
"invoice_payment_id": "11111111111111111",
"invoice_id": "11111111111111111",
"amount_applied": 1,
"amount_applied_formatted": "$1.00",
"tax_amount_withheld": 0,
"tax_amount_withheld_formatted": "$0.00",
"discount_amount": 0,
"discount_amount_formatted": "$0.00",
"total": 1,
"total_formatted": "$1.00",
"balance": 0,
"balance_formatted": "$0.00",
"date": "2019-03-04",
"date_formatted": "03/04/2019",
"due_date": "2019-03-04",
"due_date_formatted": "03/04/2019",
"price_precision": 2,
"apply_date": "",
"apply_date_formatted": ""
}
],
"payment_refunds": [],
"last_four_digits": "1234",
"template_id": "11111111111111111",
"template_name": "Elite Template",
"page_width": "8.27in",
"page_height": "11.69in",
"orientation": "portrait",
"template_type": "elite",
"template_type_formatted": "Elite",
"attachment_name": "",
"can_send_in_mail": true,
"can_send_payment_sms": false,
"is_payment_details_required": true,
"custom_fields": [],
"custom_field_hash": {},
"imported_transactions": []
}
paymentMap.put("Order",customer_payment.get("invoices[0].invoice_id"));
Deluge does not throw an error here. Instead, when an element whose key is not available is being fetched, it throws a null.
The key used in ur code snippet invoices[0].invoice_id is not a valid key in the customer_payment map. So, this has been throwing a null value which would have populated as an empty (or no) value in Zoho Creator.
If you notice the customer_payment clearly, all invoices are available under the key "invoices".
invoices = customer_payment.get("invoices");// now invoices will have the list of invoices in customer_payment map
Assuming that the payment has only one invoice, the invoice ID can be extracted as below:
invoiceId = invoices.getJson("invoice_id");
It is also possible to extract the invoice ID as you have tried, like the below:
info customer_payment.get("invoices").get(0).get("invoice_id");
You can fetch invoice_id like this :
customer_payment = {"payment_id":"11111111111111111","payment_number":"1","payment_number_prefix":"","payment_number_suffix":"1","documents":{},"customer_id":"11111111111111111","customer_name":"John Doe","payment_mode":"Stripe","card_type":"visa","card_type_formatted":"Visa","date":"2019-03-04","date_formatted":"03/04/2019","account_id":"11111111111111111","account_name":"Stripe Clearing","account_type":"payment_clearing","account_type_formatted":"Payment Clearing Account","currency_id":"11111111111111111","currency_code":"USD","exchange_rate":1,"exchange_rate_formatted":"$1.00","amount":1,"amount_formatted":"$1.00","unused_amount":0,"unused_amount_formatted":"$0.00","bank_charges":0.33,"bank_charges_formatted":"$0.33","tax_account_id":"","is_client_review_settings_enabled":false,"tax_account_name":"","tax_amount_withheld":0,"tax_amount_withheld_formatted":"$0.00","discount_amount":0,"discount_amount_formatted":"$0.00","description":"Stripe processing fees : $0.33 ","reference_number":"12345","online_transaction_id":"12345","settlement_status":"","settlement_status_formatted":"","invoices":{{"invoice_number":"11111111111111111","invoice_payment_id":"11111111111111111","invoice_id":"11111111111111111","amount_applied":1,"amount_applied_formatted":"$1.00","tax_amount_withheld":0,"tax_amount_withheld_formatted":"$0.00","discount_amount":0,"discount_amount_formatted":"$0.00","total":1,"total_formatted":"$1.00","balance":0,"balance_formatted":"$0.00","date":"2019-03-04","date_formatted":"03/04/2019","due_date":"2019-03-04","due_date_formatted":"03/04/2019","price_precision":2,"apply_date":"","apply_date_formatted":""}},"payment_refunds":{},"last_four_digits":"1234","template_id":"11111111111111111","template_name":"Elite Template","page_width":"8.27in","page_height":"11.69in","orientation":"portrait","template_type":"elite","template_type_formatted":"Elite","attachment_name":"","can_send_in_mail":true,"can_send_payment_sms":false,"is_payment_details_required":true,"custom_fields":{},"custom_field_hash":{},"imported_transactions":{}};
invoices = customer_payment.getJson("invoices");
//info invoices;
invoiceId = invoices.getJSON("invoice_id");
info invoiceId;
Related
We have the SecurityEventItem that have the owner taken from another security_location model and returned.
The logic behind not having security_location direct as a foreign key is that we get events with security_location names that are not added yet to database, but we want them to be registered without adding the missing security location to the database.
class SecurityEventItemGetSerializer(serializers.ModelSerializer):
epc = RfidTagNestedSerializer()
owner = serializers.SerializerMethodField('get_owner')
def get_owner(self, member):
location = SecurityLocationSerializer(models.SecurityLocation.objects.get(name=member.security_location)).data
owner_name = ProductOwnerSerializer(models.ProductOwner.objects.get(id=location["owner"])).data
return owner_name["owner_name"]
class Meta:
model = models.SecurityEventItem
fields = ["id", "epc", "acknowledged", "firstSeenTimestamp", "security_location", "owner"]
The ViewSet bellow
class SecurityEventItemGetViewset(viewsets.ModelViewSet):
"""SecurityEventItemGet Viewset
API endpoint that allows security event items to be viewed.
Allowed actions:
"GET"
"""
queryset = models.SecurityEventItem.objects.all()
serializer_class = serializers.SecurityEventItemGetSerializer
http_method_names = ['get']
filter_backends = [DjangoFilterBackend]
search_fields = ["owner"]
filterset_fields = {
'acknowledged': ['exact'],
'epc': ['exact', "in"],
'security_location': ['exact', "in"],
'firstSeenTimestamp': ['gte', 'lte'],
}
I have tryed SearchFilter unsuccesfull as simillar to DjangoFilterBackend it does not recognize the owner field added that does not belong to the SecurityEventItem model.
The response is like this: and I would like to make a filter on the request passing a parameter "owner" added to the existing ones.
[
{
"id": 73,
"epc": {
"id": 8371,
"number": "1234",
"product": {
"id": 1,
"name": "default_product",
"ean": "",
"description": "default product for foreign/unknown RFID tags",
"category": {
"id": 1,
"name": "default_category",
"description": "default category for foreign/unknown RFID tags"
},
"info": []
},
"state": 1,
"info": [],
"owner": {
"id": 1,
"owner_id": 1,
"owner_name": "George"
}
},
"acknowledged": false,
"firstSeenTimestamp": "2022-02-21T09:44:08",
"security_location": "Test Location",
"owner": "Second Owner"
},
{
"id": 72,
"epc": {
"id": 105177,
"number": "303625D4580B2484000002CA",
"product": {
"id": 590,
"name": "A78R07",
"ean": "5940000792305",
"description": "Fata de perna 50x70",
"category": {
"id": 1,
"name": "default_category",
"description": "default category for foreign/unknown RFID tags"
},
"info": "{\"company\": \"HOTEL Nr1\"}"
},
"state": 1,
"info": [],
"owner": {
"id": 1,
"owner_id": 1,
"owner_name": "Regina"
}
},
"acknowledged": false,
"firstSeenTimestamp": "2022-02-21T09:31:16",
"security_location": "Front Desk",
"owner": "Second Company"
}
]
I would really appreciate if someone could teach me how to do that, there are plenty of information regarding model filtering, but no filters for the filters added to extra fields
SerializerMethodField is read-only.
This field is generated only at the time of serialization and does not exist in the database.
Filters work only with the database, but the owner field is not there.
I think you should annotate the queryset with the data you want (.annotate(owner=...), Subquery() ), then the filter can work because that field will be returned from the database.
I have a problem in repeated grid, I have a drop-down list where the users will choose what model they want.
Then I also have a JSON array which contains the model and other description of different cars.
How can I auto fill the appropriate JSON value to textField according to the chosen value in the drop-down list?
Like for example: The user chose the model Toyota, only the Toyota car model present in the JSON will be displayed at textField.
The form I've created is available at https://demo.orbeon.com/demo/fr/orbeon/builder/edit/3b1ebd5340007f245b34ccd468c36c188b376bd6. And here is the JSON:
{
"corppassUser": {
"corppassData": null,
"corppassEntity": {
"primaryActiviyDesc": "Marine insurance ",
"companyType": "A1",
"corppassPreviousNames": [],
"entityType": "LC",
"primaryActivityCode": "65121",
"businessExpiryDate": "",
"secondaryActivityCode": "93202",
"corppassShareholders": [
{
"allocation": 20000,
"personRef": {
"personName": "ANDY",
"nationality": "SG",
"id": 8,
"idno": "S6001111A"
},
"currency": "SGD",
"id": 3,
"entityRef": null,
"category": "1",
"shareType": "1"
},
{
"allocation": 10000,
"personRef": {
"personName": "TIMOTHY TAN",
"nationality": "SP",
"id": 6,
"idno": "S1112374E "
},
"currency": "SGD",
"id": 1,
"entityRef": null,
"category": "1",
"shareType": "1"
},
{
"allocation": 10000,
"personRef": {
"personName": "CLARISSA LIN",
"nationality": "SG",
"id": 7,
"idno": "S3212386E"
},
"currency": "SGD",
"id": 2,
"entityRef": null,
"category": "1",
"shareType": "1"
}
],
"uen": "T15LP0005A"
},
"id": 1
}
}
I have 2 tables Customer(Parent) and jobCode(Child) with one to many relationships
I want to retrieve a child record but with one extra field from the parent (customerGuid) as well. My code:
$jobCodes=JobCode::all();
foreach ($jobCodes as $jobCode) {
$jobCode['customerGuid']=$jobCode->customer->guid;
// I also tried $jobCode->setAttribute('customerGuid',$jobCode->customer->guid);
}
return $jobCodes;
I was expecting just the parent's guid field to be appended to each jobCode object and returned. However the ENTIRE customer parent object is returned!
[{
"id": 137,
"customerId": 1,
"jobCode": "Journeyman Plumber",
"jobDescription": "Journeyman Plumber",
"created_at": null,
"updated_at": "2017-01-27 12:20:27",
"guid": "28f35e94-e483-11e6-98e9-e0db55883624",
"customerGuid": "8d48931d-dc61-11e6-8927-e0db55883624",
"customer": {
"id": 1,
"name": "ACME",
"address1": "",
"address2": "",
"city": "San Jose",
"zip": "",
"phone": "",
"fax": "",
"email": "",
"guid": "8d48931d-dc61-11e6-8927-e0db55883624",
"stateName": "California",
"created_at": null,
"updated_at": "2017-01-20 07:10:59"
}
}, {
"id": 138,
"customerId": 1,
"jobCode": "JRP PreFab",
"jobDescription": "JRP",
......,
Its because your return statement returns $jobCodes; which is the entire table you retrieve here: $jobCodes=JobCode::all();
try putting this inside your loop
echo '$jobCode' to see what is the output every time it loops
Reaching for the relationship customer on $jobCode you automatically lazy load the relationship object, which is stored in $jobCode->customer attribute.
Try this instead just returning the collection:
// return $jobCodes;
return $jobCodes->map(function($jobCode){
$jobCode = $jobCode->toArray();
unset($jobCode['customer']);
return $jobCode;
});
I have customer data which has hasOne relationship with address table.
Returned data format is like below.
{
"customer_id": 1,
"last_name": "Cruickshank",
"first_name": "Pearl",
"phone": "+4 921-008-8344",
"email": "kristofer.kautzer#example.org",
"order_id": null,
"address_id": 66,
"created_at": "2017-01-18 06:24:40",
"updated_at": "2017-01-18 06:24:40",
"deleted_at": null,
"address": {
"address_id": 1,
"address_code": "RS-03549-9811",
"address1": "14978 Effertz Turnpike Apt. 086",
"address2": null,
"city": "Susanaburgh",
"province": "Illinois",
"country": "PG",
"postal_code": "03549-9811",
"created_at": "2017-01-18 06:24:40",
"updated_at": "2017-01-18 06:24:40"
}
I got data using return $this->model->with(implode(',', $relation))->get();
However, I cannot access any of data in address object.
Vue Code
I throw city is undefined. However, I can access to address object data using chrome developer tool
<tr v-for="(customer, index) in customers">
<td>{{index + 1}}</td>
<td>{{getFullName(customer.first_name, customer.last_name)}}</td>
<td>{{customer.phone}}</td>
<td>{{customer.address.city}}</td>
</tr>
Am I doing something wrong? I tried customer['address']['city'] as well.
I can access city when I get data as you see below.
getCustomerList () {
axios.get('/api/customers')
.then((res)=>{
if(res.status === 200){
//I can access city here but not in vue for loop ...
console.log(res.data.customers[0].address.city)
this.customers = res.data.customers
}
})
},
after a successful payment I store the stripe id on a mysql table. With that id I would like to retrieve all the details stored in the stripe database.
So is it possible to resume a single payment by the stripe id?
Thanks
Here is the documentation you need to use: https://stripe.com/docs/api/php#retrieve_customer
Use the "customer retrieve" Stripe API call to retrieve details about the customer's purchase:
Stripe::setApiKey(Config::get('your_stripe_secret_key_here'));
$customer_object = Customer::retrieve(customers_stripe_id);
This will return the following JSON:
Stripe\Customer JSON: {
"id": "cus_7KJZQ8Z6jfSSMl",
"object": "customer",
"account_balance": 0,
"created": 1447172728,
"currency": "usd",
"default_source": "card_175evz2eZvKYlo2CKoS2WEDk",
"delinquent": false,
"description": "Bingo|www|0c1234567890",
"discount": null,
"email": null,
"livemode": false,
"metadata": {
},
"shipping": null,
"sources": {
"object": "list",
"data": [
{
"id": "card_175evz2eZvKYlo2CKoS2WEDk",
"object": "card",
"address_city": null,
"address_country": null,
"address_line1": null,
"address_line1_check": null,
"address_line2": null,
"address_state": null,
"address_zip": null,
"address_zip_check": null,
"brand": "Visa",
"country": "US",
"customer": "cus_7KJZQ8Z6jfSSMl",
"cvc_check": "pass",
"dynamic_last4": null,
"exp_month": 5,
"exp_year": 2016,
"funding": "credit",
"last4": "4242",
"metadata": {
},
"name": null,
"tokenization_method": null
}
],
"has_more": false,
"total_count": 1,
"url": "/v1/customers/cus_7KJZQ8Z6jfSSMl/sources"
},
"subscriptions": {
"object": "list",
"data": [
],
"has_more": false,
"total_count": 0,
"url": "/v1/customers/cus_7KJZQ8Z6jfSSMl/subscriptions"
}
}
Here is Stripe's version of the API call:
\Stripe\Stripe::setApiKey("your_secret_key");
\Stripe\Customer::retrieve("the_customers_id");
Make sure to import the \Stripe classes by adding this at the top of your Model or Controller:
use Stripe\Customer;
use Stripe\Stripe;
if you want to use "Stripe" instead of \Stripe\Stripe and \Stripe\Customer prefixes)