Skip to content

Instantly share code, notes, and snippets.

@Shankjbs571
Last active July 28, 2025 16:27
Show Gist options
  • Save Shankjbs571/b044462d43176aef2a4ea579e02a264e to your computer and use it in GitHub Desktop.
Save Shankjbs571/b044462d43176aef2a4ea579e02a264e to your computer and use it in GitHub Desktop.
#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< END <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
elsif ($endpoint eq 'capture_order') {
print $query->header('application/json');
&ReadParse(); # now works, thanks to correct content-type
my $order_id = $in{'order_id'};
my $merchant_id = $in{'merchant_id'};
my $shipping = $in{'shipping'};
my $handling = $in{'handling'};
my $tax = $in{'tax'};
my $item = $in{'item'};
if (!$order_id || !$merchant_id) {
&bad("Missing order_id or merchant_id"); exit;
}
&log("capture_order called with order_id=$order_id, merchant_id=$merchant_id");
# Generate PayPal auth assertion
my $auth_assertion = generate_paypal_auth_assertion($PAYPAL_CLIENT_ID, $merchant_id);
my $req = HTTP::Request->new(POST => "$PAYPAL_API_BASE/v2/checkout/orders/$order_id/capture");
$req->header('Authorization' => "Bearer $token");
$req->header('Content-Type' => 'application/json');
$req->header('PayPal-Partner-Attribution-Id' => $BN_CODE);
$req->header('PayPal-Auth-Assertion' => $auth_assertion);
$req->content('{}');
my $res = $ua->request($req);
if ($res->is_success) {
my $json = decode_json($res->decoded_content);
$dump=Dumper($json);
&log('capture-response',"$response_data\nJSON: $json \n$dump");
# Order data can be used to process further
# Calling subroutine with full data
handle_capture_order(
order_id => $order_id,
merchant_id => $merchant_id,
shipping => $shipping,
handling => $handling,
tax => $tax,
item => $item,
json => $json
);
} else {
my $error_detail;
eval {
$error_detail = decode_json($res->decoded_content);
};
print encode_json({
status => 'error',
code => $res->code,
message => $res->status_line,
details => $error_detail || $res->decoded_content
});
}
exit;
}
sub handle_capture_order {
my (%args) = @_; # Accept a hash of parameters
my $order_id = $args{order_id};
my $merchant_id = $args{merchant_id};
my $shipping = $args{shipping};
my $handling = $args{handling};
my $tax = $args{tax};
my $json = $args{json};
$event_type = "SDK.ORDER.CAPTURED";
$ip=""; # $ENV{'REMOTE_ADDR'};
# $shipping=$in{'shipping'};
# $handling=$in{'handling'};
# $tax=$in{'tax'};
if ($price<=0) {$price=0;}
if ($shipping<=0) {$shipping=0;}
if ($handling<=0) {$handling=0;}
if ($tax<=0) {$tax=0;}
$item=$in{'item'};
if ($item>0) {
$item=&to_sql($item);
$q="select user.id,item_name,big_image,email,price,company,paypal_id,name,order_confirmation_message,layaway,layaway_policy,return_policy,terms_and_conditions,all_items_message from inventory,user where user.id=inventory.id and item=$item";
&sql($q);
&fetch();
$big_image=~ s/\.b/s/;
$item_name = ucfirst($item_name);
$item_name_ = &to_sql($item_name);
$seller_email=$email;
$seller_name=&to_sql($name);
$seller_company=&to_sql($company);
$return_policy_=&to_sql($return_policy);
$terms_and_conditions_=&to_sql($terms_and_conditions);
if ($layaway==1) {
$layaway_policy_=&to_sql($layaway_policy);
} else {
$layaway_policy_="";
$layaway_policy="";
}
$all_items_message_=&to_sql($all_items_message);
} else {
$error.="Missing item number";
}
if ($price<=0 and $shipping<=0 and $handling<=0 and $tax<0) {
$error.="No Item Cost";
}
if ($id==1) { ## sandbox for Dave!
$PAYPAL_API_BASE_URL = 'https://api-m.sandbox.paypal.com';
} else {
$PAYPAL_API_BASE_URL = 'https://api-m.paypal.com';
}
# $order_id=$in{'order_id'}; ## order_id from SDK
# if (!$order_id) {$error="No Capture ORDER_id from SDK"; }
if (!$error) {
###############################################
##### Capture Order
###############################################
# $json = capture_order($order_id); ## get the order information from PayPal Capture
# $dump=Dumper($json);
# &log('capture-response',"$response_data\nJSON: $json \n$dump");
$webhook_id = $json->{"id"} || "";
$create_time = $json->{"purchase_units"}[0]->{"payments"}->{"captures"}[0]->{"create_time"} || "";
$create_time =~ s/T/ /;
chop($create_time);
$response=&to_sql($json,1);
$webhook_id=&to_sql($webhook_id);
$txn = $json->{"purchase_units"}[0]->{"payments"}->{"captures"}[0]->{"id"} || "";
$txn = &to_sql($txn);
$capture_status = $json->{"purchase_units"}[0]->{"payments"}->{"captures"}[0]->{"status"} || ""; # should be COMPLETED
$seller_protection = $json->{"purchase_units"}[0]->{"payments"}->{"captures"}[0]->{"seller_protection"}->{"status"} || ""; # ELIGIBLE
$x=0;
while ($x<10) {
$temp = $json->{"purchase_units"}[0]->{"payments"}->{"captures"}[0]->{"seller_protection"}->{"dispute_categories"}[$x] || "";
$temp=~ s/\_/ /g;
if (!$temp) {last;}
$dispute_categories.="$temp,"; ## ITEM_NOT_RECEIVED / UNAUTHORIZED_TRANSCTION
$x++;
}
chop($dispute_categories);
$d=substr($create_time,8,2);
$m=substr($create_time,5,2);
$y=substr($create_time,0,4);
$d=~ s/^0//;
$m=~ s/^0//;
$create_time_readable="$d $month[$m] $y";
$bid = $json->{"purchase_units"}[0]->{"payments"}->{"captures"}[0]->{"custom_id"} || "0";
$bid=~ s/^REBORNS\-//i; ## stripe out leading identifier
$bid=&to_sql($bid);
if ($bid<=0) {$bid=0;}
$order_number = $json->{"purchase_units"}[0]->{"payments"}->{"captures"}[0]->{"invoice_id"} || "";
$payee_email = $email; # from SQL at top
$method="PayPal"; # default
$payer_id = $json->{"payment_source"}->{"paypal"}->{"account_id"} || "";
$paypal_account_status= $json->{"payment_source"}->{"paypal"}->{"account_status"} || "";
$payer_email = $json->{"payment_source"}->{"paypal"}->{"email_address"} || "";
$given_name = $json->{"payment_source"}->{"paypal"}->{"name"}->{"given_name"} || "";
$surname = $json->{"payment_source"}->{"paypal"}->{"name"}->{"surname"} || "";
$birthday = $json->{"payment_source"}->{"paypal"}->{"birth_date"} || "";
$phone = $json->{"payment_source"}->{"paypal"}->{"phone"}->{"phone_number"}->{"national_number"} || ""; ## enable on PayPal side of things if you need this field
$bcountry = $json->{"payment_source"}->{"paypal"}->{"address"}->{"country_code"} || "";
$bname = "$given_name $surname";
if ($json->{"payment_source"}->{"card"}->{"name"}) {
$method="PayPal->Credit Card";
$bname = $json->{"payment_source"}->{"card"}->{"name"} || "$bname";
$baddress1 = $json->{"payment_source"}->{"card"}->{"billing_address"}->{"address_line_1"} || "";
$baddress2 = $json->{"payment_source"}->{"card"}->{"billing_address"}->{"address_line_2"} || "";
$bstate = $json->{"payment_source"}->{"card"}->{"billing_address"}->{"admin_area_1"} || "";
$bcity = $json->{"payment_source"}->{"card"}->{"billing_address"}->{"admin_area_2"} || "";
$bzip = $json->{"payment_source"}->{"card"}->{"billing_address"}->{"postal_code"} || "";
$bcountry = $json->{"payment_source"}->{"card"}->{"billing_address"}->{"country_code"} || "";
$payer_id = $json->{"payment_source"}->{"card"}->{"attributes"}->{"customer"}->{"id"} || "$payer_id";
$payer_email = $json->{"payment_source"}->{"card"}->{"attributes"}->{"customer"}->{"email_address"} || "$payer_email";
$phone = $json->{"payment_source"}->{"card"}->{"attributes"}->{"customer"}->{"phone"}->{"phone_number"}->{"national_number"} || ""; ## enable on PayPal side of things if you need this field
}
$status = $json->{"status"}; ## should be Completed
$ship_name = $json->{"purchase_units"}[0]->{"shipping"}->{"name"}->{"full_name"} || "no name given";
$address1 = $json->{"purchase_units"}[0]->{"shipping"}->{"address"}->{"address_line_1"} || "";
$address2 = $json->{"purchase_units"}[0]->{"shipping"}->{"address"}->{"address_line_2"} || "";
$state = $json->{"purchase_units"}[0]->{"shipping"}->{"address"}->{"admin_area_1"} || "";
$city = $json->{"purchase_units"}[0]->{"shipping"}->{"address"}->{"admin_area_2"} || "";
$zip = $json->{"purchase_units"}[0]->{"shipping"}->{"address"}->{"postal_code"} || "";
$country = $json->{"purchase_units"}[0]->{"shipping"}->{"address"}->{"country_code"} || "";
$total = $json->{"purchase_units"}[0]->{"payments"}->{"captures"}[0]->{"amount"}->{"value"};
$currency = $json->{"purchase_units"}[0]->{"payments"}->{"captures"}[0]->{"amount"}->{"currency_code"};
$cursymbol=$currency_symbol{$currency};
# $a="$capture_status -- $status --$item-----$bid=bid---$txn ---$order_number";
if (
(
($capture_status eq "COMPLETED" and $status eq 'COMPLETED') or
($capture_status eq "COMPLETED" and $status eq 'PENDING') or
($capture_status eq "PENDING" and $status eq 'COMPLETED') or
($capture_status eq "PENDING" and $status eq 'PENDING')
)
and
$item>0 and $bid>0 and $txn and $order_number=~ /^REBORNS\-$bid\-/) {
##########################################################################################
######
# store the response in orders_json
$q="insert into orders_json (num,date,webhook_id,txn,json,event_type) values (null,now(),
'$webhook_id','$txn','$response_data','$event_type')";
&sql($q);
$qtemp=$q;
$orders_json=1;
$q="select txn_id from orders where txn_id='$txn'";
&sql($q);
&fetch();
&log("Inserted into orders_json","$qtemp\n$q\ntxn_id=$txn_id");
if ($txn_id) {
$error="Duplicate Transaction: TXN_ID=$txn";
}
else { # no transaction ID exisits in database orders table, add new order and email seller
$txn_id=$txn;
if ($bid>0) {
$q="select ip_last from user where id=$bid";
&sql($q);
&fetch();
$ip=&to_sql($ip_last);
} else {
$ip="";
}
if ($id==1) { } else { # don't update order status if Admin
$q="update inventory set bear_type=3,adopted_date=now() where item=$item";
&sql($q);
}
&log("Item Marked Sold",$q);
$currency_ = &to_sql($currency);
$capture_status_ = &to_sql($capture_status);
$dispute_categories_ = &to_sql($dispute_categories);
$seller_protection_ = &to_sql($seller_protection);
$paypal_account_status_=&to_sql($paypal_account_status);
$ship_name=ucfirst($ship_name);
$ship_name_=&to_sql($ship_name);
$payer_email_ =&to_sql($payer_email);
if ($buyer_id<=0) {$buyer_id=0;}
$baddress1=ucfirst($baddress1);
$baddress2=ucfirst($baddress2);
$bstate =ucfirst($bstate);
$bcountry =ucfirst($bcountry);
$baddress=$baddress1;
if ($baddress2) {$baddress="$baddress1\n$baddress2";}
if ($baddress and $bcity and $bstate) {
$bshipping_address="\nBilling Address:\n$baddress\n$bcity, $bstate $bzip\n$bcountry\n";
} elsif ($bcountry) {
$bshipping_address="\nBuyer Country: $bcountry";
}
# $bshipping_address_=&to_sql($bshipping_address);
$address1=ucfirst($address1);
$address2=ucfirst($address2);
$state =ucfirst($state);
$country =ucfirst($country);
$address=$address1;
if ($address2) {$address="$address1\n$address2";}
$shipping_address="$address\n$city, $state $zip\n$country";
$shipping_address_=&to_sql($shipping_address);
if ($handling>0) {$handling=&price($handling);$handling_=" + $cursymbol$handling payment fee";}
if ($tax>0) {$tax=&price($tax); $tax_ =" + $cursymbol$tax tax";} else {
$tax_="";}
$item_cost = &price($price);
$shipping = &price($shipping);
#$item_cost_line="$cursymbol$item_cost $currency + $cursymbol$shipping $currency shipping $handling_$tax_";
$item_cost_line="$cursymbol$item_cost + $cursymbol$shipping shipping$handling_$tax_";
$paypal_record="$create_time|$event_type|$total|$currency|$reason|$capture_status|$status|";
$description="Buyer Name: $bname$bshipping_address
PayPal Email: $payer_email
Transaction ID: $txn_id
$create_time: $cursymbol$total $currency deposited in your PayPal account [$item_cost_line]";
$paypal_record_=&to_sql($paypal_record);
$description_ =&to_sql($description,1);
$order_number_ =&to_sql($order_number);
$bname_=&to_sql($bname);
$baddress1_=&to_sql($baddress1);
$baddress2_=&to_sql($baddress2);
$bcity_=&to_sql($bcity);
$bstate_=&to_sql($bstate);
$bzip_=&to_sql($bzip);
$bcountry_=&to_sql($bcountry);
$address1_=&to_sql($address1);
$address2_=&to_sql($address2);
$city_=&to_sql($city);
$state_=&to_sql($state);
$zip_=&to_sql($zip);
$phone_=&to_sql($phone);
$country_=&to_sql($country);
$postage_ =&to_sql($postage);
$method_ =&to_sql($method);
$payer_id_=&to_sql($payer_id);
$birthday_=&to_sql($birthday);
$status_ =&to_sql($status);
if($item_cost<=0) {$item_cost="0.00";}
if($handling<=0) {$handling="0.00";}
if($shipping<=0) {$shipping="0.00";}
if($tax<=0) {$tax="0.00";}
$item_cost_ = &to_sql($item_cost);
$handling =&to_sql($handling);
$shipping =&to_sql($shipping);
$tax =&to_sql($tax);
$ip_ =&to_sql($ip);
$time=time();
# &log("before insert into orders");
$q="insert into orders (id,bid,ip,num,item,item_name,price,email,description,currency,addr
ess,address1,city,state,zip,country,shipping,name,phone,method,time,date,postage,order_typ
e,order_number,txn_id,txn_id_date,return_policy,terms_and_conditions,layaway_policy,all_it
ems_message,bname,baddress,baddress1,bcity,bstate,bzip,bcountry,payer_id,birthday,handling
,shipping_cost,tax,paypal_account_status,order_status,seller_protection,dispute_categories
,paypal_record) values ($id,$bid,'$ip_',null,$item,'$item_name_','$item_cost_','$payer_ema
il_','$description_','$currency_','$address1_','$address2_','$city_','$state_','$zip_','$c
ountry_','$shipping_address_','$ship_name_','$phone_','$method_',$time,now(),'$postage_',2
,'$order_number_','$txn_id',now(),'$return_policy_','$terms_and_conditions_','$layaway_pol
icy_','$all_items_message_','$bname_','$baddress1_','$baddress2_','$bcity_','$bstate_','$b
zip_','$bcountry_','$payer_id_','$birthday_',$handling,$shipping,$tax,'$paypal_account_sta
tus_','$capture_status_','$seller_protection_','$dispute_categories_','$paypal_record_')";
$qtemp1=$q;
&sql($q);
&log("Insert into orders",$q);
$q="select LAST_INSERT_ID() from orders";
&sql($q);
&fetch();
$order_num=$last_insert_id;
&log("Last_Insert_id",$order_num);
$temp=&do_review_counts($id);
$temp=&do_review_counts($bid);
if ($shipping>0 or $handling>0 or $tax>0) {
$ship1="[$item_cost_line]";
}
$baddress=$baddress1;
if ($baddress2) {$baddress="$baddress1<br>$baddress2";}
if ($baddress and $bcity and $bstate) {
$bshipping_address="<br><b>Billing Address:</b><br>$baddress<br>$bcity, $bstate $bzip<br>$bcountry\n";
} elsif ($bcountry) {
$bshipping_address="<br><b>Country:</b> $bcountry";
}
if ($order_confirmation_message) {
$order_confirmation_message1="<b>Message From $seller_name</b><br>$order_confirmation_message<br><br>";
}
if ($order_confirmation_message) {
$order_confirmation_message="<b>Message Sent To Buyer</b><br>$order_confirmation_message<br><br>";
}
($f1,$s1)=split (/ /,$seller_name);
$address=$address1;
if ($address2) {$address="$address1<br>$address2";}
$capture_status=&cap($capture_status);
if ($seller_protection eq 'ELIGIBLE' and $dispute_categories) {
$temp=$dispute_categories;
$temp=~ s/,/, /g;
$temp=&cap($temp);
$temp=~ s/, /\<br\>/g;
$seller_protect="<br><b>Seller Protection Eligible</b><br>$temp"
} else {
$seller_protection=&cap($seller_protection);
$seller_protect="<b>Seller Protection:</b> $seller_protection";
}
# $subject1=$bname;
# $subject1="test dave";
# $bname="mike";$ship_name="mike";
$html="
<table>
<tr><td valign=top>
<img src=\"$http/images/co_name.jpg\" width=125 alt=\"Reborns\" border=0>
</td>
<td>&nbsp;</td>
<td align=right>
<font size=+1 face=arial><b>New Order</b>
</td></tr>
<tr><td colspan=3>
<!-- separator -->
<center>
<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"430\" height=\"0\" class=\
"horizontalRule\" style=\"border-bottom: 1px solid #e6e6e6;\">
<tr><td>&nbsp;</td></tr></table>
</center>
</td></tr>
<tr><td colspan=3>
&nbsp;<br>
</td></tr>
<tr><td valign=top colspan=3>
<center>
<a href=\"$http/item/$item\" target=new><img src=\"$http/user/$id/$big_image\" width=170 a
lt=\"\" border=0></a><br>
<font size=+1 face=arial><b>$item_name</b></font><br><br>
</center>
</td></tr>
<tr><td valign=top colspan=3>
<b>Order Date:</b> $create_time_readable<br>
<b>Order Number:</b> $order_num<br>
<br>
<b>Buyer:</b> $bname$bshipping_address<br>
<br>
<b>Payment</b><br>
$cursymbol$total $currency has been deposited in your PayPal account<br>
$ship1
<br>
<br>
<b>PayPal Email:</b> $payer_email ($paypal_account_status)<br>
<b>Transaction ID:</b> $txn_id<br>
<b>Payment Status:</b> $capture_status<br>
$seller_protect
<br>
<br>
<b>Shipping Address</b><br>
$ship_name<br>
$address<br>
$city, $state $zip<br>
$country<br>
<br>
$order_confirmation_message
<b>Next Steps</b><br>
1) Confirm the funds are in your PayPal account.<br>
2) Ship out the item to the buyer.<br>
3) Add the parcel tracking number to the $site_name Orders page.<br>
</td></tr></table>
";
$html="<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.or
g/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html>
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
<title>$site_name Order</title>
<style>
body{font-family:Arial;font-size:12px;color:#000000;}
.t{font-family:Arial;font-size:12px;color:#000000;}
a{color:#000000;}
a:visted{color:#000000;}
.prevent-apple-blue-links-gray a {color: #6D6E71 !important; text-decoration:
none;}
</style>
</head>
<body bgcolor=\"#e6e7e8\" leftmargin=\"0\" marginwidth=\"0\" topmargin=\"0\" marginheight=
\"0\" offset=\"0\" style=\"-webkit-text-size-adjust: none;margin: 0;padding: 0;width: 100%
;\">
<style>
*, body, html {
font-family: 'HelveticaNeue', 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', san
s-serif;
}
</style>
<center>
<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" height=\"100%\" width=\"100%\" id=
\"backgroundTable\" style=\"margin: 0;padding: 0;height: 100%;width: 100%;\"><tr><td align
=\"center\" valign=\"top\">
<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"550\" id=\"contentWrapper\
">
<tr><td style=\"padding:0 15px 0 15px\">
<!-- top graphic -->
<table valign=\"bottom\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"520\" he
ight=\"40\" id=\"templatePreheader\">
<tr><td valign=\"bottom\" class=\"preheaderContent\">
<img width=\"520\" height=\"5\" valign=\"bottom\" src=\"$http/gif/email/email_top_1.png\"
alt=\"\" style=\"max-width: 520px;display: block;border: none;font-size: 14px;font-weight:
bold;height: auto;line-height: 100%;outline: none;text-decoration: none;text-transform: c
apitalize;\" id=\"headerImage campaign-icon\"></td></tr></table>
<!--body-->
<table border=\"0\" cellpadding=\"36\" cellspacing=\"0\" width=\"520\" id=\"templateContai
ner\" style=\"border: 1px solid #e6e6e6;border-bottom: none;border-top: none;background-co
lor: #FFFFFF;\">
<tr><td>$html</td></tr></table>
<!--footer shadow-->
<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"520\" id=\"templatePostCon
tent\">
<tr><td valign=\"top\" class=\"preheaderContent\">
<img alt=\"\" src=\"$http/gif/email/email_bottom_1.png\" style=\"max-width: 520px;border:
none;font-size: 14px;font-weight: bold;height: auto;line-height: 100%;outline: none;text-d
ecoration: none;text-transform: capitalize;display: block;\" width=\"520\" height=\"20\" i
d=\"headerImage campaign-icon\">
</td></tr></table>
</td></tr></table>
</td></tr></table>
</center>
</div>
<br><br>
</body>
</html>
";
##### email to the buyer###
$html1="
<table>
<tr><td valign=top>
<img src=\"$http/images/co_name.jpg\" width=125 alt=\"Reborns\" border=0>
</td>
<td>&nbsp;</td>
<td align=right>
<font size=+1 face=arial><b>Order Receipt</b>
</td></tr>
<tr><td colspan=3>
<!-- separator -->
<center>
<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"430\" height=\"0\" class=\
"horizontalRule\" style=\"border-bottom: 1px solid #e6e6e6;\">
<tr><td>&nbsp;</td></tr></table>
</center>
</td></tr>
<tr><td colspan=3>
&nbsp;<br>
</td></tr>
<tr><td valign=top colspan=3>
<center>
<a href=\"$http/item/$item\" target=new><img src=\"$http/user/$id/$big_image\" width=170 a
lt=\"\" border=0></a><br>
<font size=+1 face=arial><b>$item_name</b></font><br><br>
</center>
</td></tr>
<tr><td colspan=3>
<b>Order Date:</b> $create_time_readable<br>
<b>Order Number:</b> $order_num<br>
<br>
<b>Payment</b><br>
Your payment of $cursymbol$total $currency has been deposited in the sellers account<br>
$ship1
<br>
<br>
<b>PayPal Email:</b> $payer_email ($paypal_account_status)<br>
<b>Transaction ID:</b> $txn_id<br>
<b>Payment Status:</b> $capture_status<br>
<br>
<b>Shipping Address</b><br>
$ship_name<br>
$address<br>
$city, $state $zip<br>
$country<br>
<br>
<b>Seller:</b> $seller_name<br>
<b>Nursery:</b> $seller_company<br>
<b>Email: </b> $seller_email<br>
<br>
$order_confirmation_message1
<b>Next Step</b><br>
The seller will follow up with you soon about your order. If you don't hear from them in a
few days contact them directly.
</td></tr></table>
";
$html1="<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.o
rg/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html>
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
<title>$site_name Order</title>
<style>
body{font-family:Arial;font-size:12px;color:#000000;}
.t{font-family:Arial;font-size:12px;color:#000000;}
a{color:#000000;}
a:visted{color:#000000;}
.prevent-apple-blue-links-gray a {color: #6D6E71 !important; text-decoration:
none;}
</style>
</head>
<body bgcolor=\"#e6e7e8\" leftmargin=\"0\" marginwidth=\"0\" topmargin=\"0\" marginheight=
\"0\" offset=\"0\" style=\"-webkit-text-size-adjust: none;margin: 0;padding: 0;width: 100%
;\">
<style>
*, body, html {
font-family: 'HelveticaNeue', 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', san
s-serif;
}
</style>
<center>
<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" height=\"100%\" width=\"100%\" id=
\"backgroundTable\" style=\"margin: 0;padding: 0;height: 100%;width: 100%;\"><tr><td align
=\"center\" valign=\"top\">
<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"550\" id=\"contentWrapper\
">
<tr><td style=\"padding:0 15px 0 15px\">
<!-- top graphic -->
<table valign=\"bottom\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"520\" he
ight=\"40\" id=\"templatePreheader\">
<tr><td valign=\"bottom\" class=\"preheaderContent\">
<img width=\"520\" height=\"5\" valign=\"bottom\" src=\"$http/gif/email/email_top_1.png\"
alt=\"\" style=\"max-width: 520px;display: block;border: none;font-size: 14px;font-weight:
bold;height: auto;line-height: 100%;outline: none;text-decoration: none;text-transform: c
apitalize;\" id=\"headerImage campaign-icon\"></td></tr></table>
<!--body-->
<table border=\"0\" cellpadding=\"36\" cellspacing=\"0\" width=\"520\" id=\"templateContai
ner\" style=\"border: 1px solid #e6e6e6;border-bottom: none;border-top: none;background-co
lor: #FFFFFF;\">
<tr><td>$html1</td></tr></table>
<!--footer shadow-->
<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"520\" id=\"templatePostCon
tent\">
<tr><td valign=\"top\" class=\"preheaderContent\">
<img alt=\"\" src=\"$http/gif/email/email_bottom_1.png\" style=\"max-width: 520px;border:
none;font-size: 14px;font-weight: bold;height: auto;line-height: 100%;outline: none;text-d
ecoration: none;text-transform: capitalize;display: block;\" width=\"520\" height=\"20\" i
d=\"headerImage campaign-icon\">
</td></tr></table>
</td></tr></table>
</td></tr></table>
</center>
</div>
<br><br>
</body>
</html>
";
print "content-type: application/json; charset=utf-8\n\n";
print JSON::encode_json($json);
$item_name=&from_html($item_name);
######################
#### send to seller ##
######################
if ($seller_email) { ## if seller email send to seller
$subject="Reborns Order: $item_name";
$to=$seller_email;
$from=$admin_email;
$reply_to=$payer_email;
&log("Sent to seller - $seller_email");
# if ($to=~ /daisydollreborns/i) {$from=$payer_email;}
$html =encode("utf8", $html); # to deal with unicode so it doesn't get double decoded in mail.pl
$subject=encode("utf8", $subject);
&mail ($to,$from,$reply_to,$subject,$html,$text);
}
######################
#### send to buyer
######################
if ($payer_email) {# and $id!=1) {
# $payer_email=$admin_email; ########## for testing ####
$subject="Reborns Order: $item_name";
$reply_to=$seller_email;
&log("Sent to buyer - $payer_email");
&mail ($payer_email,$from,$reply_to,$subject,$html1,$text);
}
#######################
## for Admin
#######################
if (1==2) {
$subject="PayPal SDK Capture Success";
$to=$admin_email;
$from=$to;
$dump=~ s/\n/\<br\>\n/g;
$capture_dump=~ s/\n/\<br\>\n/g;
$html.="$dump<br>$capture_dump<br><br>$qtemp<br>$qtemp1";
&log("PayPal SKK Capture Success -- sending email to $to");
&mail ($to,$from,$reply_to,$subject,$html,$text);
}
} # if TXN ID exists
} else { ## end if captured and completed with all ids and txt id
$error="Missing Data: $capture_status $status TXN=$txn bid=$bid order_number=$order_number item=$item";
}
} # if Order ID from Capture
###################################################################################
##### Error #######################################################################
###################################################################################
if ($error) {
$subject="$site_name /paypal/capture.cgi error: $event_type";
$to=$admin_email;
$from=$to;
$dump=~ s/\n/\<br\>/g;
$html.="=====Error====== $error ============<br>\n$dump<br>\n===========================
==============<br>\n";
&log("Error: $error $html");
# &mail ($to,$from,$reply_to,$subject,$html,$text);
}
###################################################################################
# Tell the paypal SDK everything is good to go, and return to store page
#print header('application/json');
#use CGI qw(:standard);
#print header('application/json');
# exit;
# print $query->header('application/json');
# my $payload = read_json_payload(); # Make sure this is imported or defined here
# my $order_id = $payload->{'order_id'};
# my $token = get_paypal_access_token(); # This too
# my $req = HTTP::Request->new(POST => "$PAYPAL_API_BASE/v2/checkout/orders/$order_id/capture");
# $req->header('Authorization' => "Bearer $token");
# $req->header('PayPal-Partner-Attribution-Id' => $BN_CODE);
# my $res = $ua->request($req);
# print $res->decoded_content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment